Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import FastAPI, Request, HTTPException
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.responses import RedirectResponse, HTMLResponse
|
| 4 |
from api import api_router
|
|
@@ -50,56 +50,58 @@ def authenticate_admin(email: str = None, password: str = None):
|
|
| 50 |
logger.info(f"Admin authenticated successfully: {email}")
|
| 51 |
return True
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
# Serve Gradio interface for /admin with authentication
|
| 54 |
@app.get("/admin")
|
| 55 |
-
async def admin_dashboard(email: str = None, password: str = None):
|
| 56 |
logger.debug("Admin dashboard accessed with email and password")
|
| 57 |
try:
|
| 58 |
authenticate_admin(email, password)
|
| 59 |
except HTTPException as e:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
background-color: #1A1B1F;
|
| 66 |
-
color: #E2E8F0;
|
| 67 |
-
font-family: 'Segoe UI', sans-serif;
|
| 68 |
-
padding: 3rem;
|
| 69 |
-
}
|
| 70 |
-
.title-text { text-align: center; font-size: 2rem; font-weight: 700; color: #37B6E9; margin-bottom: 0.5rem; }
|
| 71 |
-
.description-text { text-align: center; font-size: 1rem; color: #A0AEC0; margin-bottom: 2rem; }
|
| 72 |
-
.gr-box, .gr-form, .gr-column, .gr-panel { background-color: #2D2F36 !important; border-radius: 16px !important; padding: 2rem !important; max-width: 600px; margin: auto; box-shadow: 0 0 0 1px #3B3E47; }
|
| 73 |
-
label { font-weight: 600; color: #F7FAFC; margin-bottom: 6px; }
|
| 74 |
-
input, select, textarea { background-color: #1A1B1F !important; color: #F7FAFC !important; border: 1px solid #4A5568 !important; font-size: 14px; padding: 10px; border-radius: 10px; }
|
| 75 |
-
button { background-color: #37B6E9 !important; color: #1A1B1F !important; border-radius: 10px !important; font-weight: 600; padding: 12px; width: 100%; margin-top: 1.5rem; }
|
| 76 |
-
.output-box textarea { background-color: transparent !important; border: none; color: #90CDF4; font-size: 14px; margin-top: 1rem; }
|
| 77 |
-
""")
|
| 78 |
-
|
| 79 |
-
with admin_ui:
|
| 80 |
-
gr.Markdown("<div class='title-text'>👨⚕️ Doctor Account Creator</div>")
|
| 81 |
-
gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel. Generated at 09:49 PM CET on Sunday, May 25, 2025.</div>")
|
| 82 |
-
|
| 83 |
-
with gr.Column():
|
| 84 |
-
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
|
| 85 |
-
email = gr.Textbox(label="Email", placeholder="e.g. doctor@clinic.org")
|
| 86 |
-
matricule = gr.Textbox(label="Matricule", placeholder="e.g. DOC-1234")
|
| 87 |
-
specialty = gr.Dropdown(
|
| 88 |
-
label="Specialty",
|
| 89 |
-
choices=["Cardiology", "Neurology", "Pediatrics", "Oncology", "General Practice", "Psychiatry", "Dermatology", "Orthopedics"],
|
| 90 |
-
value="Cardiology"
|
| 91 |
-
)
|
| 92 |
-
password = gr.Textbox(label="Password", type="password", placeholder="Secure password")
|
| 93 |
-
submit_btn = gr.Button("Create Doctor Account")
|
| 94 |
-
output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"])
|
| 95 |
-
|
| 96 |
-
submit_btn.click(
|
| 97 |
-
fn=create_doctor,
|
| 98 |
-
inputs=[full_name, email, matricule, specialty, password],
|
| 99 |
-
outputs=output
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
-
return admin_ui.launch(share=False, inline=True)
|
| 103 |
|
| 104 |
# Gradio doctor creation logic
|
| 105 |
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space"
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request, HTTPException, Response
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.responses import RedirectResponse, HTMLResponse
|
| 4 |
from api import api_router
|
|
|
|
| 50 |
logger.info(f"Admin authenticated successfully: {email}")
|
| 51 |
return True
|
| 52 |
|
| 53 |
+
# Define Gradio interface
|
| 54 |
+
admin_ui = gr.Blocks(css="""
|
| 55 |
+
.gradio-container {
|
| 56 |
+
background-color: #1A1B1F;
|
| 57 |
+
color: #E2E8F0;
|
| 58 |
+
font-family: 'Segoe UI', sans-serif;
|
| 59 |
+
padding: 3rem;
|
| 60 |
+
}
|
| 61 |
+
.title-text { text-align: center; font-size: 2rem; font-weight: 700; color: #37B6E9; margin-bottom: 0.5rem; }
|
| 62 |
+
.description-text { text-align: center; font-size: 1rem; color: #A0AEC0; margin-bottom: 2rem; }
|
| 63 |
+
.gr-box, .gr-form, .gr-column, .gr-panel { background-color: #2D2F36 !important; border-radius: 16px !important; padding: 2rem !important; max-width: 600px; margin: auto; box-shadow: 0 0 0 1px #3B3E47; }
|
| 64 |
+
label { font-weight: 600; color: #F7FAFC; margin-bottom: 6px; }
|
| 65 |
+
input, select, textarea { background-color: #1A1B1F !important; color: #F7FAFC !important; border: 1px solid #4A5568 !important; font-size: 14px; padding: 10px; border-radius: 10px; }
|
| 66 |
+
button { background-color: #37B6E9 !important; color: #1A1B1F !important; border-radius: 10px !important; font-weight: 600; padding: 12px; width: 100%; margin-top: 1.5rem; }
|
| 67 |
+
.output-box textarea { background-color: transparent !important; border: none; color: #90CDF4; font-size: 14px; margin-top: 1rem; }
|
| 68 |
+
""")
|
| 69 |
+
|
| 70 |
+
with admin_ui:
|
| 71 |
+
gr.Markdown("<div class='title-text'>👨⚕️ Doctor Account Creator</div>")
|
| 72 |
+
gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel. Generated at 10:01 PM CET on Sunday, May 25, 2025.</div>")
|
| 73 |
+
|
| 74 |
+
with gr.Column():
|
| 75 |
+
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
|
| 76 |
+
email = gr.Textbox(label="Email", placeholder="e.g. doctor@clinic.org")
|
| 77 |
+
matricule = gr.Textbox(label="Matricule", placeholder="e.g. DOC-1234")
|
| 78 |
+
specialty = gr.Dropdown(
|
| 79 |
+
label="Specialty",
|
| 80 |
+
choices=["Cardiology", "Neurology", "Pediatrics", "Oncology", "General Practice", "Psychiatry", "Dermatology", "Orthopedics"],
|
| 81 |
+
value="Cardiology"
|
| 82 |
+
)
|
| 83 |
+
password = gr.Textbox(label="Password", type="password", placeholder="Secure password")
|
| 84 |
+
submit_btn = gr.Button("Create Doctor Account")
|
| 85 |
+
output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"])
|
| 86 |
+
|
| 87 |
+
submit_btn.click(
|
| 88 |
+
fn=create_doctor,
|
| 89 |
+
inputs=[full_name, email, matricule, specialty, password],
|
| 90 |
+
outputs=output
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
# Serve Gradio interface for /admin with authentication
|
| 94 |
@app.get("/admin")
|
| 95 |
+
async def admin_dashboard(email: str = None, password: str = None, response: Response = None):
|
| 96 |
logger.debug("Admin dashboard accessed with email and password")
|
| 97 |
try:
|
| 98 |
authenticate_admin(email, password)
|
| 99 |
except HTTPException as e:
|
| 100 |
+
response.status_code = 401
|
| 101 |
+
return HTMLResponse(content="<h1>401 Unauthorized</h1><p>Invalid email or password. Please use: email=yakdhanali97@gmail.com&password=123456</p>")
|
| 102 |
+
|
| 103 |
+
# Mount and serve the Gradio interface
|
| 104 |
+
return gr.mount_gradio_app(app, admin_ui, path="/admin").app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Gradio doctor creation logic
|
| 107 |
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space"
|