Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai.text.all import *
|
2 |
+
import gradio as gr
|
3 |
+
from huggingface_hub import from_pretrained_fastai
|
4 |
+
|
5 |
+
# Cargamos el learner
|
6 |
+
repo_id = "ikerml/twitter_class"
|
7 |
+
|
8 |
+
learner = from_pretrained_fastai(repo_id)
|
9 |
+
|
10 |
+
# Definimos las etiquetas de nuestro modelo
|
11 |
+
labels = ['β€','π','π','π','π₯','π','π','β¨','π','π','π·','πΊπΈ','β','π','π','π―','π','π','πΈ','π']
|
12 |
+
|
13 |
+
example1 = "I like potatoe"
|
14 |
+
example2 = "My house is on fire"
|
15 |
+
example3 = "The other day, i eat a banana"
|
16 |
+
|
17 |
+
# Definimos una funciΓ³n que se encarga de llevar a cabo las predicciones
|
18 |
+
def predict(text):
|
19 |
+
pred,pred_idx,probs = learner.predict(text)
|
20 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
21 |
+
|
22 |
+
# Creamos la interfaz y la lanzamos.
|
23 |
+
gr.Interface(fn=predict, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Label(),examples=[example1,example2,example3]).launch(share=False)
|