Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,84 +41,113 @@ def create_doctor(full_name, email, matricule, password, specialty):
|
|
| 41 |
# Modern admin UI
|
| 42 |
with gr.Blocks(css="""
|
| 43 |
.gradio-container {
|
| 44 |
-
background-color: #
|
|
|
|
| 45 |
font-family: 'Segoe UI', sans-serif;
|
| 46 |
-
padding:
|
| 47 |
}
|
| 48 |
|
| 49 |
-
.
|
| 50 |
text-align: center;
|
| 51 |
font-size: 2rem;
|
| 52 |
font-weight: 800;
|
| 53 |
-
color: #
|
| 54 |
-
margin-bottom: 0.
|
| 55 |
}
|
| 56 |
|
| 57 |
-
.
|
| 58 |
text-align: center;
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
}
|
| 63 |
|
| 64 |
-
.gr-box, .gr-form, .gr-column, .gr-
|
| 65 |
-
background-color: #
|
| 66 |
-
padding: 2rem !important;
|
| 67 |
border-radius: 16px !important;
|
| 68 |
-
|
| 69 |
max-width: 700px;
|
| 70 |
margin: auto;
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
label {
|
| 74 |
font-weight: 600;
|
| 75 |
-
color: #
|
| 76 |
-
margin-bottom: 0.
|
| 77 |
}
|
| 78 |
|
| 79 |
input, select, textarea {
|
|
|
|
|
|
|
|
|
|
| 80 |
font-size: 0.95rem;
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
border: 1px solid #ccc;
|
| 84 |
}
|
| 85 |
|
| 86 |
button {
|
|
|
|
|
|
|
|
|
|
| 87 |
font-weight: bold;
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
border-radius: 30px !important;
|
| 91 |
}
|
| 92 |
-
""") as admin_ui:
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
with gr.Column(
|
| 101 |
-
full_name = gr.Textbox(label="Full Name", placeholder="Dr. Sarah Hopkins")
|
| 102 |
-
email = gr.Textbox(label="Email", placeholder="doctor@clinic.org")
|
| 103 |
-
matricule = gr.Textbox(label="Matricule", placeholder="DOC-
|
| 104 |
specialty = gr.Dropdown(
|
| 105 |
label="Specialty",
|
| 106 |
choices=[
|
| 107 |
-
"Cardiology", "
|
| 108 |
-
"
|
| 109 |
],
|
| 110 |
-
value="Cardiology"
|
| 111 |
)
|
| 112 |
password = gr.Textbox(label="Password", type="password", placeholder="Secure password")
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
submit_btn.click(
|
| 118 |
fn=create_doctor,
|
| 119 |
-
inputs=[full_name, email, matricule,
|
| 120 |
-
outputs=output
|
| 121 |
)
|
| 122 |
|
|
|
|
|
|
|
|
|
|
| 123 |
# Mount Gradio at /admin
|
| 124 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|
|
|
|
| 41 |
# Modern admin UI
|
| 42 |
with gr.Blocks(css="""
|
| 43 |
.gradio-container {
|
| 44 |
+
background-color: #0f172a; /* dark slate */
|
| 45 |
+
color: #e2e8f0;
|
| 46 |
font-family: 'Segoe UI', sans-serif;
|
| 47 |
+
padding: 3rem;
|
| 48 |
}
|
| 49 |
|
| 50 |
+
.title-text {
|
| 51 |
text-align: center;
|
| 52 |
font-size: 2rem;
|
| 53 |
font-weight: 800;
|
| 54 |
+
color: #38bdf8;
|
| 55 |
+
margin-bottom: 0.4rem;
|
| 56 |
}
|
| 57 |
|
| 58 |
+
.description-text {
|
| 59 |
text-align: center;
|
| 60 |
+
font-size: 1rem;
|
| 61 |
+
color: #94a3b8;
|
| 62 |
+
margin-bottom: 2rem;
|
| 63 |
}
|
| 64 |
|
| 65 |
+
.gr-box, .gr-form, .gr-column, .gr-panel, .gr-group {
|
| 66 |
+
background-color: #1e293b !important;
|
|
|
|
| 67 |
border-radius: 16px !important;
|
| 68 |
+
padding: 2rem !important;
|
| 69 |
max-width: 700px;
|
| 70 |
margin: auto;
|
| 71 |
+
box-shadow: 0 0 0 1px #334155;
|
| 72 |
}
|
| 73 |
|
| 74 |
label {
|
| 75 |
font-weight: 600;
|
| 76 |
+
color: #e2e8f0;
|
| 77 |
+
margin-bottom: 0.25rem;
|
| 78 |
}
|
| 79 |
|
| 80 |
input, select, textarea {
|
| 81 |
+
background-color: #0f172a !important;
|
| 82 |
+
color: #f8fafc !important;
|
| 83 |
+
border: 1px solid #334155 !important;
|
| 84 |
font-size: 0.95rem;
|
| 85 |
+
padding: 10px;
|
| 86 |
+
border-radius: 8px;
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
button {
|
| 90 |
+
background-color: #38bdf8 !important;
|
| 91 |
+
color: #0f172a !important;
|
| 92 |
+
border-radius: 25px !important;
|
| 93 |
font-weight: bold;
|
| 94 |
+
padding: 12px 24px;
|
| 95 |
+
margin-top: 1.5rem;
|
|
|
|
| 96 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
.output-box textarea {
|
| 99 |
+
background-color: #0f172a !important;
|
| 100 |
+
color: #38bdf8 !important;
|
| 101 |
+
border: none;
|
| 102 |
+
font-size: 0.9rem;
|
| 103 |
+
margin-top: 1rem;
|
| 104 |
+
}
|
| 105 |
+
""") as admin_ui:
|
| 106 |
+
gr.Markdown("<div class='title-text'>π¨ββοΈ Doctor Account Creator</div>")
|
| 107 |
+
gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel.</div>")
|
| 108 |
|
| 109 |
+
with gr.Column():
|
| 110 |
+
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
|
| 111 |
+
email = gr.Textbox(label="Email", placeholder="e.g. doctor@clinic.org")
|
| 112 |
+
matricule = gr.Textbox(label="Matricule", placeholder="e.g. DOC-1234")
|
| 113 |
specialty = gr.Dropdown(
|
| 114 |
label="Specialty",
|
| 115 |
choices=[
|
| 116 |
+
"Cardiology", "Neurology", "Pediatrics", "Oncology",
|
| 117 |
+
"General Practice", "Psychiatry", "Dermatology", "Orthopedics"
|
| 118 |
],
|
| 119 |
+
value="Cardiology"
|
| 120 |
)
|
| 121 |
password = gr.Textbox(label="Password", type="password", placeholder="Secure password")
|
| 122 |
+
submit_btn = gr.Button("β
Create Doctor Account")
|
| 123 |
+
output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"])
|
| 124 |
+
|
| 125 |
+
def create_doctor(full_name, email, matricule, specialty, password):
|
| 126 |
+
import requests
|
| 127 |
+
payload = {
|
| 128 |
+
"full_name": full_name,
|
| 129 |
+
"email": email,
|
| 130 |
+
"matricule": matricule,
|
| 131 |
+
"specialty": specialty,
|
| 132 |
+
"password": password
|
| 133 |
+
}
|
| 134 |
+
try:
|
| 135 |
+
res = requests.post("https://rocketfarmstudios-cps-api.hf.space/admin/create-doctor", json=payload)
|
| 136 |
+
if res.status_code == 200:
|
| 137 |
+
return "β
Doctor account successfully created!"
|
| 138 |
+
else:
|
| 139 |
+
return f"β {res.json().get('detail', 'Something went wrong')}"
|
| 140 |
+
except Exception as e:
|
| 141 |
+
return f"β Connection error: {str(e)}"
|
| 142 |
|
| 143 |
submit_btn.click(
|
| 144 |
fn=create_doctor,
|
| 145 |
+
inputs=[full_name, email, matricule, specialty, password],
|
| 146 |
+
outputs=output
|
| 147 |
)
|
| 148 |
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
|
| 152 |
# Mount Gradio at /admin
|
| 153 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|