Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
from huggingface_hub import InferenceClient
|
4 |
+
|
5 |
+
# Load API key securely from Hugging Face Secrets
|
6 |
+
api_key = os.getenv("HUGGINGFACEHUB_API_TOKEN")
|
7 |
+
|
8 |
+
# Initialize Hugging Face Inference API Client
|
9 |
+
client = InferenceClient(
|
10 |
+
model="mistralai/Mistral-7B-Instruct-v0.2",
|
11 |
+
token=api_key
|
12 |
+
)
|
13 |
+
|
14 |
+
# Function to generate response
|
15 |
+
def generate_response(prompt):
|
16 |
+
response = client.text_generation(prompt, max_new_tokens=200)
|
17 |
+
return response
|
18 |
+
|
19 |
+
# Gradio UI
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_response,
|
22 |
+
inputs=gr.Textbox(placeholder="Ask me anything..."),
|
23 |
+
outputs="text",
|
24 |
+
title="Mistral-7B Chatbot",
|
25 |
+
description="Enter a question and get a response from Mistral-7B."
|
26 |
+
)
|
27 |
+
|
28 |
+
# Launch Gradio app
|
29 |
+
iface.launch()
|