Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,13 @@ import nltk
|
|
3 |
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
4 |
from transformers import pipeline
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
def greet(name):
|
7 |
return "Hello " + name + "!!"
|
8 |
|
@@ -11,16 +18,18 @@ def classify(text):
|
|
11 |
|
12 |
def predict_sentiment(text, model):
|
13 |
if model == "finiteautomata/bertweet-base-sentiment-analysis":
|
14 |
-
|
15 |
-
out = pipe(text, return_all_scores=True)
|
16 |
return {pred["label"]: pred["score"] for pred in out[0]}
|
17 |
elif model == "vader":
|
18 |
nltk.download('vader_lexicon')
|
19 |
sia = SentimentIntensityAnalyzer()
|
20 |
return sia.polarity_scores(text)
|
|
|
|
|
|
|
|
|
21 |
|
22 |
|
23 |
-
|
24 |
demo = gr.Blocks()
|
25 |
|
26 |
with demo:
|
|
|
3 |
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# global variables to load models
|
7 |
+
lr_model = load("lr_model.joblib")
|
8 |
+
lr_vectorizer = load("vectorizer.joblib")
|
9 |
+
sentiment_pipe = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
def greet(name):
|
14 |
return "Hello " + name + "!!"
|
15 |
|
|
|
18 |
|
19 |
def predict_sentiment(text, model):
|
20 |
if model == "finiteautomata/bertweet-base-sentiment-analysis":
|
21 |
+
out = sentiment_pipe(text, return_all_scores=True)
|
|
|
22 |
return {pred["label"]: pred["score"] for pred in out[0]}
|
23 |
elif model == "vader":
|
24 |
nltk.download('vader_lexicon')
|
25 |
sia = SentimentIntensityAnalyzer()
|
26 |
return sia.polarity_scores(text)
|
27 |
+
elif model == "custom logistic regression":
|
28 |
+
x = lr_vectorizer.transform([text])
|
29 |
+
pred = lr_model.predict_proba(x)[0]
|
30 |
+
return {"neg": pred[0], "pos": pred[1]}
|
31 |
|
32 |
|
|
|
33 |
demo = gr.Blocks()
|
34 |
|
35 |
with demo:
|