Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,49 +10,4 @@ from transformers import AutoConfig
|
|
10 |
from transformers import AutoModelForSequenceClassification
|
11 |
from transformers import TFAutoModelForSequenceClassification
|
12 |
from transformers import pipeline
|
13 |
-
from scipy.special import softmax
|
14 |
-
|
15 |
-
# Requirements
|
16 |
-
model_path ="HOLYBOY/Sentiment_Analysis"
|
17 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
18 |
-
config = AutoConfig.from_pretrained(model_path)
|
19 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
20 |
-
|
21 |
-
# Preprocess text (username and link placeholders)
|
22 |
-
def preprocess(text):
|
23 |
-
new_text = []
|
24 |
-
for t in text.split(" "):
|
25 |
-
t = "@user" if t.startswith("@") and len(t) > 1 else t
|
26 |
-
t = "http" if t.startswith("http") else t
|
27 |
-
new_text.append(t)
|
28 |
-
return " ".join(new_text)
|
29 |
-
|
30 |
-
# ---- Function to process the input and return prediction
|
31 |
-
def sentiment_analysis(text):
|
32 |
-
text = preprocess(text)
|
33 |
-
|
34 |
-
encoded_input = tokenizer(text, return_tensors = "pt") # for PyTorch-based models
|
35 |
-
output = model(**encoded_input)
|
36 |
-
scores_ = output[0][0].detach().numpy()
|
37 |
-
scores_ = softmax(scores_)
|
38 |
-
|
39 |
-
# Format output dict of scores
|
40 |
-
labels = ["Negative", "Neutral", "Positive"]
|
41 |
-
scores = {l:float(s) for (l,s) in zip(labels, scores_) }
|
42 |
-
|
43 |
-
return scores
|
44 |
-
|
45 |
-
# ---- Gradio app interface
|
46 |
-
app = gr.Interface(fn = sentiment_analysis,
|
47 |
-
inputs = gr.Textbox("Input your tweet to classify or use the example provided below..."),
|
48 |
-
outputs = "label",
|
49 |
-
title = "Public Perception of COVID-19 Vaccines",
|
50 |
-
description = "This app analyzes Perception of text based on tweets about COVID-19 Vaccines using a fine-tuned distilBERT model",
|
51 |
-
interpretation = "default",
|
52 |
-
examples = [["The idea of introducing the vaccine is good"],
|
53 |
-
["I am definately not taking the jab"],
|
54 |
-
["The vaccine is bad and can cause serious health implications"],
|
55 |
-
["I dont have any opinion "]]
|
56 |
-
)
|
57 |
-
|
58 |
-
app.launch(share =True)
|
|
|
10 |
from transformers import AutoModelForSequenceClassification
|
11 |
from transformers import TFAutoModelForSequenceClassification
|
12 |
from transformers import pipeline
|
13 |
+
from scipy.special import softmax
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|