Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Carga el modelo y tokenizador antes de definir la funci贸n
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-base")
|
| 6 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-base")
|
| 7 |
+
|
| 8 |
+
def responder(texto):
|
| 9 |
+
inputs = tokenizer(texto, return_tensors="pt")
|
| 10 |
+
outputs = model.generate(**inputs, max_length=100)
|
| 11 |
+
respuesta = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 12 |
+
return respuesta
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=responder,
|
| 16 |
+
inputs=gr.Textbox(lines=2, placeholder="Escribe tu pregunta aqu铆..."),
|
| 17 |
+
outputs="text",
|
| 18 |
+
title="Smart Bot - Chat con FLAN-T5-Base",
|
| 19 |
+
description="Un chatbot simple usando google/flan-t5-base en Hugging Face Spaces."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
iface.launch()
|
| 24 |
+
|