Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
# Modelo
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
if not message:
|
| 9 |
return "Pregúntame algo 😊"
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.ChatInterface(fn=respond)
|
| 17 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Modelo confiable en español tipo tutor
|
| 6 |
+
API_URL = "https://api-inference.huggingface.co/models/mrm8488/t5-small-spanish-summarization"
|
| 7 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_TOKEN')}"}
|
| 8 |
+
|
| 9 |
+
def query(payload):
|
| 10 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 11 |
+
result = response.json()
|
| 12 |
+
# Manejo si el modelo está cargando
|
| 13 |
+
if isinstance(result, dict) and "error" in result:
|
| 14 |
+
return {"error": "Modelo cargando, intenta otra vez"}
|
| 15 |
+
return result
|
| 16 |
|
| 17 |
def respond(message, history):
|
| 18 |
if not message:
|
| 19 |
return "Pregúntame algo 😊"
|
| 20 |
|
| 21 |
+
output = query({
|
| 22 |
+
"inputs": "Explica claramente y paso a paso en español como un tutor: " + message
|
| 23 |
+
})
|
| 24 |
|
| 25 |
+
if isinstance(output, list) and "generated_text" in output[0]:
|
| 26 |
+
return output[0]["generated_text"]
|
| 27 |
+
else:
|
| 28 |
+
return "La IA está ocupada 😭 intenta otra vez en unos segundos"
|
| 29 |
|
| 30 |
demo = gr.ChatInterface(fn=respond)
|
| 31 |
demo.launch()
|