File size: 867 Bytes
efe2bbb
 
 
 
 
 
 
 
 
 
 
c24a618
efe2bbb
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from huggingface_hub import from_pretrained_fastai
from fastai.text.all import *
import gradio as gr



# Cargamos el learner
repo_id = "PablitoGil14/ModelEmotions"
learner = from_pretrained_fastai(repo_id)

# Definimos las etiquetas de nuestro modelo
labels = learner.dls.vocab

example1 = "I cant believe this happened."
example2 = "Thats fantastic news!"
example3 = "I am very irate by your complete disregard for honesty and decency. Your actions are unacceptable. Go screw yourself."

# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(text):
    pred,pred_idx, probs = learner.predict(text)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}
    
# Creamos la interfaz y la lanzamos. 
gr.Interface(fn=predict, inputs=gr.Textbox(), outputs=gr.Label(),examples=[example1,example2,example3]).launch(share=False)