Update app.py
Browse files
app.py
CHANGED
|
@@ -4,29 +4,26 @@ import gradio as gr
|
|
| 4 |
from components.auth import register, login, logout
|
| 5 |
from components.predict import predict
|
| 6 |
|
| 7 |
-
# ---
|
| 8 |
-
#
|
| 9 |
-
# adapt to the user's system Light or Dark mode, ensuring visibility.
|
| 10 |
css = """
|
| 11 |
.gradio-container { max-width: 1000px !important; margin: auto !important; }
|
| 12 |
.centered-text { text-align: center; }
|
| 13 |
"""
|
| 14 |
|
| 15 |
-
# The theme argument is removed to enable automatic light/dark mode detection.
|
| 16 |
with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as demo:
|
| 17 |
|
| 18 |
-
# A state object to hold the user's session information.
|
| 19 |
user_state = gr.State({"email": None, "logged_in": False})
|
| 20 |
|
| 21 |
# --- Header ---
|
| 22 |
-
# The "Current User" box has been completely removed for a cleaner look.
|
| 23 |
gr.Markdown("# 🩺 Welcome to DiaSpark: An AI-based Diabetes Detector")
|
| 24 |
gr.Markdown("#### Your Proactive Partner in Health Awareness")
|
| 25 |
|
| 26 |
# --- Main Tabs ---
|
| 27 |
with gr.Tabs():
|
| 28 |
|
| 29 |
-
# --- Homepage Tab
|
| 30 |
with gr.TabItem("Home"):
|
| 31 |
gr.Markdown(
|
| 32 |
"<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
|
|
@@ -68,29 +65,32 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
|
|
| 68 |
"""
|
| 69 |
)
|
| 70 |
|
| 71 |
-
# --- Authentication Tab ---
|
| 72 |
with gr.TabItem("Login / Signup"):
|
| 73 |
-
# This Markdown component will now be the primary place for login/logout status messages.
|
| 74 |
auth_message = gr.Markdown()
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# --- Prediction Tab ---
|
| 96 |
with gr.TabItem("Prediction"):
|
|
@@ -111,12 +111,30 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", css=css) as dem
|
|
| 111 |
|
| 112 |
|
| 113 |
# --- Component Logic (Event Handlers) ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
signup_btn.click(fn=register, inputs=[email_signup, pwd_signup], outputs=[auth_message])
|
| 115 |
login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state])
|
| 116 |
logout_btn.click(fn=logout, inputs=[user_state], outputs=[auth_message, user_state])
|
| 117 |
-
|
| 118 |
-
# The logic to update the old user status box has been removed.
|
| 119 |
-
|
| 120 |
predict_btn.click(fn=predict, inputs=[preg, glucose, bp, insulin, bmi, age, user_state], outputs=[result_output])
|
| 121 |
|
| 122 |
# --- Launch the App ---
|
|
|
|
| 4 |
from components.auth import register, login, logout
|
| 5 |
from components.predict import predict
|
| 6 |
|
| 7 |
+
# --- Style and Theme ---
|
| 8 |
+
# Using default theme for automatic light/dark mode compatibility.
|
|
|
|
| 9 |
css = """
|
| 10 |
.gradio-container { max-width: 1000px !important; margin: auto !important; }
|
| 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 |
+
# A state object to hold the user's session information.
|
| 17 |
user_state = gr.State({"email": None, "logged_in": False})
|
| 18 |
|
| 19 |
# --- Header ---
|
|
|
|
| 20 |
gr.Markdown("# 🩺 Welcome to DiaSpark: An AI-based Diabetes Detector")
|
| 21 |
gr.Markdown("#### Your Proactive Partner in Health Awareness")
|
| 22 |
|
| 23 |
# --- Main Tabs ---
|
| 24 |
with gr.Tabs():
|
| 25 |
|
| 26 |
+
# --- Homepage Tab ---
|
| 27 |
with gr.TabItem("Home"):
|
| 28 |
gr.Markdown(
|
| 29 |
"<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
|
|
|
|
| 65 |
"""
|
| 66 |
)
|
| 67 |
|
| 68 |
+
# --- NEW: Revamped Authentication Tab ---
|
| 69 |
with gr.TabItem("Login / Signup"):
|
|
|
|
| 70 |
auth_message = gr.Markdown()
|
| 71 |
+
|
| 72 |
+
# --- Login Form (Initially Visible) ---
|
| 73 |
+
with gr.Column(visible=True) as login_col:
|
| 74 |
+
gr.Markdown("### Login to Your Account")
|
| 75 |
+
email_login = gr.Textbox(label="Email", placeholder="Enter your email")
|
| 76 |
+
pwd_login = gr.Textbox(label="Password", type="password", placeholder="Enter your password")
|
| 77 |
+
login_btn = gr.Button("Login", variant="primary")
|
| 78 |
+
show_signup_btn = gr.Button("New user? Sign up here.", variant="secondary")
|
| 79 |
+
logout_btn = gr.Button("Logout")
|
| 80 |
+
|
| 81 |
+
# --- Signup Form (Initially Hidden) ---
|
| 82 |
+
with gr.Column(visible=False) as signup_col:
|
| 83 |
+
gr.Markdown("### Create a New Account")
|
| 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 |
+
signup_btn = gr.Button("Sign Up", variant="primary")
|
| 92 |
+
show_login_btn = gr.Button("Already have an account? Login.", variant="secondary")
|
| 93 |
+
|
| 94 |
|
| 95 |
# --- Prediction Tab ---
|
| 96 |
with gr.TabItem("Prediction"):
|
|
|
|
| 111 |
|
| 112 |
|
| 113 |
# --- Component Logic (Event Handlers) ---
|
| 114 |
+
|
| 115 |
+
# --- NEW: Handlers to switch between Login and Signup forms ---
|
| 116 |
+
def switch_to_signup():
|
| 117 |
+
return gr.update(visible=False), gr.update(visible=True)
|
| 118 |
+
|
| 119 |
+
def switch_to_login():
|
| 120 |
+
return gr.update(visible=True), gr.update(visible=False)
|
| 121 |
+
|
| 122 |
+
show_signup_btn.click(
|
| 123 |
+
fn=switch_to_signup,
|
| 124 |
+
inputs=None,
|
| 125 |
+
outputs=[login_col, signup_col]
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
show_login_btn.click(
|
| 129 |
+
fn=switch_to_login,
|
| 130 |
+
inputs=None,
|
| 131 |
+
outputs=[login_col, signup_col]
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
# Existing handlers for auth and prediction
|
| 135 |
signup_btn.click(fn=register, inputs=[email_signup, pwd_signup], outputs=[auth_message])
|
| 136 |
login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state])
|
| 137 |
logout_btn.click(fn=logout, inputs=[user_state], outputs=[auth_message, user_state])
|
|
|
|
|
|
|
|
|
|
| 138 |
predict_btn.click(fn=predict, inputs=[preg, glucose, bp, insulin, bmi, age, user_state], outputs=[result_output])
|
| 139 |
|
| 140 |
# --- Launch the App ---
|