File size: 996 Bytes
5e5f995
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr 
import transformers as pipeline 
from transformers import AutoTokenizer,AutoModelForSequenceClassification
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline

model_name = "Sonny4Sonnix/twitter-roberta-base-sentimental-analysis-of-covid-tweets"  # Replace with the name of the pre-trained model you want to use
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

sentiment = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

def get_sentiment(input_text):
    return sentiment(input_text)



#Function to predict sentiments from the input text using the model
    prediction = model.predict([text])[0]
    if label==-1:
       return "Negative"
    elif label== 0:
        return "Neutral"
    else:
        return "Positive"

iface = gr.Interface(fn=get_sentiment,title="Sentimental Analysis", inputs="text",outputs="text")
iface.launch(inline=True)