Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -50,6 +50,25 @@ def authenticate_admin(email: str = None, password: str = None):
|
|
| 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 {
|
|
@@ -69,7 +88,7 @@ admin_ui = gr.Blocks(css="""
|
|
| 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:
|
| 73 |
|
| 74 |
with gr.Column():
|
| 75 |
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
|
|
@@ -90,38 +109,21 @@ with admin_ui:
|
|
| 90 |
outputs=output
|
| 91 |
)
|
| 92 |
|
| 93 |
-
#
|
|
|
|
|
|
|
|
|
|
| 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"
|
| 108 |
-
|
| 109 |
-
def create_doctor(full_name, email, matricule, password, specialty):
|
| 110 |
-
payload = {
|
| 111 |
-
"full_name": full_name,
|
| 112 |
-
"email": email,
|
| 113 |
-
"license_number": matricule,
|
| 114 |
-
"password": password,
|
| 115 |
-
"specialty": specialty,
|
| 116 |
-
}
|
| 117 |
-
try:
|
| 118 |
-
res = requests.post(f"{BACKEND_URL}/auth/admin/doctors", json=payload)
|
| 119 |
-
if res.status_code == 201:
|
| 120 |
-
return "β
Doctor created successfully!"
|
| 121 |
-
return f"β {res.json().get('detail', 'Error occurred')}"
|
| 122 |
-
except Exception as e:
|
| 123 |
-
return f"β Network Error: {str(e)}"
|
| 124 |
-
|
| 125 |
if __name__ == "__main__":
|
| 126 |
logger.debug("Running main block")
|
| 127 |
import uvicorn
|
|
|
|
| 50 |
logger.info(f"Admin authenticated successfully: {email}")
|
| 51 |
return True
|
| 52 |
|
| 53 |
+
# Gradio doctor creation logic
|
| 54 |
+
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space"
|
| 55 |
+
|
| 56 |
+
def create_doctor(full_name, email, matricule, password, specialty):
|
| 57 |
+
payload = {
|
| 58 |
+
"full_name": full_name,
|
| 59 |
+
"email": email,
|
| 60 |
+
"license_number": matricule,
|
| 61 |
+
"password": password,
|
| 62 |
+
"specialty": specialty,
|
| 63 |
+
}
|
| 64 |
+
try:
|
| 65 |
+
res = requests.post(f"{BACKEND_URL}/auth/admin/doctors", json=payload)
|
| 66 |
+
if res.status_code == 201:
|
| 67 |
+
return "β
Doctor created successfully!"
|
| 68 |
+
return f"β {res.json().get('detail', 'Error occurred')}"
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return f"β Network Error: {str(e)}"
|
| 71 |
+
|
| 72 |
# Define Gradio interface
|
| 73 |
admin_ui = gr.Blocks(css="""
|
| 74 |
.gradio-container {
|
|
|
|
| 88 |
|
| 89 |
with admin_ui:
|
| 90 |
gr.Markdown("<div class='title-text'>π¨ββοΈ Doctor Account Creator</div>")
|
| 91 |
+
gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel. Generated at 10:03 PM CET on Sunday, May 25, 2025.</div>")
|
| 92 |
|
| 93 |
with gr.Column():
|
| 94 |
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
|
|
|
|
| 109 |
outputs=output
|
| 110 |
)
|
| 111 |
|
| 112 |
+
# Mount Gradio interface at startup (unprotected for now, authentication handled by route)
|
| 113 |
+
app = gr.mount_gradio_app(app, admin_ui, path="/admin-auth")
|
| 114 |
+
|
| 115 |
+
# Authentication route to redirect to /admin-auth with credentials
|
| 116 |
@app.get("/admin")
|
| 117 |
async def admin_dashboard(email: str = None, password: str = None, response: Response = None):
|
| 118 |
logger.debug("Admin dashboard accessed with email and password")
|
| 119 |
try:
|
| 120 |
authenticate_admin(email, password)
|
| 121 |
+
# Redirect to the mounted Gradio interface
|
| 122 |
+
return RedirectResponse(url="/admin-auth", status_code=307)
|
| 123 |
except HTTPException as e:
|
| 124 |
response.status_code = 401
|
| 125 |
return HTMLResponse(content="<h1>401 Unauthorized</h1><p>Invalid email or password. Please use: email=yakdhanali97@gmail.com&password=123456</p>")
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
if __name__ == "__main__":
|
| 128 |
logger.debug("Running main block")
|
| 129 |
import uvicorn
|