Spaces:
Runtime error
Runtime error
File size: 1,616 Bytes
d48ca0f 9618d15 d48ca0f 9618d15 d48ca0f 9757a78 d48ca0f 9618d15 d48ca0f 9618d15 79a23f3 d48ca0f 9618d15 ebaf2cb |
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 47 48 49 50 |
#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
import gradio_client as grc
# 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})
# Extract the generated text from the response
if isinstance(response, dict) and 'generated_text' in response:
return response['generated_text']
elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
return response[0]['generated_text']
return '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()
grc.Client("Z3ktrix/Chatty").deploy_discord(to_id="1247789500445233275")
|