Feiiisal commited on
Commit
997e257
·
1 Parent(s): 57eea4f

Gradio App

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+
4
+ model_path = f'Feiiisal/cardiffnlp_twitter_roberta_base_sentiment_latest_Nov2023'
5
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
7
+
8
+ def predict_tweet(tweet):
9
+ inputs = tokenizer(tweet, return_tensors="pt", padding=True, truncation=True, max_length=128)
10
+ outputs = model(**inputs)
11
+ probs = outputs.logits.softmax(dim=-1)
12
+ sentiment_classes = ['Negative', 'Neutral', 'Positive']
13
+ return {sentiment_classes[i]: float(probs.squeeze()[i]) for i in range(len(sentiment_classes))}
14
+
15
+ iface = gr.Interface(
16
+ fn=predict_tweet,
17
+ inputs="text",
18
+ outputs="label",
19
+ title="Vaccine Sentiment Classifier",
20
+ description="Enter a text about vaccines to determine if the sentiment is negative, neutral, or positive.",
21
+ examples=[
22
+ ["Vaccinations have been a game-changer in public health, significantly reducing the incidence of many dangerous diseases and saving countless lives."],
23
+ ["Vaccinations are a medical intervention that introduces a vaccine to stimulate an individual’s immune response against a particular disease."],
24
+ ["Vaccines are rushed to the market without proper testing and are pushed by corporations that value profits over the well-being of the public."]
25
+ ]
26
+ )
27
+
28
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ transformers