parass13 commited on
Commit
8b43d60
·
verified ·
1 Parent(s): c51f3d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -36
app.py CHANGED
@@ -4,6 +4,11 @@ import gradio as gr
4
  from components.auth import register, login, logout
5
  from components.predict import predict
6
  from components.report_generator import create_report
 
 
 
 
 
7
 
8
  # --- Style and Theme ---
9
  css = """
@@ -11,12 +16,12 @@ css = """
11
  .centered-text { text-align: center; }
12
  """
13
 
14
- with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as demo:
15
 
16
  user_state = gr.State({"email": None, "id": None, "logged_in": False, "gender": None, "username": None})
17
 
18
  # --- Static Header (Always Visible) ---
19
- gr.Markdown("# 🩺 Welcome to DiaSpark: An AI-based Diabetes Detector")
20
 
21
  # --- Personalized Header (Visible only when logged in) ---
22
  with gr.Row(visible=False) as logged_in_header:
@@ -25,8 +30,8 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
25
  # --- Main Tabs ---
26
  with gr.Tabs() as main_tabs:
27
 
28
- # --- Homepage Tab (Full content restored) ---
29
- with gr.TabItem("Home", id="home_tab"):
30
  gr.Markdown(
31
  "<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
32
  elem_classes="centered-text"
@@ -66,34 +71,19 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
66
  The results from DiaSpark are for informational purposes only. Always seek the advice of your physician or another qualified health provider with any questions you may have regarding a medical condition. Never disregard professional medical advice or delay in seeking it because of something you have read or seen on this application.
67
  """
68
  )
69
-
70
- # --- Authentication Tab ---
71
- with gr.TabItem("Login / Signup", id="auth_tab"):
72
- auth_message = gr.Markdown()
73
 
74
- with gr.Column(visible=True) as login_col:
75
- gr.Markdown("### Login to Your Account")
76
- email_login = gr.Textbox(label="Email", placeholder="Enter your email")
77
- pwd_login = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
78
- login_btn = gr.Button("Login", variant="primary")
79
- show_signup_btn = gr.Button("New user? Sign up here.", variant="secondary")
80
-
81
- with gr.Column(visible=False) as signup_col:
82
- gr.Markdown("### Create a New Account")
83
- username_signup = gr.Textbox(label="Username", placeholder="Choose a unique username")
84
- email_signup = gr.Textbox(label="Email", placeholder="Enter your email")
85
- pwd_signup = gr.Textbox(
86
- label="Password",
87
- type="password",
88
- placeholder="Create a password",
89
- info="Must be at least 6 characters long."
90
- )
91
- gender_signup = gr.Radio(["Female", "Male"], label="Gender", info="This determines if the 'Pregnancies' field is shown.")
92
- signup_btn = gr.Button("Sign Up", variant="primary")
93
- show_login_btn = gr.Button("Already have an account? Login.", variant="secondary")
94
 
95
- # --- Prediction Tab (Correctly Ordered) ---
96
- with gr.TabItem("Prediction", id="prediction_tab"):
97
 
98
  with gr.Column(visible=False) as prediction_view:
99
  gr.Markdown("### Enter Your Health Metrics for Prediction")
@@ -116,7 +106,6 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
116
 
117
  result_output = gr.Textbox(label="Prediction Result", interactive=False)
118
 
119
- # The report generation UI components are defined here
120
  generate_report_btn = gr.Button("Download Report as PDF", variant="secondary", visible=False)
121
  report_file_output = gr.File(label="Your Report", visible=False)
122
 
@@ -132,16 +121,41 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
132
  """
133
  )
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
- # --- Component Logic (Event Handlers) (Correctly Ordered) ---
137
 
138
- # --- Handlers for UI switching ---
139
  def switch_to_signup(): return gr.update(visible=False), gr.update(visible=True)
140
  def switch_to_login(): return gr.update(visible=True), gr.update(visible=False)
141
  show_signup_btn.click(fn=switch_to_signup, outputs=[login_col, signup_col])
142
  show_login_btn.click(fn=switch_to_login, outputs=[login_col, signup_col])
143
 
144
- # --- Handler for main state changes (login/logout UI updates) ---
145
  def handle_user_state_change(user_data):
146
  is_logged_in = user_data.get("logged_in", False)
147
  is_female = user_data.get("gender") == "Female"
@@ -156,12 +170,12 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
156
  )
157
  user_state.change(fn=handle_user_state_change, inputs=user_state, outputs=[prediction_view, logged_out_view, pregnancies_row, welcome_message, logged_in_header])
158
 
159
- # --- Handlers for core auth actions ---
160
  signup_btn.click(fn=register, inputs=[email_signup, pwd_signup, gender_signup, username_signup], outputs=[auth_message, email_signup, pwd_signup, gender_signup, username_signup])
161
  login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state, main_tabs])
162
  logout_btn.click(fn=logout, inputs=[user_state], outputs=[auth_message, user_state, main_tabs, email_login, pwd_login, preg, glucose, bp, insulin, bmi, age, result_output, pregnancies_row])
163
 
164
- # --- Handlers for prediction and report generation ---
165
  def handle_create_report(user, p, g, b, i, bm, a, result):
166
  if not result:
167
  return gr.update(visible=False)
 
4
  from components.auth import register, login, logout
5
  from components.predict import predict
6
  from components.report_generator import create_report
7
+ # --- NEW IMPORTS ---
8
+ # Import the render functions from our new content components
9
+ from components.diabetes_factors import render_factors_info
10
+ from components.food_suggestions import render_food_guide
11
+ from components.doctor_info import render_doctor_list
12
 
13
  # --- Style and Theme ---
14
  css = """
 
16
  .centered-text { text-align: center; }
17
  """
18
 
19
+ with gr.Blocks(title="DiaSpark: Your Health Management Platform", css=css) as demo:
20
 
21
  user_state = gr.State({"email": None, "id": None, "logged_in": False, "gender": None, "username": None})
22
 
23
  # --- Static Header (Always Visible) ---
24
+ gr.Markdown("# 🩺 Welcome to DiaSpark: Your Health Management Platform")
25
 
26
  # --- Personalized Header (Visible only when logged in) ---
27
  with gr.Row(visible=False) as logged_in_header:
 
30
  # --- Main Tabs ---
31
  with gr.Tabs() as main_tabs:
32
 
33
+ # --- Homepage Tab ---
34
+ with gr.TabItem("Home 🏠", id="home_tab"):
35
  gr.Markdown(
36
  "<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
37
  elem_classes="centered-text"
 
71
  The results from DiaSpark are for informational purposes only. Always seek the advice of your physician or another qualified health provider with any questions you may have regarding a medical condition. Never disregard professional medical advice or delay in seeking it because of something you have read or seen on this application.
72
  """
73
  )
74
+
75
+ # --- NEW INFORMATIONAL TABS ---
76
+ with gr.TabItem("Learn About Diabetes 📚"):
77
+ render_factors_info()
78
 
79
+ with gr.TabItem("Healthy Eating Guide 🥗"):
80
+ render_food_guide()
81
+
82
+ with gr.TabItem("Find a Specialist 🧑‍⚕️"):
83
+ render_doctor_list()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
+ # --- Interactive Prediction Tab ---
86
+ with gr.TabItem("Prediction Tool 🔬", id="prediction_tab"):
87
 
88
  with gr.Column(visible=False) as prediction_view:
89
  gr.Markdown("### Enter Your Health Metrics for Prediction")
 
106
 
107
  result_output = gr.Textbox(label="Prediction Result", interactive=False)
108
 
 
109
  generate_report_btn = gr.Button("Download Report as PDF", variant="secondary", visible=False)
110
  report_file_output = gr.File(label="Your Report", visible=False)
111
 
 
121
  """
122
  )
123
 
124
+ # --- Authentication Tab ---
125
+ with gr.TabItem("Login / Signup", id="auth_tab"):
126
+ auth_message = gr.Markdown()
127
+
128
+ with gr.Column(visible=True) as login_col:
129
+ gr.Markdown("### Login to Your Account")
130
+ email_login = gr.Textbox(label="Email", placeholder="Enter your email")
131
+ pwd_login = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
132
+ login_btn = gr.Button("Login", variant="primary")
133
+ show_signup_btn = gr.Button("New user? Sign up here.", variant="secondary")
134
+
135
+ with gr.Column(visible=False) as signup_col:
136
+ gr.Markdown("### Create a New Account")
137
+ username_signup = gr.Textbox(label="Username", placeholder="Choose a unique username")
138
+ email_signup = gr.Textbox(label="Email", placeholder="Enter your email")
139
+ pwd_signup = gr.Textbox(
140
+ label="Password",
141
+ type="password",
142
+ placeholder="Create a password",
143
+ info="Must be at least 6 characters long."
144
+ )
145
+ gender_signup = gr.Radio(["Female", "Male"], label="Gender", info="This determines if the 'Pregnancies' field is shown.")
146
+ signup_btn = gr.Button("Sign Up", variant="primary")
147
+ show_login_btn = gr.Button("Already have an account? Login.", variant="secondary")
148
+
149
 
150
+ # --- Component Logic (Event Handlers) ---
151
 
152
+ # Handlers for UI switching
153
  def switch_to_signup(): return gr.update(visible=False), gr.update(visible=True)
154
  def switch_to_login(): return gr.update(visible=True), gr.update(visible=False)
155
  show_signup_btn.click(fn=switch_to_signup, outputs=[login_col, signup_col])
156
  show_login_btn.click(fn=switch_to_login, outputs=[login_col, signup_col])
157
 
158
+ # Handler for main state changes (login/logout UI updates)
159
  def handle_user_state_change(user_data):
160
  is_logged_in = user_data.get("logged_in", False)
161
  is_female = user_data.get("gender") == "Female"
 
170
  )
171
  user_state.change(fn=handle_user_state_change, inputs=user_state, outputs=[prediction_view, logged_out_view, pregnancies_row, welcome_message, logged_in_header])
172
 
173
+ # Handlers for core auth actions
174
  signup_btn.click(fn=register, inputs=[email_signup, pwd_signup, gender_signup, username_signup], outputs=[auth_message, email_signup, pwd_signup, gender_signup, username_signup])
175
  login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state, main_tabs])
176
  logout_btn.click(fn=logout, inputs=[user_state], outputs=[auth_message, user_state, main_tabs, email_login, pwd_login, preg, glucose, bp, insulin, bmi, age, result_output, pregnancies_row])
177
 
178
+ # Handlers for prediction and report generation
179
  def handle_create_report(user, p, g, b, i, bm, a, result):
180
  if not result:
181
  return gr.update(visible=False)