Spaces:
Runtime error
Runtime error
File size: 789 Bytes
a72b0a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# imports
from transformers import pipeline
import gradio as gr
# define nlp mask
model = "siebert/sentiment-roberta-large-english"
nlp = pipeline(model=model) # set device=0 to use GPU (CPU default, -1)
# Inference
def inference(sentence):
preds = nlp(sentence)
pred_sentiment = preds[0]["label"]
pred_score = preds[0]["score"]
return pred_sentiment, pred_score
# launch app
gr.Interface(inference,
inputs=[gr.inputs.Textbox(label="Sentiment to predict", default="I love this!")],
outputs=[gr.outputs.Textbox(type="auto", label="Predicted sentiment"),
gr.outputs.Textbox(type="auto", label="Predicted score")],
description="Sentiment analysis",
allow_flagging=False,
).launch(debug=True) |