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