misewl / app.py
56yth's picture
Update app.py
216d210 verified
raw
history blame contribute delete
744 Bytes
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()