parass13 commited on
Commit
1737776
·
verified ·
1 Parent(s): 6fb0a45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -45
app.py CHANGED
@@ -4,8 +4,6 @@ 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
- # --- 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
@@ -27,10 +25,10 @@ with gr.Blocks(title="DiaSpark: Your Health Management Platform", css=css) as de
27
  with gr.Row(visible=False) as logged_in_header:
28
  welcome_message = gr.Markdown()
29
 
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>",
@@ -71,8 +69,33 @@ with gr.Blocks(title="DiaSpark: Your Health Management Platform", css=css) as de
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
 
@@ -82,7 +105,6 @@ with gr.Blocks(title="DiaSpark: Your Health Management Platform", css=css) as de
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:
@@ -121,61 +143,26 @@ with gr.Blocks(title="DiaSpark: Your Health Management Platform", css=css) as de
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"
162
  username = user_data.get("username", "User")
163
  welcome_text = f"### 👋 Welcome, {username}!"
164
- return (
165
- gr.update(visible=is_logged_in),
166
- gr.update(visible=not is_logged_in),
167
- gr.update(visible=is_female),
168
- gr.update(value=welcome_text),
169
- gr.update(visible=is_logged_in)
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)
 
4
  from components.auth import register, login, logout
5
  from components.predict import predict
6
  from components.report_generator import create_report
 
 
7
  from components.diabetes_factors import render_factors_info
8
  from components.food_suggestions import render_food_guide
9
  from components.doctor_info import render_doctor_list
 
25
  with gr.Row(visible=False) as logged_in_header:
26
  welcome_message = gr.Markdown()
27
 
28
+ # --- Main Tabs ---
29
  with gr.Tabs() as main_tabs:
30
 
31
+ # --- Tab 1: Homepage ---
32
  with gr.TabItem("Home 🏠", id="home_tab"):
33
  gr.Markdown(
34
  "<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
 
69
  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.
70
  """
71
  )
72
+
73
+ # --- Tab 2: Authentication (Moved Up) ---
74
+ with gr.TabItem("Login / Signup", id="auth_tab"):
75
+ auth_message = gr.Markdown()
76
+
77
+ with gr.Column(visible=True) as login_col:
78
+ gr.Markdown("### Login to Your Account")
79
+ email_login = gr.Textbox(label="Email", placeholder="Enter your email")
80
+ pwd_login = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
81
+ login_btn = gr.Button("Login", variant="primary")
82
+ show_signup_btn = gr.Button("New user? Sign up here.", variant="secondary")
83
+
84
+ with gr.Column(visible=False) as signup_col:
85
+ gr.Markdown("### Create a New Account")
86
+ username_signup = gr.Textbox(label="Username", placeholder="Choose a unique username")
87
+ email_signup = gr.Textbox(label="Email", placeholder="Enter your email")
88
+ pwd_signup = gr.Textbox(
89
+ label="Password",
90
+ type="password",
91
+ placeholder="Create a password",
92
+ info="Must be at least 6 characters long."
93
+ )
94
+ gender_signup = gr.Radio(["Female", "Male"], label="Gender", info="This determines if the 'Pregnancies' field is shown.")
95
+ signup_btn = gr.Button("Sign Up", variant="primary")
96
+ show_login_btn = gr.Button("Already have an account? Login.", variant="secondary")
97
+
98
+ # --- The rest of the informational and tool tabs ---
99
  with gr.TabItem("Learn About Diabetes 📚"):
100
  render_factors_info()
101
 
 
105
  with gr.TabItem("Find a Specialist 🧑‍⚕️"):
106
  render_doctor_list()
107
 
 
108
  with gr.TabItem("Prediction Tool 🔬", id="prediction_tab"):
109
 
110
  with gr.Column(visible=False) as prediction_view:
 
143
  """
144
  )
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  # --- Component Logic (Event Handlers) ---
147
+ # NOTE: No changes are needed in the event handlers for this reordering.
148
+
149
  def switch_to_signup(): return gr.update(visible=False), gr.update(visible=True)
150
  def switch_to_login(): return gr.update(visible=True), gr.update(visible=False)
151
  show_signup_btn.click(fn=switch_to_signup, outputs=[login_col, signup_col])
152
  show_login_btn.click(fn=switch_to_login, outputs=[login_col, signup_col])
153
 
 
154
  def handle_user_state_change(user_data):
155
  is_logged_in = user_data.get("logged_in", False)
156
  is_female = user_data.get("gender") == "Female"
157
  username = user_data.get("username", "User")
158
  welcome_text = f"### 👋 Welcome, {username}!"
159
+ return (gr.update(visible=is_logged_in), gr.update(visible=not is_logged_in), gr.update(visible=is_female), gr.update(value=welcome_text), gr.update(visible=is_logged_in))
 
 
 
 
 
 
160
  user_state.change(fn=handle_user_state_change, inputs=user_state, outputs=[prediction_view, logged_out_view, pregnancies_row, welcome_message, logged_in_header])
161
 
 
162
  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])
163
  login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state, main_tabs])
164
  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])
165
 
 
166
  def handle_create_report(user, p, g, b, i, bm, a, result):
167
  if not result:
168
  return gr.update(visible=False)