Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import os
|
| 4 |
|
| 5 |
-
# Modelo confiable en español
|
| 6 |
-
|
| 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 |
-
|
| 22 |
-
|
| 23 |
-
})
|
| 24 |
|
| 25 |
-
|
| 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()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# Modelo pequeño, confiable y en español
|
| 5 |
+
chatbot = pipeline("text-generation", model="datificate/gpt2-small-spanish")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
if not message:
|
| 9 |
return "Pregúntame algo 😊"
|
| 10 |
|
| 11 |
+
prompt = "Responde en español de forma clara y amigable: " + message
|
| 12 |
+
response = chatbot(prompt, max_length=100, do_sample=False)
|
|
|
|
| 13 |
|
| 14 |
+
return response[0]["generated_text"]
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
demo = gr.ChatInterface(fn=respond)
|
| 17 |
demo.launch()
|