Update app.py
Browse files
app.py
CHANGED
|
@@ -4,47 +4,29 @@ import gradio as gr
|
|
| 4 |
from components.auth import register, login, logout
|
| 5 |
from components.predict import predict
|
| 6 |
|
| 7 |
-
# --- 1. New
|
| 8 |
-
#
|
| 9 |
-
#
|
| 10 |
-
theme = gr.themes.Monochrome(
|
| 11 |
-
primary_hue="indigo",
|
| 12 |
-
secondary_hue="blue",
|
| 13 |
-
neutral_hue="slate"
|
| 14 |
-
)
|
| 15 |
-
|
| 16 |
css = """
|
| 17 |
-
.gradio-container {
|
| 18 |
-
max-width: 1000px !important;
|
| 19 |
-
margin: auto !important;
|
| 20 |
-
background-color: #F7F7F7 !important; /* Soft off-white background for the whole app */
|
| 21 |
-
}
|
| 22 |
.centered-text { text-align: center; }
|
| 23 |
"""
|
| 24 |
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
# A state object to hold the user's session information
|
| 28 |
user_state = gr.State({"email": None, "logged_in": False})
|
| 29 |
|
| 30 |
# --- Header ---
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
gr.Markdown("#### Your Proactive Partner in Health Awareness")
|
| 35 |
|
| 36 |
-
with gr.Column(scale=1, min_width=200):
|
| 37 |
-
login_status_display = gr.Textbox(
|
| 38 |
-
label="Current User",
|
| 39 |
-
value="Not logged in",
|
| 40 |
-
interactive=False,
|
| 41 |
-
max_lines=1
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
# --- Main Tabs ---
|
| 45 |
with gr.Tabs():
|
| 46 |
|
| 47 |
-
# ---
|
| 48 |
with gr.TabItem("Home"):
|
| 49 |
gr.Markdown(
|
| 50 |
"<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
|
|
@@ -58,7 +40,6 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", theme=theme, cs
|
|
| 58 |
)
|
| 59 |
gr.Markdown("---")
|
| 60 |
|
| 61 |
-
# Accordion layout prevents a cluttered look
|
| 62 |
with gr.Accordion("🎯 Our Mission: The 'Why'", open=True):
|
| 63 |
gr.Markdown(
|
| 64 |
"""
|
|
@@ -87,8 +68,9 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", theme=theme, cs
|
|
| 87 |
"""
|
| 88 |
)
|
| 89 |
|
| 90 |
-
# --- Authentication Tab
|
| 91 |
with gr.TabItem("Login / Signup"):
|
|
|
|
| 92 |
auth_message = gr.Markdown()
|
| 93 |
with gr.Row():
|
| 94 |
with gr.Column(scale=1):
|
|
@@ -110,7 +92,7 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", theme=theme, cs
|
|
| 110 |
|
| 111 |
logout_btn = gr.Button("Logout")
|
| 112 |
|
| 113 |
-
# --- Prediction Tab
|
| 114 |
with gr.TabItem("Prediction"):
|
| 115 |
with gr.Row():
|
| 116 |
with gr.Column():
|
|
@@ -133,14 +115,8 @@ with gr.Blocks(title="DiaSpark: Your spark for early detection", theme=theme, cs
|
|
| 133 |
login_btn.click(fn=login, inputs=[email_login, pwd_login, user_state], outputs=[auth_message, user_state])
|
| 134 |
logout_btn.click(fn=logout, inputs=[user_state], outputs=[auth_message, user_state])
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
return gr.update(value=f"{user_data['email']}")
|
| 139 |
-
else:
|
| 140 |
-
return gr.update(value="Not logged in")
|
| 141 |
-
|
| 142 |
-
user_state.change(fn=update_login_display, inputs=user_state, outputs=login_status_display)
|
| 143 |
-
|
| 144 |
predict_btn.click(fn=predict, inputs=[preg, glucose, bp, insulin, bmi, age, user_state], outputs=[result_output])
|
| 145 |
|
| 146 |
# --- Launch the App ---
|
|
|
|
| 4 |
from components.auth import register, login, logout
|
| 5 |
from components.predict import predict
|
| 6 |
|
| 7 |
+
# --- 1. New Theme and Style ---
|
| 8 |
+
# By removing a specific theme and custom background, Gradio will automatically
|
| 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. This is now invisible to the user.
|
| 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 (Retaining the clean Accordion layout) ---
|
| 30 |
with gr.TabItem("Home"):
|
| 31 |
gr.Markdown(
|
| 32 |
"<h2 class='centered-text'>A Smart First Step in Understanding Your Health</h2>",
|
|
|
|
| 40 |
)
|
| 41 |
gr.Markdown("---")
|
| 42 |
|
|
|
|
| 43 |
with gr.Accordion("🎯 Our Mission: The 'Why'", open=True):
|
| 44 |
gr.Markdown(
|
| 45 |
"""
|
|
|
|
| 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 |
with gr.Row():
|
| 76 |
with gr.Column(scale=1):
|
|
|
|
| 92 |
|
| 93 |
logout_btn = gr.Button("Logout")
|
| 94 |
|
| 95 |
+
# --- Prediction Tab ---
|
| 96 |
with gr.TabItem("Prediction"):
|
| 97 |
with gr.Row():
|
| 98 |
with gr.Column():
|
|
|
|
| 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 ---
|