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



# Cargamos el learner
learner = from_pretrained_fastai('DavidVarona/review')

# Definimos las etiquetas de nuestro modelo
labels = ['0','1']

example1 = "This film is the worst I have seen in my whole life."
example2 = "Really interesting. I liked it a lot."
example3 = "I didn't like the ending,."

# 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)