vsrinivas's picture
Update app.py
a0249ee verified
raw
history blame
2.69 kB
import gradio as gr
import random
from PIL import Image
# from funcs import detect_emotions, cosine_distance, generate_triggers_img, process_session
from funcs import detect_emotions, cosine_distance, generate_triggers_img, get_doc_response_emotions, summarize_and_recommend
# ps = process_session()
# 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)
with gr.Blocks() as demo:
gr.Markdown("""# Falcon Cognitive Behavioural Therapy Assistant
- Your Personal AI Therapist. Start chatting...""")
therapy_session_conversation = gr.State([])
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)
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(get_doc_response_emotions, [user_input, chatbox], [user_input, chatbox, emotions])
user_input.submit(get_doc_response_emotions, [user_input, chatbox], [user_input, chatbox, emotions])
# submit_button.click(ps.get_doc_response_emotions, [user_input, chatbox], [user_input, chatbox, emotions])
# user_input.submit(ps.get_doc_response_emotions, [user_input, chatbox], [user_input, chatbox, emotions])
recommendations = gr.Textbox(label="Recommended Actions", visible = False)
def summarize_and_recommend_process():
# sn, r = ps.summarize_and_recommend()
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(summarize_and_recommend_process, inputs=chatbox, outputs=[summary_notes, recommendations])
demo.launch(debug=True, share=True)