OmarElgammal1 commited on
Commit
e9dc27e
·
1 Parent(s): d3b509b

Version 2.2

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -7,12 +7,14 @@ def load_model(selected_model):
7
  loaded_model = pickle.load(file)
8
  return loaded_model
9
 
10
- def predict(model, text):
11
- encoder = {
12
- 0:'assets/negative.jpeg',
13
- 1:'assets/neutral.jpeg',
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, ["positive", "negative", "neutral"], multi_label=True)
40
- sentiment = max(results['labels'], key=results['scores'].__getitem__)
41
- return sentiment
 
 
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="text", title="Sentiment Analysis")
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)