Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
#import gradio as gr
|
2 |
#gr.load("models/mistralai/Mistral-7B-Instruct-v0.3").launch()
|
|
|
3 |
import os
|
4 |
-
import
|
5 |
import requests
|
6 |
from dotenv import load_dotenv
|
7 |
|
@@ -10,36 +11,36 @@ load_dotenv()
|
|
10 |
|
11 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
12 |
headers = {"Authorization": f"Bearer {os.getenv('HFREAD')}"}
|
13 |
-
DISCORD_TOKEN = os.getenv('dsTOK')
|
14 |
-
|
15 |
-
client = discord.Client()
|
16 |
|
17 |
def query(payload):
|
18 |
response = requests.post(API_URL, headers=headers, json=payload)
|
19 |
return response.json()
|
20 |
|
21 |
-
def
|
22 |
response = query({"inputs": input_text})
|
|
|
23 |
if isinstance(response, dict) and 'generated_text' in response:
|
24 |
return response['generated_text']
|
25 |
elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
|
26 |
return response[0]['generated_text']
|
27 |
return 'No response generated.'
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
1 |
#import gradio as gr
|
2 |
#gr.load("models/mistralai/Mistral-7B-Instruct-v0.3").launch()
|
3 |
+
|
4 |
import os
|
5 |
+
import gradio as gr
|
6 |
import requests
|
7 |
from dotenv import load_dotenv
|
8 |
|
|
|
11 |
|
12 |
API_URL = "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3"
|
13 |
headers = {"Authorization": f"Bearer {os.getenv('HFREAD')}"}
|
|
|
|
|
|
|
14 |
|
15 |
def query(payload):
|
16 |
response = requests.post(API_URL, headers=headers, json=payload)
|
17 |
return response.json()
|
18 |
|
19 |
+
def chatbot_response(input_text):
|
20 |
response = query({"inputs": input_text})
|
21 |
+
# Extract the generated text from the response
|
22 |
if isinstance(response, dict) and 'generated_text' in response:
|
23 |
return response['generated_text']
|
24 |
elif isinstance(response, list) and len(response) > 0 and 'generated_text' in response[0]:
|
25 |
return response[0]['generated_text']
|
26 |
return 'No response generated.'
|
27 |
|
28 |
+
# Gradio interface
|
29 |
+
def main():
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("# Mistral-7B Chatbot")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
input_box = gr.Textbox(label="Input Text", placeholder="Type your question here...", lines=2)
|
35 |
+
|
36 |
+
with gr.Row():
|
37 |
+
output_box = gr.Textbox(label="Response", placeholder="The response will appear here...", lines=5)
|
38 |
+
|
39 |
+
submit_button = gr.Button("Submit")
|
40 |
+
|
41 |
+
submit_button.click(fn=chatbot_response, inputs=input_box, outputs=output_box)
|
42 |
+
|
43 |
+
demo.launch()
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
main()
|