File size: 841 Bytes
bc0e3d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from fastai.vision.all import *
import gradio as gr


# Cargamos el learner
learn = load_learner('export.pkl')

# Definimos las etiquetas de nuestro modelo
labels = ['World','Sports','Business ','Sci/Tech']


# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(text):
    pred,pred_idx,probs = learn.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.outputs.Label(num_top_classes=3),examples=['the Ukraine war still holds surprises','Rafa Nadal has won Roland Garros', 'Benchmarks likewise rose in Tokyo, Seoul and Sydney. Shanghai declined. Oil prices remained near $120 per barrel.','What experts told me to do after my positive COVID-19 at-home test']).launch(share=False)