Spaces:
Sleeping
Sleeping
# app.py | |
import gradio as gr | |
from pipeline import process_answers_pipeline # Import the centralized pipeline function | |
from questions import questions # Import questions list | |
def process_answers( | |
sleep, | |
exercise, | |
mood, | |
stress_level, | |
wellness_goals, | |
dietary_restrictions, | |
relaxation_time, | |
health_issues, | |
water_intake, | |
gratitude_feelings, | |
connection_rating, | |
energy_rating | |
): | |
# Map the selected responses to their corresponding questions | |
responses = { | |
questions[0]: sleep, # How many hours of sleep do you get each night? | |
questions[1]: exercise, # How often do you exercise in a week? | |
questions[2]: mood, # On a scale of 1 to 10, how would you rate your mood today? | |
questions[3]: stress_level, # What is your current stress level on a scale from 1 to 10? | |
questions[4]: wellness_goals, # What are your primary wellness goals? | |
questions[5]: dietary_restrictions, # Do you follow any specific diet or have any dietary restrictions? | |
questions[7]: relaxation_time, # How much time do you spend on relaxation or mindfulness activities daily? | |
questions[8]: health_issues, # Do you experience any recurring health issues or pain? | |
questions[12]: water_intake, # How much water do you drink on average per day? | |
questions[23]: gratitude_feelings, # How often do you experience feelings of gratitude or happiness? | |
questions[24]: connection_rating, # On a scale from 1 to 10, how connected do you feel to your friends and family? | |
questions[27]: energy_rating # On a scale from 1 to 10, how would you rate your energy levels throughout the day? | |
} | |
# Process responses using the centralized pipeline | |
results = process_answers_pipeline(responses) | |
# Format outputs using results from the pipeline | |
wellness_report = f"**Wellness Report**\n------------------\n{results['report'].strip()}" | |
identified_problems = ( | |
"**Identified Problems**\n" | |
"-----------------------\n" | |
f"Stress Management: {results['problems'].get('stress_management', 'N/A')}%\n" | |
f"Low Therapy: {results['problems'].get('low_therapy', 'N/A')}%\n" | |
f"Balanced Weight: {results['problems'].get('balanced_weight', 'N/A')}%\n" | |
f"Restless Night: {results['problems'].get('restless_night', 'N/A')}%\n" | |
f"Lack of Motivation: {results['problems'].get('lack_of_motivation', 'N/A')}%\n" | |
f"Gut Health: {results['problems'].get('gut_health', 'N/A')}%\n" | |
f"Anxiety: {results['problems'].get('anxiety', 'N/A')}%\n" | |
f"Burnout: {results['problems'].get('burnout', 'N/A')}%" | |
) | |
recommendations = ( | |
"**Recommendations**\n" | |
"--------------------\n" | |
f"{results['recommendation'].strip()}" | |
) | |
summary_shown = ( | |
"**Summary (SHOWN TO USER)**\n" | |
"-----------------\n" | |
f"{results['final_summary'].strip()}" | |
) | |
final_summary_video = ( | |
"**Final Summary (FOR VIDEO CREATION)**\n" | |
"-----------------\n" | |
f"{results['shortened_summary'].strip()}" | |
) | |
return wellness_report, identified_problems, recommendations, summary_shown, final_summary_video | |
# Define the Gradio interface using only the 12 selected questions | |
iface = gr.Interface( | |
fn=process_answers, | |
inputs=[ | |
gr.Textbox(label=questions[0]), | |
gr.Textbox(label=questions[1]), | |
gr.Textbox(label=questions[2]), | |
gr.Textbox(label=questions[3]), | |
gr.Textbox(label=questions[4]), | |
gr.Textbox(label=questions[5]), | |
gr.Textbox(label=questions[7]), | |
gr.Textbox(label=questions[8]), | |
gr.Textbox(label=questions[12]), | |
gr.Textbox(label=questions[23]), | |
gr.Textbox(label=questions[24]), | |
gr.Textbox(label=questions[27]) | |
], | |
outputs=[ | |
gr.Markdown(label="Wellness Report"), | |
gr.Markdown(label="Identified Problems"), | |
gr.Markdown(label="Recommendations"), | |
gr.Markdown(label="Summary (SHOWN TO USER)"), | |
gr.Markdown(label="Final Summary (FOR VIDEO CREATION)") | |
], | |
title="Wellness Report Generator", | |
description="Answer the questions to generate a wellness report, problem analysis, recommendations, and a final summary." | |
) | |
iface.launch() | |