Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
if not message:
|
| 8 |
return "Ask me something 😊"
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
demo = gr.ChatInterface(fn=respond)
|
| 16 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-small"
|
| 6 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 7 |
+
|
| 8 |
+
def query(payload):
|
| 9 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 10 |
+
return response.json()
|
| 11 |
|
| 12 |
def respond(message, history):
|
| 13 |
if not message:
|
| 14 |
return "Ask me something 😊"
|
| 15 |
|
| 16 |
+
output = query({
|
| 17 |
+
"inputs": "Explain clearly like a tutor: " + message
|
| 18 |
+
})
|
| 19 |
|
| 20 |
+
try:
|
| 21 |
+
return output[0]["generated_text"]
|
| 22 |
+
except:
|
| 23 |
+
return "Error 😭 try again"
|
| 24 |
|
| 25 |
demo = gr.ChatInterface(fn=respond)
|
| 26 |
|