Karthikeyan commited on
Commit
5fc65a1
1 Parent(s): b55512d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -23,8 +23,9 @@ class SentimentAnalyzer:
23
  # result = pipe(text, label)
24
  # sentiment_scores= {result['labels'][0]:result['scores'][0],result['labels'][1]:result['scores'][1],result['labels'][2]:result['scores'][2]}
25
  # sentiment_scores_str = f"Positive: {sentiment_scores['positive']:.2f}, Neutral: {sentiment_scores['neutral']:.2f}, Negative: {sentiment_scores['negative']:.2f}"
26
- prompt = f""" Your task is find the top 3 setiments : <positive, negative, neutral> and it's sentiment score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
27
- your are analyze the text and provide the output in the following json order: \"\"\"Positive: <sentiment_scores['positive']:.2f>, Neutral: <sentiment_scores['neutral']:.2f>, Negative: <sentiment_scores['negative']:.2f>\"\"\"
 
28
  analyze the text : '''{text}'''
29
  """
30
  response = openai.Completion.create(
@@ -60,14 +61,32 @@ class SentimentAnalyzer:
60
  return message
61
 
62
  def analyze_sentiment_for_graph(self, text):
63
- pipe = pipeline("zero-shot-classification", model=self.model)
64
- label=["positive", "negative", "neutral"]
65
- result = pipe(text, label)
66
- sentiment_scores = {
67
- result['labels'][0]: result['scores'][0],
68
- result['labels'][1]: result['scores'][1],
69
- result['labels'][2]: result['scores'][2]
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  return sentiment_scores
72
 
73
  def emotion_analysis_for_graph(self,text):
 
23
  # result = pipe(text, label)
24
  # sentiment_scores= {result['labels'][0]:result['scores'][0],result['labels'][1]:result['scores'][1],result['labels'][2]:result['scores'][2]}
25
  # sentiment_scores_str = f"Positive: {sentiment_scores['positive']:.2f}, Neutral: {sentiment_scores['neutral']:.2f}, Negative: {sentiment_scores['negative']:.2f}"
26
+ prompt = f""" Your task is find the top 3 setiments : <labels = positive, negative, neutral> and it's sentiment score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
27
+ your are analyze the text and provide the output in the following json order: \"\"\"
28
+ <\{result['labels'][0]: result['scores'][0], result['labels'][1]: result['scores'][1], result['labels'][2]: result['scores'][2] \}>\"\"\" \
29
  analyze the text : '''{text}'''
30
  """
31
  response = openai.Completion.create(
 
61
  return message
62
 
63
  def analyze_sentiment_for_graph(self, text):
64
+ # pipe = pipeline("zero-shot-classification", model=self.model)
65
+ # label=["positive", "negative", "neutral"]
66
+ # result = pipe(text, label)
67
+ # sentiment_scores = {
68
+ # result['labels'][0]: result['scores'][0],
69
+ # result['labels'][1]: result['scores'][1],
70
+ # result['labels'][2]: result['scores'][2]
71
+ # }
72
+ prompt = f""" Your task is find the top 3 setiments : <labels = positive, negative, neutral> and it's sentiment score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
73
+ your are analyze the text and provide the output in the following json order: \"\"\"
74
+ <\{result['labels'][0]: result['scores'][0], result['labels'][1]: result['scores'][1], result['labels'][2]: result['scores'][2] \}>\"\"\" \
75
+ analyze the text : '''{text}'''
76
+ """
77
+ response = openai.Completion.create(
78
+ model="text-davinci-003",
79
+ prompt=prompt,
80
+ temperature=1,
81
+ max_tokens=60,
82
+ top_p=1,
83
+ frequency_penalty=0,
84
+ presence_penalty=0
85
+ )
86
+
87
+ # Extract the generated text
88
+ sentiment_scores = response.choices[0].text.strip()
89
+ print(sentiment_scores)
90
  return sentiment_scores
91
 
92
  def emotion_analysis_for_graph(self,text):