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