Spaces:
Runtime error
Runtime error
File size: 1,308 Bytes
d48ca0f b3010db d48ca0f b3010db d48ca0f |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#import gradio as gr
#gr.load("models/mistralai/Mistral-7B-Instruct-v0.3").launch()
import os
import gradio as gr
import requests
from dotenv import load_dotenv
# Load the environment variables from the .env file
load_dotenv()
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
headers = {"Authorization": f"Bearer {os.getenv('HFREAD')}"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
def chatbot_response(input_text):
response = query({"inputs": input_text})
if 'error' in response:
return response['error']
return response.get('generated_text', 'No response generated.')
# Gradio interface
def main():
with gr.Blocks() as demo:
gr.Markdown("# Mistral-7B Chatbot")
with gr.Row():
input_box = gr.Textbox(label="Input Text", placeholder="Type your question here...", lines=2)
with gr.Row():
output_box = gr.Textbox(label="Response", placeholder="The response will appear here...", lines=5)
submit_button = gr.Button("Submit")
submit_button.click(fn=chatbot_response, inputs=input_box, outputs=output_box)
demo.launch()
if __name__ == "__main__":
main()
|