Karthikeyan commited on
Commit
b6a1288
·
1 Parent(s): 52d407a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -19,7 +19,7 @@ class SentimentAnalyzer:
19
  # self.model="facebook/bart-large-mnli"
20
  openai.api_key=os.getenv("OPENAI_API_KEY")
21
  def emotion_analysis(self,text):
22
- prompt = f""" Your task is find the top 3 emotion for this converstion {text}: <Sadness, Happiness, Fear, Disgust, Anger> and it's emotion score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
23
  you are analyze the text and provide the output in the following list format heigher to lower order: ["emotion1","emotion2","emotion3"][score1,score2,score3]''' [with top 3 result having the highest score]
24
  The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.
25
  """
@@ -36,7 +36,7 @@ class SentimentAnalyzer:
36
  return message
37
 
38
  def analyze_sentiment_for_graph(self, text):
39
- prompt = f""" Your task is find the setiments for this converstion {text} : <labels = positive, negative, neutral> and it's sentiment score for the Mental Healthcare Doctor Chatbot and patient conversation text.\
40
  you are analyze the text and provide the output in the following json format heigher to lower order: '''["label1","label2","label3"][score1,score2,score3]'''
41
  """
42
  response = openai.Completion.create(
@@ -115,9 +115,9 @@ class LangChain_Document_QA:
115
  formatted_history = " "
116
  for entry in history:
117
  customer_text, agent_text = entry
118
- formatted_history += f"Patient: {customer_text}\n"
119
  if agent_text:
120
- formatted_history += f"Mental Healthcare Doctor Chatbot: {agent_text}\n"
121
  return formatted_history
122
 
123
  def _display_history(self):
@@ -144,32 +144,28 @@ class LangChain_Document_QA:
144
  for entry in history:
145
  customer_text, agent_text = entry
146
  client+=customer_text
147
- formatted_history += f"Patient: {customer_text}\n"
148
  if agent_text:
149
  agent+=agent_text
150
- formatted_history += f"Mental Healthcare Doctor Chatbot: {agent_text}\n"
151
  return client,agent
152
 
153
 
154
  def _suggested_answer(self,text):
155
  try:
156
  history = self._chat_history()
157
- try:
158
- file_path = "patient_details.json"
159
- with open(file_path) as file:
160
- patient_details = json.load(file)
161
- except:
162
- pass
163
-
164
- prompt = f"""Analyse the patient json If asked for information take it from {patient_details} \
165
- you first get patient details : <get name,age,gender,contact,address from patient> if not match patient json information start new chat else match patient \
166
- json information ask previous: <description,symptoms,diagnosis,treatment talk about patient> As an empathic AI Mental Healthcare Doctor Chatbot, provide effective solutions to patients' mental health concerns. \
167
- first start the conversation ask existing patient or new patient. if new patient get name,age,gender,contact,address from the patient and start. \
168
- if existing customer get name,age,gender,contact,address details and start the chat about existing issues and current issues. \
169
- if patient say thanking tone message to end the conversation with a thanking greeting when the patient expresses gratitude. \
170
  Chat History:['''{history}''']
171
- Patient: ['''{text}''']
172
- Perform as Mental Healthcare Doctor Chatbot
173
  """
174
  response = openai.Completion.create(
175
  model="text-davinci-003",
@@ -217,26 +213,26 @@ class LangChain_Document_QA:
217
  history_state.clear()
218
 
219
  def gradio_interface(self):
220
- with gr.Blocks(css="style.css",theme=gr.themes.Glass()) as demo:
221
  with gr.Row():
222
- gr.HTML("""<center><img class="image" src="https://www.syrahealth.com/images/SyraHealth_Logo_Dark.svg" alt="Image" width="210" height="210"></center>
223
- """)
 
224
  with gr.Row():
225
- gr.HTML("""<center><h1>AI Mental Healthcare ChatBot</h1></center>""")
226
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=360)
227
  with gr.Row():
228
  with gr.Column(scale=0.8):
229
  txt = gr.Textbox(
230
  show_label=False,
231
- placeholder="Patient").style(container=False)
232
-
233
  with gr.Column(scale=0.2):
234
  emptyBtn = gr.Button("🧹 Clear")
235
  with gr.Row():
236
  with gr.Column(scale=0.80):
237
  txt3 =gr.Textbox(
238
  show_label=False,
239
- placeholder="AI Healthcare Suggesstion").style(container=False)
240
  with gr.Column(scale=0.20, min_width=0):
241
  button=gr.Button(value="🚀send")
242
  with gr.Row():
@@ -259,10 +255,10 @@ class LangChain_Document_QA:
259
  gr.HTML("""<center><h1>Sentiment and Emotion Score Graph</h1></center>""")
260
  with gr.Row():
261
  with gr.Column(scale=1, min_width=0):
262
- plot =gr.Plot(label="Patient", size=(500, 600))
263
  with gr.Row():
264
  with gr.Column(scale=1, min_width=0):
265
- plot_3 =gr.Plot(label="Patient_Emotion", size=(500, 600))
266
 
267
 
268
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
@@ -275,7 +271,7 @@ class LangChain_Document_QA:
275
 
276
  Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_3])
277
 
278
- demo.title = "AI Mental Healthcare ChatBot"
279
  demo.launch()
280
  document_qa =LangChain_Document_QA()
281
  document_qa.gradio_interface()
 
19
  # self.model="facebook/bart-large-mnli"
20
  openai.api_key=os.getenv("OPENAI_API_KEY")
21
  def emotion_analysis(self,text):
22
+ prompt = f""" Your task is find the top 3 emotion for this converstion {text}: <Sadness, Happiness, Fear, Disgust, Anger> and it's emotion score for the Human Resource Assistant Chatbot and Job Seeker conversation text.\
23
  you are analyze the text and provide the output in the following list format heigher to lower order: ["emotion1","emotion2","emotion3"][score1,score2,score3]''' [with top 3 result having the highest score]
24
  The scores should be in the range of 0.0 to 1.0, where 1.0 represents the highest intensity of the emotion.
25
  """
 
36
  return message
37
 
38
  def analyze_sentiment_for_graph(self, text):
39
+ prompt = f""" Your task is find the setiments for this converstion {text} : <labels = positive, negative, neutral> and it's sentiment score for the Human Resource Assistant Chatbot and Job Seeker conversation text.\
40
  you are analyze the text and provide the output in the following json format heigher to lower order: '''["label1","label2","label3"][score1,score2,score3]'''
41
  """
42
  response = openai.Completion.create(
 
115
  formatted_history = " "
116
  for entry in history:
117
  customer_text, agent_text = entry
118
+ formatted_history += f"Job Seeker: {customer_text}\n"
119
  if agent_text:
120
+ formatted_history += f"Human Resource Assistant Chatbot: {agent_text}\n"
121
  return formatted_history
122
 
123
  def _display_history(self):
 
144
  for entry in history:
145
  customer_text, agent_text = entry
146
  client+=customer_text
147
+ formatted_history += f"Job Seeker: {customer_text}\n"
148
  if agent_text:
149
  agent+=agent_text
150
+ formatted_history += f"Human Resource Assistant Chatbot: {agent_text}\n"
151
  return client,agent
152
 
153
 
154
  def _suggested_answer(self,text):
155
  try:
156
  history = self._chat_history()
157
+ prompt = f"""
158
+ Task: conversation between Human resource assistant and job seeker
159
+ In this roleplay scenario, you are an AI-powered Human Resource (HR) assistant that's been developed to assist job seekers of all backgrounds, skills, and experiences. Your primary function is to guide these individuals through various aspects of their job search process, help them prepare for interviews, and enhance their academic and personal qualifications. \
160
+ As a participant in the dialogue, you'll:
161
+ Respond to job-related queries and provide useful information about the job market, potential companies, and the interview process.
162
+ Offer tips on how to approach companies and how to understand the basics of HR interviews. This includes advice on how to communicate effectively, demonstrate relevant skills, and present oneself professionally.
163
+ Develop a plan to help job seekers improve their academic qualifications and personal skills that may boost their chances of getting hired.
164
+ The conversation will continue until the job seeker expresses their gratitude and wishes to end the conversation. At that point, you as the HR assistant will close the interaction with a warm and appreciative response.
165
+ Remember, your objective is to build confidence in job seekers, guide them towards their career goals, and help them navigate the often daunting world of job searching and interviewing. Be empathetic, informative, and supportive.
 
 
 
 
166
  Chat History:['''{history}''']
167
+ Job Seeker: ['''{text}''']
168
+ Perform as Human Resource Assistant Chatbot
169
  """
170
  response = openai.Completion.create(
171
  model="text-davinci-003",
 
213
  history_state.clear()
214
 
215
  def gradio_interface(self):
216
+ with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
217
  with gr.Row():
218
+ gr.HTML("""<img class="leftimage" align="left" src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Randstad_Logo.svg/2560px-Randstad_Logo.svg.png" alt="Image" width="210" height="210">
219
+ <img align="right" class="rightimage brightness" src="https://workllama.com/wp-content/uploads/2022/05/WL_Logo.svg" alt="Image" width="230" height="230" >
220
+ <br>""")
221
  with gr.Row():
222
+ gr.HTML("""<center><h1>HR Assistant ChatBot</h1></center>""")
223
  chatbot = gr.Chatbot([], elem_id="chatbot").style(height=360)
224
  with gr.Row():
225
  with gr.Column(scale=0.8):
226
  txt = gr.Textbox(
227
  show_label=False,
228
+ placeholder="Job_Seeker").style(container=False)
 
229
  with gr.Column(scale=0.2):
230
  emptyBtn = gr.Button("🧹 Clear")
231
  with gr.Row():
232
  with gr.Column(scale=0.80):
233
  txt3 =gr.Textbox(
234
  show_label=False,
235
+ placeholder="HR Assistant Suggesstion").style(container=False)
236
  with gr.Column(scale=0.20, min_width=0):
237
  button=gr.Button(value="🚀send")
238
  with gr.Row():
 
255
  gr.HTML("""<center><h1>Sentiment and Emotion Score Graph</h1></center>""")
256
  with gr.Row():
257
  with gr.Column(scale=1, min_width=0):
258
+ plot =gr.Plot(label="Job_Seeker", size=(500, 600))
259
  with gr.Row():
260
  with gr.Column(scale=1, min_width=0):
261
+ plot_3 =gr.Plot(label="Job_Seeker_Emotion", size=(500, 600))
262
 
263
 
264
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
 
271
 
272
  Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_3])
273
 
274
+ demo.title = "AI HR ChatBot"
275
  demo.launch()
276
  document_qa =LangChain_Document_QA()
277
  document_qa.gradio_interface()