File size: 744 Bytes
334946b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216d210
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
import os
from huggingface_hub import InferenceClient

# Load API key securely from Hugging Face Secrets
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")

# Initialize Hugging Face Inference API Client
client = InferenceClient(
    model="mistralai/Mistral-7B-Instruct-v0.2",
    token=api_key
)

# Function to generate response
def generate_response(prompt):
    response = client.text_generation(prompt, max_new_tokens=200)
    return response

# Gradio UI
iface = gr.Interface(
    fn=generate_response,
    inputs=gr.Textbox(placeholder="Ask me anything..."),
    outputs="text",
    title="Mistral-7B Chatbot",
    description="Enter a question and get a response from Mistral-7B."
)

# Launch Gradio app
iface.launch()