samueldomdey commited on
Commit
a72b0a2
1 Parent(s): c237469

Create app.py

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