Spaces:
Runtime error
Runtime error
Karthikeyan
commited on
Commit
•
c00db80
1
Parent(s):
ae7e86a
Update app.py
Browse files
app.py
CHANGED
@@ -16,6 +16,7 @@ import plotly.express as px
|
|
16 |
class SentimentAnalyzer:
|
17 |
def __init__(self):
|
18 |
self.model="facebook/bart-large-mnli"
|
|
|
19 |
def analyze_sentiment(self, text):
|
20 |
pipe = pipeline("zero-shot-classification", model=self.model)
|
21 |
label=["positive","negative","neutral"]
|
@@ -65,7 +66,7 @@ Please analyze the text and provide the output in the following format: emotion:
|
|
65 |
|
66 |
class Summarizer:
|
67 |
def __init__(self):
|
68 |
-
|
69 |
def generate_summary(self, text):
|
70 |
model_engine = "text-davinci-003"
|
71 |
prompt = f"""summarize the following conversation delimited by triple backticks.
|
@@ -89,7 +90,7 @@ sentiment = SentimentAnalyzer()
|
|
89 |
class LangChain_Document_QA:
|
90 |
|
91 |
def __init__(self):
|
92 |
-
|
93 |
|
94 |
def _add_text(self,history, text):
|
95 |
history = history + [(text, None)]
|
@@ -107,9 +108,9 @@ class LangChain_Document_QA:
|
|
107 |
formatted_history = " "
|
108 |
for entry in history:
|
109 |
customer_text, agent_text = entry
|
110 |
-
formatted_history += f"
|
111 |
if agent_text:
|
112 |
-
formatted_history += f"
|
113 |
return formatted_history
|
114 |
|
115 |
def _display_history(self):
|
@@ -150,11 +151,6 @@ class LangChain_Document_QA:
|
|
150 |
except:
|
151 |
pass
|
152 |
|
153 |
-
# prompt = f"""You are an AI psychotherapist chatbot for Mental Healthcare.You are a brilliant and empathic counselor for Mental Healthcare.you should suggest solution to patient for his problem. Analyse the patient json If asked for information take it from {patient_details}.
|
154 |
-
# patient say thanks tone you should end the conversation with thanking greeting.
|
155 |
-
# Chat History:[{history}]
|
156 |
-
# Patient: [{text}]
|
157 |
-
# Perform as Mental Healthcare Doctor Chatbot"""
|
158 |
prompt = f"""As an empathic AI psychotherapist chatbot, provide effective solutions to patients' mental health concerns.
|
159 |
if patient say thanking tone message to end the conversation with a thanking greeting when the patient expresses gratitude.
|
160 |
Analyse the patient json If asked for information take it from {patient_details}
|
@@ -192,28 +188,19 @@ class LangChain_Document_QA:
|
|
192 |
customer_emotion=sentiment.emotion_analysis(client)
|
193 |
customer_sentiment_score = sentiment.analyze_sentiment_for_graph(client)
|
194 |
|
195 |
-
agent_emotion=sentiment.emotion_analysis(agent)
|
196 |
-
agent_sentiment_score = sentiment.analyze_sentiment_for_graph(agent)
|
197 |
|
198 |
scores=self._text_box(customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score)
|
199 |
|
200 |
customer_fig=self._display_graph(customer_sentiment_score)
|
201 |
customer_fig.update_layout(title="Sentiment Analysis",width=775)
|
202 |
|
203 |
-
agent_fig=self._display_graph(agent_sentiment_score)
|
204 |
-
agent_fig.update_layout(title="Sentiment Analysis",width=775)
|
205 |
-
|
206 |
-
agent_emotion_score = sentiment.emotion_analysis_for_graph(agent_emotion)
|
207 |
-
|
208 |
-
agent_emotion_fig=self._display_graph(agent_emotion_score)
|
209 |
-
agent_emotion_fig.update_layout(title="Emotion Analysis",width=775)
|
210 |
|
211 |
customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
|
212 |
|
213 |
customer_emotion_fig=self._display_graph(customer_emotion_score)
|
214 |
customer_emotion_fig.update_layout(title="Emotion Analysis",width=775)
|
215 |
|
216 |
-
return scores,customer_fig,
|
217 |
|
218 |
|
219 |
def clear_func(self):
|
@@ -221,24 +208,20 @@ class LangChain_Document_QA:
|
|
221 |
|
222 |
def gradio_interface(self):
|
223 |
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
|
224 |
-
# with gr.Row():
|
225 |
-
# gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210">
|
226 |
-
# <img align="right" class="rightimage" src="https://download.logo.wine/logo/Vodafone/Vodafone-Logo.wine.png" alt="Image" width="230" height="230" >""")
|
227 |
with gr.Row():
|
228 |
-
gr.HTML("""<
|
|
|
|
|
|
|
229 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=360)
|
230 |
with gr.Row():
|
231 |
-
with gr.Column(scale=0.
|
232 |
txt = gr.Textbox(
|
233 |
show_label=False,
|
234 |
placeholder="Patient",elem_classes="height"
|
235 |
).style(container=False)
|
236 |
-
|
237 |
-
|
238 |
-
show_label=False,
|
239 |
-
placeholder="psychotherapist",elem_classes="height"
|
240 |
-
).style(container=False)
|
241 |
-
with gr.Column(scale=0.06):
|
242 |
emptyBtn = gr.Button(
|
243 |
"🧹 Clear",elem_classes="height"
|
244 |
)
|
@@ -246,10 +229,10 @@ class LangChain_Document_QA:
|
|
246 |
with gr.Column(scale=0.80):
|
247 |
txt3 =gr.Textbox(
|
248 |
show_label=False,
|
249 |
-
placeholder="AI
|
250 |
).style(container=False)
|
251 |
with gr.Column(scale=0.20, min_width=0):
|
252 |
-
button=gr.Button(value="🚀send"
|
253 |
with gr.Row():
|
254 |
with gr.Column(scale=0.50):
|
255 |
txt4 =gr.Textbox(
|
|
|
16 |
class SentimentAnalyzer:
|
17 |
def __init__(self):
|
18 |
self.model="facebook/bart-large-mnli"
|
19 |
+
openai.api_key=os.getenv("OPENAI_API_KEY")
|
20 |
def analyze_sentiment(self, text):
|
21 |
pipe = pipeline("zero-shot-classification", model=self.model)
|
22 |
label=["positive","negative","neutral"]
|
|
|
66 |
|
67 |
class Summarizer:
|
68 |
def __init__(self):
|
69 |
+
openai.api_key=os.getenv("OPENAI_API_KEY")
|
70 |
def generate_summary(self, text):
|
71 |
model_engine = "text-davinci-003"
|
72 |
prompt = f"""summarize the following conversation delimited by triple backticks.
|
|
|
90 |
class LangChain_Document_QA:
|
91 |
|
92 |
def __init__(self):
|
93 |
+
openai.api_key=os.getenv("OPENAI_API_KEY")
|
94 |
|
95 |
def _add_text(self,history, text):
|
96 |
history = history + [(text, None)]
|
|
|
108 |
formatted_history = " "
|
109 |
for entry in history:
|
110 |
customer_text, agent_text = entry
|
111 |
+
formatted_history += f"Patient: {customer_text}\n"
|
112 |
if agent_text:
|
113 |
+
formatted_history += f"Psycotherapist Bot: {agent_text}\n"
|
114 |
return formatted_history
|
115 |
|
116 |
def _display_history(self):
|
|
|
151 |
except:
|
152 |
pass
|
153 |
|
|
|
|
|
|
|
|
|
|
|
154 |
prompt = f"""As an empathic AI psychotherapist chatbot, provide effective solutions to patients' mental health concerns.
|
155 |
if patient say thanking tone message to end the conversation with a thanking greeting when the patient expresses gratitude.
|
156 |
Analyse the patient json If asked for information take it from {patient_details}
|
|
|
188 |
customer_emotion=sentiment.emotion_analysis(client)
|
189 |
customer_sentiment_score = sentiment.analyze_sentiment_for_graph(client)
|
190 |
|
|
|
|
|
191 |
|
192 |
scores=self._text_box(customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score)
|
193 |
|
194 |
customer_fig=self._display_graph(customer_sentiment_score)
|
195 |
customer_fig.update_layout(title="Sentiment Analysis",width=775)
|
196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
|
198 |
customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
|
199 |
|
200 |
customer_emotion_fig=self._display_graph(customer_emotion_score)
|
201 |
customer_emotion_fig.update_layout(title="Emotion Analysis",width=775)
|
202 |
|
203 |
+
return scores,customer_fig,customer_emotion_fig
|
204 |
|
205 |
|
206 |
def clear_func(self):
|
|
|
208 |
|
209 |
def gradio_interface(self):
|
210 |
with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
211 |
with gr.Row():
|
212 |
+
gr.HTML("""<img class="image" src="https://www.syrahealth.com/images/SyraHealth_Logo_Dark.svg" alt="Image" width="210" height="210">
|
213 |
+
""")
|
214 |
+
with gr.Row():
|
215 |
+
gr.HTML("""<center><h1>AI Mental Healthcare ChatBot</h1></center>""")
|
216 |
chatbot = gr.Chatbot([], elem_id="chatbot").style(height=360)
|
217 |
with gr.Row():
|
218 |
+
with gr.Column(scale=0.8):
|
219 |
txt = gr.Textbox(
|
220 |
show_label=False,
|
221 |
placeholder="Patient",elem_classes="height"
|
222 |
).style(container=False)
|
223 |
+
|
224 |
+
with gr.Column(scale=0.2):
|
|
|
|
|
|
|
|
|
225 |
emptyBtn = gr.Button(
|
226 |
"🧹 Clear",elem_classes="height"
|
227 |
)
|
|
|
229 |
with gr.Column(scale=0.80):
|
230 |
txt3 =gr.Textbox(
|
231 |
show_label=False,
|
232 |
+
placeholder="AI Healthcare Suggesstion"
|
233 |
).style(container=False)
|
234 |
with gr.Column(scale=0.20, min_width=0):
|
235 |
+
button=gr.Button(value="🚀send")
|
236 |
with gr.Row():
|
237 |
with gr.Column(scale=0.50):
|
238 |
txt4 =gr.Textbox(
|