Commit
·
e9dc27e
1
Parent(s):
d3b509b
Version 2.2
Browse files
app.py
CHANGED
@@ -7,12 +7,14 @@ def load_model(selected_model):
|
|
7 |
loaded_model = pickle.load(file)
|
8 |
return loaded_model
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
2:'assets/positive.jpeg'
|
15 |
}
|
|
|
|
|
|
|
16 |
selected_model = None
|
17 |
with open('vectorizer.pkl', 'rb') as file:
|
18 |
vectorizer = pickle.load(file)
|
@@ -36,11 +38,13 @@ def predict(model, text):
|
|
36 |
|
37 |
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
|
38 |
def analyze_sentiment(text):
|
39 |
-
results = classifier(text,
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
|
43 |
# models = gr.Radio(['Random Forest', 'Logistic Regression','Naive Bayes','Decision Tree','KNN'], label="Choose model")
|
44 |
# demo = gr.Interface(fn=predict, inputs=[models,"text"], outputs="image", title="Sentiment Analysis")
|
45 |
-
demo = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="
|
46 |
-
demo.launch()
|
|
|
7 |
loaded_model = pickle.load(file)
|
8 |
return loaded_model
|
9 |
|
10 |
+
encoder = {
|
11 |
+
'negative':'assets/negative.jpeg',
|
12 |
+
'neutral':'assets/neutral.jpeg',
|
13 |
+
'positive':'assets/positive.jpeg'
|
|
|
14 |
}
|
15 |
+
|
16 |
+
def predict(model, text):
|
17 |
+
|
18 |
selected_model = None
|
19 |
with open('vectorizer.pkl', 'rb') as file:
|
20 |
vectorizer = pickle.load(file)
|
|
|
38 |
|
39 |
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
|
40 |
def analyze_sentiment(text):
|
41 |
+
results = classifier(text,["positive","negative",'neutral'],multi_label=True)
|
42 |
+
mx = max(results['scores'])
|
43 |
+
ind = results['scores'].index(mx)
|
44 |
+
result = results['labels'][ind]
|
45 |
+
return encoder[result]
|
46 |
|
47 |
# models = gr.Radio(['Random Forest', 'Logistic Regression','Naive Bayes','Decision Tree','KNN'], label="Choose model")
|
48 |
# demo = gr.Interface(fn=predict, inputs=[models,"text"], outputs="image", title="Sentiment Analysis")
|
49 |
+
demo = gr.Interface(fn=analyze_sentiment, inputs="text", outputs="image", title="Sentiment Analysis")
|
50 |
+
demo.launch(share=True)
|