Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_fastai
|
| 2 |
+
from fastai.text.all import *
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Cargamos el learner
|
| 8 |
+
repo_id = "PablitoGil14/ModelEmotions"
|
| 9 |
+
learner = from_pretrained_fastai(repo_id)
|
| 10 |
+
|
| 11 |
+
# Definimos las etiquetas de nuestro modelo
|
| 12 |
+
labels = ['0','1','2','3']
|
| 13 |
+
|
| 14 |
+
example1 = "I cant believe this happened."
|
| 15 |
+
example2 = "Thats fantastic news!"
|
| 16 |
+
example3 = "I am very irate by your complete disregard for honesty and decency. Your actions are unacceptable. Go screw yourself."
|
| 17 |
+
|
| 18 |
+
# Definimos una funci贸n que se encarga de llevar a cabo las predicciones
|
| 19 |
+
def predict(text):
|
| 20 |
+
pred,pred_idx, probs = learner.predict(text)
|
| 21 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 22 |
+
|
| 23 |
+
# Creamos la interfaz y la lanzamos.
|
| 24 |
+
gr.Interface(fn=predict, inputs=gr.Textbox(), outputs=gr.Label(),examples=[example1,example2,example3]).launch(share=False)
|