Spaces:
Build error
Build error
File size: 681 Bytes
5cb1781 4e9727c 5cb1781 3c50889 5cb1781 c29f97f ac0997d 5cb1781 44b8484 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | from huggingface_hub import from_pretrained_fastai
import gradio as gr
from fastai.text.all import *
repo_id = "Igmata/TwitterFinancialSentiment"
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab[1]
# Definimos una función que se encarga de llevar a cabo las predicciones
def predict(txt):
pred, pred_idx, probs = learner.predict(txt)
class_map = {0: 'bearish', 1: 'bullish', 2: 'neutral'}
return {class_map[i]: float(probs[i]) for i in range(len(labels))}
# Creamos la interfaz y la lanzamos.
gr.Interface(fn=predict, inputs=gr.Textbox(lines=5,placeholder="Escribe el tweet aquí"), outputs=gr.Label(num_top_classes=3)).launch(share=False) |