Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from agents import run_first_aider, run_introspect, run_journaling_pipeline | |
| from journal_utils import ( | |
| log_entry, log_chat_interaction, export_to_pdf, export_to_md, | |
| generate_emotion_map, get_weekly_summary, get_counselor_view | |
| ) | |
| chat_history = [] | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## π€ MoodJournal Bot") | |
| with gr.Tab("π£οΈ Empathetic Chat"): | |
| mood = gr.Radio(["π", "π", "π’", "π ", "π°"], label="Your Mood") | |
| user_input = gr.Textbox(label="Talk to me", lines=2) | |
| chat_output = gr.Chatbot(label="AI Listener") | |
| chat_btn = gr.Button("Send") | |
| introspect_btn = gr.Button("πͺ Introspect with AI") | |
| def handle_chat(msg, mood): | |
| ai = run_first_aider(msg, mood) | |
| chat_history.append((msg, ai)) | |
| log_chat_interaction(msg, ai, mood) | |
| return chat_history | |
| chat_btn.click(handle_chat, [user_input, mood], chat_output) | |
| def start_introspect(msg, mood): | |
| reply = run_introspect(msg, mood) | |
| chat_history.append(("Introspect", reply)) | |
| return chat_history | |
| introspect_btn.click(start_introspect, [user_input, mood], chat_output) | |
| with gr.Tab("π Journal"): | |
| mode = gr.Radio(["Adult (Personal Growth)", "Workplace (EAP-Focused)"]) | |
| mood_j = gr.Radio(["π", "π", "π’", "π ", "π°"], label="Mood") | |
| entry = gr.Textbox(lines=6, label="Write your thoughts") | |
| outbox = gr.Textbox(label="AI Response") | |
| btn = gr.Button("Submit") | |
| def journal_entry_flow(mood, entry, mode): | |
| result = run_journaling_pipeline(mood, entry, mode) | |
| log_entry(result) | |
| return result["response"] | |
| btn.click(journal_entry_flow, [mood_j, entry, mode], outbox) | |
| gr.Button("Export to PDF").click(export_to_pdf, [entry, mood_j, mode]) | |
| gr.Button("Export to Markdown").click(export_to_md, [entry, mood_j, mode]) | |
| with gr.Tab("π Counselor View"): | |
| gr.Button("Generate Weekly Mood Chart").click(generate_emotion_map, outputs=gr.Image()) | |
| gr.Button("Get Weekly Summary").click(get_weekly_summary, outputs=gr.JSON()) | |
| gr.Button("Get Counselor Insights").click(get_counselor_view, outputs=gr.Textbox()) | |
| demo.launch(share=True) | |