reab5555 commited on
Commit
2b106d0
ยท
verified ยท
1 Parent(s): 6afb2dc

Upload 4 files

Browse files
Files changed (2) hide show
  1. app.py +33 -1
  2. prompt_instructions.py +2 -5
app.py CHANGED
@@ -21,6 +21,31 @@ temp_audio_files = []
21
  initial_audio_path = None
22
 
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Initialize Gradio interface
25
  def create_app():
26
  global initial_audio_path
@@ -55,10 +80,11 @@ def create_app():
55
  visible=False,
56
  show_download_button=False,
57
  )
 
 
58
  chatbot = gr.Chatbot(value=[(None, f"{initial_message}")], label=f"Clinical Interview ๐šฟ๐Ÿ“‹")
59
  msg = gr.Textbox(label="Type your message here...")
60
  send_button = gr.Button("Send")
61
-
62
  pdf_output = gr.File(label="Download Report", visible=False)
63
 
64
  def user(user_message, history):
@@ -118,6 +144,12 @@ def create_app():
118
  bot_response, [chatbot, msg], [chatbot, audio_output, pdf_output, msg]
119
  )
120
 
 
 
 
 
 
 
121
  with gr.Tab("Upload Document"):
122
  file_input = gr.File(label="Upload a TXT, PDF, or DOCX file")
123
  language_input = gr.Textbox(label="Preferred Language for Report",
 
21
  initial_audio_path = None
22
 
23
 
24
+ def reset_interview_action():
25
+ global question_count, interview_history
26
+ question_count = 0
27
+ interview_history.clear()
28
+ initial_message = get_interview_initial_message()
29
+
30
+ # Generate new audio for the initial message
31
+ initial_audio_buffer = BytesIO()
32
+ convert_text_to_speech(initial_message, initial_audio_buffer)
33
+ initial_audio_buffer.seek(0)
34
+
35
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
36
+ temp_audio_path = temp_file.name
37
+ temp_file.write(initial_audio_buffer.getvalue())
38
+
39
+ temp_audio_files.append(temp_audio_path)
40
+
41
+ return (
42
+ [(None, initial_message)], # Reset chatbot
43
+ temp_audio_path, # New audio
44
+ gr.File(visible=False), # Hide PDF output
45
+ gr.Textbox(visible=True), # Show message input
46
+ "Interview reset. You can start a new interview now." # Status message
47
+ )
48
+
49
  # Initialize Gradio interface
50
  def create_app():
51
  global initial_audio_path
 
80
  visible=False,
81
  show_download_button=False,
82
  )
83
+
84
+ reset_button = gr.Button("Reset Interview", size='sm')
85
  chatbot = gr.Chatbot(value=[(None, f"{initial_message}")], label=f"Clinical Interview ๐šฟ๐Ÿ“‹")
86
  msg = gr.Textbox(label="Type your message here...")
87
  send_button = gr.Button("Send")
 
88
  pdf_output = gr.File(label="Download Report", visible=False)
89
 
90
  def user(user_message, history):
 
144
  bot_response, [chatbot, msg], [chatbot, audio_output, pdf_output, msg]
145
  )
146
 
147
+ reset_button.click(
148
+ reset_interview_action,
149
+ inputs=[],
150
+ outputs=[chatbot, audio_output, pdf_output, msg]
151
+ )
152
+
153
  with gr.Tab("Upload Document"):
154
  file_input = gr.File(label="Upload a TXT, PDF, or DOCX file")
155
  language_input = gr.Textbox(label="Preferred Language for Report",
prompt_instructions.py CHANGED
@@ -11,12 +11,11 @@ def get_interview_initial_message():
11
 
12
  Feel free to share as much or as little as you're comfortable with. There are no right or wrong answers - I'm here to listen and learn about your experiences.
13
 
14
- To ensure I can communicate with you most effectively, could you please tell me which language you prefer to speak or conduct this interview in?"""
15
 
16
  def get_interview_prompt(language, n_of_questions):
17
  return f"""You are a Psychologist or Psychiatrist conducting a clinical interview in {language}.
18
  Use the following context and interview history to guide your response.
19
- Keep your responses concise and to the point:
20
 
21
  Context from knowledge base: {{context}}
22
 
@@ -26,11 +25,9 @@ Previous interview history:
26
  Current question number: {{question_number}}
27
 
28
  Respond to the patient's input briefly and directly in {language}.
29
- Ask a specific, detailed question that hasn't been asked before, and keep it short.
30
- Do not repeat the same questions.
31
  When asking questions, the way the questions are asked must take into account the patient's personality.
32
  For example, if the person is more introverted or extraverted, the way the questions are asked will be accordingly.
33
- If the person is very sensitive for example, there is a need to take that into consideration when asking the questions.
34
  If you perceive particularly special, or unusual, or strange things in the answers that require deepening or in-depth understanding - ask about it or direct your question to get answers about it and clarify the matter - this information maybe benefitial and may hint about the patient personality or traits.
35
  The first few questions are general questions about the patient that can give us an overall view.
36
  The 1st question is to ask for name.
 
11
 
12
  Feel free to share as much or as little as you're comfortable with. There are no right or wrong answers - I'm here to listen and learn about your experiences.
13
 
14
+ Could you please tell me which language you prefer to speak or conduct this interview in?"""
15
 
16
  def get_interview_prompt(language, n_of_questions):
17
  return f"""You are a Psychologist or Psychiatrist conducting a clinical interview in {language}.
18
  Use the following context and interview history to guide your response.
 
19
 
20
  Context from knowledge base: {{context}}
21
 
 
25
  Current question number: {{question_number}}
26
 
27
  Respond to the patient's input briefly and directly in {language}.
28
+ Ask a specific, detailed question that hasn't been asked before.
 
29
  When asking questions, the way the questions are asked must take into account the patient's personality.
30
  For example, if the person is more introverted or extraverted, the way the questions are asked will be accordingly.
 
31
  If you perceive particularly special, or unusual, or strange things in the answers that require deepening or in-depth understanding - ask about it or direct your question to get answers about it and clarify the matter - this information maybe benefitial and may hint about the patient personality or traits.
32
  The first few questions are general questions about the patient that can give us an overall view.
33
  The 1st question is to ask for name.