sotseth commited on
Commit
62eb5f0
1 Parent(s): 3e99294

first commit

Browse files
Files changed (2) hide show
  1. app.py +45 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import AutoModelForSequenceClassification
3
+ from transformers import TFAutoModelForSequenceClassification
4
+ from transformers import AutoTokenizer, AutoConfig
5
+ import numpy as np
6
+ from scipy.special import softmax
7
+ import gradio as gr
8
+
9
+ #model_path=f'sotseth/output'
10
+ model_path=f'https://huggingface.co/sotseth/output'
11
+
12
+ model=AutoModelForSequenceClassification.from_pretrained(model_path)
13
+ #tokenizer=AutoTokenizer.from_pretrained(f"cardiffnlp/twitter-roberta-base-sentiment-latest")
14
+ tokenizer=AutoTokenizer.from_pretrained(model_path)
15
+
16
+ #from huggingface_hub import notebook_login
17
+ #notebook_login()
18
+
19
+ #tokenizer.push_to_hub('sotseth/output')
20
+
21
+ def predict_tweet(tweet):
22
+
23
+ inputs = tokenizer(tweet, return_tensors="pt", padding=True)
24
+ outputs = model(**inputs)
25
+ probs = outputs.logits.softmax(dim=-1)
26
+ sentiment_classes = ['Negative', 'Neutral', 'Positive']
27
+
28
+ return {sentiment_classes[i]: float(probs[0, i]) for i in range(len(sentiment_classes))}
29
+
30
+ iface=gr.Interface(
31
+ fn=predict_tweet,
32
+ inputs="text",
33
+ outputs="label",
34
+ title="Vaccine Sentiment Classifier",
35
+ description="Enter your thought on vaccines",
36
+ examples=[
37
+ ["Vaccines are a game-changer in addressing public health"],
38
+ ["Vaccines are profit making"],
39
+ ["Vaccines are dangerous"]
40
+ ]
41
+
42
+ )
43
+
44
+ iface.launch(share=True)
45
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ transformers==4.35.0
2
+ gradio==4.2.0
3
+ scikit-learn==1.2.2
4
+ scipy==1.11.3
5
+ torch==2.1.0
6
+
7
+