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