Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from chains import questions
|
| 4 |
+
from chain_reports import generate_short_report_for_session
|
| 5 |
+
from chain_problems import analyze_problems_with_chain
|
| 6 |
+
from chain_recommendations import generate_recommendations
|
| 7 |
+
from chain_summary import generate_final_summary, shorten_summary
|
| 8 |
+
|
| 9 |
+
def process_answers(
|
| 10 |
+
sleep: str,
|
| 11 |
+
exercise: str,
|
| 12 |
+
stress: str,
|
| 13 |
+
goals: str,
|
| 14 |
+
diet: str,
|
| 15 |
+
eating: str,
|
| 16 |
+
relaxation: str,
|
| 17 |
+
health_issues: str,
|
| 18 |
+
manage_stress: str,
|
| 19 |
+
routine: str
|
| 20 |
+
):
|
| 21 |
+
# Map user inputs to questions
|
| 22 |
+
responses = {
|
| 23 |
+
questions[0]: sleep,
|
| 24 |
+
questions[1]: exercise,
|
| 25 |
+
questions[2]: stress,
|
| 26 |
+
questions[3]: goals,
|
| 27 |
+
questions[4]: diet,
|
| 28 |
+
questions[5]: eating,
|
| 29 |
+
questions[6]: relaxation,
|
| 30 |
+
questions[7]: health_issues,
|
| 31 |
+
questions[8]: manage_stress,
|
| 32 |
+
questions[9]: routine
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
report = generate_short_report_for_session(responses)
|
| 36 |
+
problems = analyze_problems_with_chain(responses, report)
|
| 37 |
+
recommendation = generate_recommendations(problems)
|
| 38 |
+
final_summary = generate_final_summary(report, problems, recommendation)
|
| 39 |
+
shortened_summary = shorten_summary(final_summary)
|
| 40 |
+
|
| 41 |
+
wellness_report = f"**Wellness Report**\n------------------\n{report.strip()}"
|
| 42 |
+
identified_problems = (
|
| 43 |
+
"**Identified Problems**\n"
|
| 44 |
+
"-----------------------\n"
|
| 45 |
+
f"Sleep Problem: {problems.get('sleep_problem', 'N/A')}%\n"
|
| 46 |
+
f"Exercise Problem: {problems.get('exercise_problem', 'N/A')}%\n"
|
| 47 |
+
f"Stress Problem: {problems.get('stress_problem', 'N/A')}%\n"
|
| 48 |
+
f"Diet Problem: {problems.get('diet_problem', 'N/A')}%"
|
| 49 |
+
)
|
| 50 |
+
recommendations = (
|
| 51 |
+
"**Recommendations**\n"
|
| 52 |
+
"--------------------\n"
|
| 53 |
+
f"{recommendation.strip()}"
|
| 54 |
+
)
|
| 55 |
+
summary_shown = (
|
| 56 |
+
"**Summary (SHOWN TO USER)**\n"
|
| 57 |
+
"-----------------\n"
|
| 58 |
+
f"{final_summary.strip()}"
|
| 59 |
+
)
|
| 60 |
+
final_summary_video = (
|
| 61 |
+
"**Final Summary (FOR VIDEO CREATION)**\n"
|
| 62 |
+
"-----------------\n"
|
| 63 |
+
f"{shortened_summary.strip()}"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
return wellness_report, identified_problems, recommendations, summary_shown, final_summary_video
|
| 67 |
+
|
| 68 |
+
iface = gr.Interface(
|
| 69 |
+
fn=process_answers,
|
| 70 |
+
inputs=[gr.Textbox(label=q) for q in questions],
|
| 71 |
+
outputs=[
|
| 72 |
+
gr.Markdown(label="Wellness Report"),
|
| 73 |
+
gr.Markdown(label="Identified Problems"),
|
| 74 |
+
gr.Markdown(label="Recommendations"),
|
| 75 |
+
gr.Markdown(label="Summary (SHOWN TO USER)"),
|
| 76 |
+
gr.Markdown(label="Final Summary (FOR VIDEO CREATION)")
|
| 77 |
+
],
|
| 78 |
+
title="Wellness Report Generator",
|
| 79 |
+
description="Answer the questions to generate a wellness report, problem analysis, recommendations, and a final summary."
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
iface.launch()
|