MissChloe commited on
Commit
c104713
·
1 Parent(s): 7e2de55

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers as pipeline
3
+ from transformers import AutoTokenizer,AutoModelForSequenceClassification
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
5
+
6
+ model_name = "Sonny4Sonnix/twitter-roberta-base-sentimental-analysis-of-covid-tweets" # Replace with the name of the pre-trained model you want to use
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
9
+
10
+ sentiment = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
11
+
12
+ def get_sentiment(input_text):
13
+ return sentiment(input_text)
14
+
15
+
16
+
17
+ #Function to predict sentiments from the input text using the model
18
+ prediction = model.predict([text])[0]
19
+ if label==-1:
20
+ return "Negative"
21
+ elif label== 0:
22
+ return "Neutral"
23
+ else:
24
+ return "Positive"
25
+
26
+ iface = gr.Interface(fn=get_sentiment,title="Sentimental Analysis", inputs="text",outputs="text")
27
+ iface.launch(inline=True)