Spaces:
Runtime error
Runtime error
Karthikeyan
commited on
Commit
•
032eb48
1
Parent(s):
ba2247b
Update app.py
Browse files
app.py
CHANGED
@@ -59,7 +59,7 @@ class SentimentAnalyzer:
|
|
59 |
|
60 |
def analyze_sentiment_for_graph(self, text):
|
61 |
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.\
|
62 |
-
your are analyze the text and provide the output in the following json format heigher to lower order:
|
63 |
analyze the text : '''{text}'''
|
64 |
"""
|
65 |
response = openai.Completion.create(
|
@@ -74,9 +74,15 @@ class SentimentAnalyzer:
|
|
74 |
|
75 |
# Extract the generated text
|
76 |
sentiment_scores = response.choices[0].text.strip()
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
def emotion_analysis_for_graph(self,text):
|
82 |
start_index = text.find("[")
|
@@ -143,9 +149,7 @@ class LangChain_Document_QA:
|
|
143 |
return summary
|
144 |
|
145 |
def _display_graph(self,sentiment_scores):
|
146 |
-
|
147 |
-
scores = sentiment_scores.values()
|
148 |
-
fig = px.bar(x=scores, y=labels, orientation='h', color=labels, color_discrete_map={"Negative": "red", "Positive": "green", "Neutral": "gray"})
|
149 |
fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
|
150 |
fig.update_layout(height=500, width=200)
|
151 |
return fig
|
@@ -209,7 +213,6 @@ class LangChain_Document_QA:
|
|
209 |
|
210 |
|
211 |
def _text_box(self,customer_emotion,customer_sentiment_score):
|
212 |
-
customer_score = ", ".join([f"{key}: {value:.2f}" for key, value in customer_sentiment_score.items()])
|
213 |
return f"customer_emotion:{customer_emotion}\nCustomer_sentiment_score:{customer_sentiment_score}"
|
214 |
|
215 |
def _on_sentiment_btn_click(self):
|
|
|
59 |
|
60 |
def analyze_sentiment_for_graph(self, text):
|
61 |
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.\
|
62 |
+
your are analyze the text and provide the output in the following json format heigher to lower order: '''["label1","label2","label3"][score1,score2,score3]''' \
|
63 |
analyze the text : '''{text}'''
|
64 |
"""
|
65 |
response = openai.Completion.create(
|
|
|
74 |
|
75 |
# Extract the generated text
|
76 |
sentiment_scores = response.choices[0].text.strip()
|
77 |
+
start_index = sentiment_scores.find("[")
|
78 |
+
end_index = sentiment_scores.find("]")
|
79 |
+
list1_text = sentiment_scores[start_index + 1: end_index]
|
80 |
+
list2_text = sentiment_scores[end_index + 2:-1]
|
81 |
+
emotions = list(map(str.strip, list1_text.split(",")))
|
82 |
+
scores = list(map(float, list2_text.split(",")))
|
83 |
+
score_dict={"Labels": emotions, "Score": scores}
|
84 |
+
print(score_dict)
|
85 |
+
return score_dict
|
86 |
|
87 |
def emotion_analysis_for_graph(self,text):
|
88 |
start_index = text.find("[")
|
|
|
149 |
return summary
|
150 |
|
151 |
def _display_graph(self,sentiment_scores):
|
152 |
+
fig = px.bar(sentiment_scores, orientation='h', color=labels, color_discrete_map={"Negative": "red", "Positive": "green", "Neutral": "gray"})
|
|
|
|
|
153 |
fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
|
154 |
fig.update_layout(height=500, width=200)
|
155 |
return fig
|
|
|
213 |
|
214 |
|
215 |
def _text_box(self,customer_emotion,customer_sentiment_score):
|
|
|
216 |
return f"customer_emotion:{customer_emotion}\nCustomer_sentiment_score:{customer_sentiment_score}"
|
217 |
|
218 |
def _on_sentiment_btn_click(self):
|