Update app.py
Browse files
app.py
CHANGED
@@ -2,21 +2,34 @@ import gradio as gr
|
|
2 |
import random
|
3 |
from PIL import Image
|
4 |
|
5 |
-
from funcs import detect_emotions, cosine_distance, generate_triggers_img,
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
img_1 = Image.open(img_path)
|
12 |
|
13 |
-
|
14 |
-
|
|
|
15 |
|
|
|
|
|
|
|
|
|
16 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
gr.Markdown("""# Falcon Cognitive Behavioural Therapy Assistant
|
18 |
- Your Personal AI Therapist. Start chatting...""")
|
19 |
-
|
20 |
|
21 |
with gr.Row():
|
22 |
|
@@ -29,17 +42,17 @@ with gr.Blocks() as demo:
|
|
29 |
chatbox = gr.Chatbot(label="Therapy Session Conversation",value =[[None, 'Therapist: Hello, What can I do for you?']], height=300)
|
30 |
user_input = gr.Textbox(placeholder="Enter your message here...", label="User")
|
31 |
submit_button = gr.Button("Submit")
|
32 |
-
submit_button.click(
|
33 |
-
user_input.submit(
|
34 |
recommendations = gr.Textbox(label="Recommended Actions", visible = False)
|
35 |
|
36 |
def summarize_and_recommend_process():
|
37 |
-
sn, r =
|
38 |
return gr.update(visible=True, value=sn), gr.update(visible=True, value=r)
|
39 |
|
40 |
process_button = gr.Button("Generate Session Notes & Recommendations")
|
41 |
clear = gr.ClearButton(components=[user_input, chatbox, emotions, summary_notes, recommendations], value="Clear console")
|
42 |
-
process_button.click(
|
43 |
|
44 |
|
45 |
demo.launch(debug=True, share=True)
|
|
|
2 |
import random
|
3 |
from PIL import Image
|
4 |
|
5 |
+
from funcs import detect_emotions, cosine_distance, generate_triggers_img, get_doc_response_emotions, summarize_and_recommend
|
6 |
|
7 |
+
# img_paths = ['2.jpg','3.jpeg','4.jpeg','5.jpeg','6.jpeg']
|
8 |
+
# img_path = random.choice(img_paths)
|
9 |
+
# img_1 = Image.open(img_path)
|
10 |
|
11 |
+
# img_path = '7.jpg'
|
12 |
+
# img_2 = Image.open(img_path)
|
|
|
13 |
|
14 |
+
def submit(user_message, therapy_session_conversation, session_conversation):
|
15 |
+
response = get_doc_response_emotions(user_message, therapy_session_conversation)
|
16 |
+
return '', therapy_session_conversation, emotions_msg
|
17 |
|
18 |
+
def sum_rec(session_conversation):
|
19 |
+
full_summary, full_recommendations = summarize_and_recommend(session_conversation)
|
20 |
+
return full_summary, full_recommendations
|
21 |
+
|
22 |
with gr.Blocks() as demo:
|
23 |
+
img_paths = ['2.jpg','3.jpeg','4.jpeg','5.jpeg','6.jpeg']
|
24 |
+
img_path = random.choice(img_paths)
|
25 |
+
img_1 = Image.open(img_path)
|
26 |
+
|
27 |
+
img_path = '7.jpg'
|
28 |
+
img_2 = Image.open(img_path)
|
29 |
+
|
30 |
gr.Markdown("""# Falcon Cognitive Behavioural Therapy Assistant
|
31 |
- Your Personal AI Therapist. Start chatting...""")
|
32 |
+
session_conversation = gr.State([])
|
33 |
|
34 |
with gr.Row():
|
35 |
|
|
|
42 |
chatbox = gr.Chatbot(label="Therapy Session Conversation",value =[[None, 'Therapist: Hello, What can I do for you?']], height=300)
|
43 |
user_input = gr.Textbox(placeholder="Enter your message here...", label="User")
|
44 |
submit_button = gr.Button("Submit")
|
45 |
+
submit_button.click(submit, [user_input, chatbox], [user_input, chatbox, emotions])
|
46 |
+
user_input.submit(submit, [user_input, chatbox], [user_input, chatbox, emotions])
|
47 |
recommendations = gr.Textbox(label="Recommended Actions", visible = False)
|
48 |
|
49 |
def summarize_and_recommend_process():
|
50 |
+
sn, r = summarize_and_recommend()
|
51 |
return gr.update(visible=True, value=sn), gr.update(visible=True, value=r)
|
52 |
|
53 |
process_button = gr.Button("Generate Session Notes & Recommendations")
|
54 |
clear = gr.ClearButton(components=[user_input, chatbox, emotions, summary_notes, recommendations], value="Clear console")
|
55 |
+
process_button.click(sum_rec, inputs=None, outputs=[summary_notes, recommendations])
|
56 |
|
57 |
|
58 |
demo.launch(debug=True, share=True)
|