Chris4K commited on
Commit
1c02c6e
1 Parent(s): 1f124d1

Update sentiment_analysis.py

Browse files
Files changed (1) hide show
  1. sentiment_analysis.py +28 -25
sentiment_analysis.py CHANGED
@@ -1,4 +1,6 @@
1
  import requests
 
 
2
 
3
  class SentimentAnalysisTool:
4
  name = "sentiment_analysis"
@@ -8,33 +10,34 @@ class SentimentAnalysisTool:
8
 
9
  outputs = ["json"]
10
 
11
- model_id_1 = "nlptown/bert-base-multilingual-uncased-sentiment"
12
- model_id_2 = "microsoft/deberta-xlarge-mnli"
13
- model_id_3 = "distilbert-base-uncased-finetuned-sst-2-english"
14
- model_id_4 = "lordtt13/emo-mobilebert"
15
- model_id_5 = "juliensimon/reviews-sentiment-analysis"
16
- model_id_6 = "sbcBI/sentiment_analysis_model"
17
- model_id_7 = "models/oliverguhr/german-sentiment-bert"
18
-
19
- def parse_output(output_json):
20
- list_pred=[]
21
- for i in range(len(output_json[0])):
22
- label = output_json[0][i]['label']
23
- score = output_json[0][i]['score']
24
- list_pred.append((label, score))
25
- return list_pred
26
-
27
- def get_prediction(model_id):
28
- classifier = pipeline("text-classification", model=model_id, return_all_scores=True)
29
-
30
- def predicto(review):
31
- classifier = SentimentAnalysisTool.get_prediction(SentimentAnalysisTool.model_id_7)
32
- prediction = classifier(review)
33
- print(prediction)
34
- return SentimentAnalysisTool.parse_output(prediction)
35
-
36
  def __call__(self, inputs: str):
37
  return SentimentAnalysisTool.predicto(str)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
 
 
1
  import requests
2
+ import gradio as gr
3
+ from transformers import pipeline
4
 
5
  class SentimentAnalysisTool:
6
  name = "sentiment_analysis"
 
10
 
11
  outputs = ["json"]
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def __call__(self, inputs: str):
14
  return SentimentAnalysisTool.predicto(str)
15
+
16
+ model_id_1 = "nlptown/bert-base-multilingual-uncased-sentiment"
17
+ model_id_2 = "microsoft/deberta-xlarge-mnli"
18
+ model_id_3 = "distilbert-base-uncased-finetuned-sst-2-english"
19
+ model_id_4 = "lordtt13/emo-mobilebert"
20
+ model_id_5 = "juliensimon/reviews-sentiment-analysis"
21
+ model_id_6 = "sbcBI/sentiment_analysis_model"
22
+ model_id_7 = "models/oliverguhr/german-sentiment-bert"
23
+
24
+ def parse_output(output_json):
25
+ list_pred=[]
26
+ for i in range(len(output_json[0])):
27
+ label = output_json[0][i]['label']
28
+ score = output_json[0][i]['score']
29
+ list_pred.append((label, score))
30
+ return list_pred
31
+
32
+ def get_prediction(model_id):
33
+ classifier = pipeline("text-classification", model=model_id, return_all_scores=True)
34
+
35
+ def predicto(review):
36
+ classifier = SentimentAnalysisTool.get_prediction(SentimentAnalysisTool.model_id_7)
37
+ prediction = classifier(review)
38
+ print(prediction)
39
+ return SentimentAnalysisTool.parse_output(prediction)
40
+
41
 
42
 
43