Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,14 @@
|
|
| 1 |
-
from huggingface_hub import from_pretrained_fastai
|
| 2 |
-
import gradio as gr
|
| 3 |
from fastai.text.all import *
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
labels = learner.dls.vocab
|
| 9 |
|
| 10 |
-
# Función
|
| 11 |
def predict(text):
|
| 12 |
pred, _, probs = learn.predict(text)
|
| 13 |
-
|
| 14 |
-
return {label: float(prob) for label, prob in zip(labels, probs)}
|
| 15 |
|
| 16 |
-
# Interfaz Gradio
|
| 17 |
-
gr.Interface(
|
| 18 |
-
|
| 19 |
-
inputs=gr.Textbox(lines=2, placeholder="Write your movie review here..."),
|
| 20 |
-
outputs=gr.Label(num_top_classes=2),
|
| 21 |
-
examples=[
|
| 22 |
-
["This movie was fantastic, I loved the plot and acting!"],
|
| 23 |
-
["The film was boring and too long."]
|
| 24 |
-
]
|
| 25 |
-
).launch(share=False)
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastai.text.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
|
| 4 |
+
# Cargar el modelo
|
| 5 |
+
learn = load_learner('model.pkl')
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Función de predicción
|
| 8 |
def predict(text):
|
| 9 |
pred, _, probs = learn.predict(text)
|
| 10 |
+
return f"Predicción: {pred} (confianza: {probs.max():.2%})"
|
|
|
|
| 11 |
|
| 12 |
+
# Interfaz Gradio
|
| 13 |
+
demo = gr.Interface(fn=predict, inputs=gr.Textbox(lines=4, placeholder="Escribe un texto..."), outputs="text")
|
| 14 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|