Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from api import api_router | |
| import gradio as gr | |
| import requests | |
| app = FastAPI() | |
| # CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(api_router) | |
| def root(): | |
| return {"message": "π FastAPI with MongoDB + JWT is running."} | |
| # Gradio doctor creation logic | |
| BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space" | |
| def create_doctor(full_name, email, matricule, password, specialty): | |
| payload = { | |
| "full_name": full_name, | |
| "email": email, | |
| "license_number": matricule, # Map 'matricule' to 'license_number' as expected by the backend | |
| "password": password, | |
| "specialty": specialty, | |
| } | |
| try: | |
| res = requests.post(f"{BACKEND_URL}/auth/admin/doctors", json=payload) | |
| if res.status_code == 201: # Status code for successful creation | |
| return "β Doctor created successfully!" | |
| return f"β {res.json().get('detail', 'Error occurred')}" | |
| except Exception as e: | |
| return f"β Network Error: {str(e)}" | |
| # Modern admin UI | |
| with gr.Blocks(css=""" | |
| .gradio-container { | |
| background-color: #1A1B1F; | |
| color: #E2E8F0; | |
| font-family: 'Segoe UI', sans-serif; | |
| padding: 3rem; | |
| } | |
| .title-text { | |
| text-align: center; | |
| font-size: 2rem; | |
| font-weight: 700; | |
| color: #37B6E9; | |
| margin-bottom: 0.5rem; | |
| } | |
| .description-text { | |
| text-align: center; | |
| font-size: 1rem; | |
| color: #A0AEC0; | |
| margin-bottom: 2rem; | |
| } | |
| .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; | |
| } | |
| label { | |
| font-weight: 600; | |
| color: #F7FAFC; | |
| margin-bottom: 6px; | |
| } | |
| input, select, textarea { | |
| background-color: #1A1B1F !important; | |
| color: #F7FAFC !important; | |
| border: 1px solid #4A5568 !important; | |
| font-size: 14px; | |
| padding: 10px; | |
| border-radius: 10px; | |
| } | |
| button { | |
| background-color: #37B6E9 !important; | |
| color: #1A1B1F !important; | |
| border-radius: 10px !important; | |
| font-weight: 600; | |
| padding: 12px; | |
| width: 100%; | |
| margin-top: 1.5rem; | |
| } | |
| .output-box textarea { | |
| background-color: transparent !important; | |
| border: none; | |
| color: #90CDF4; | |
| font-size: 14px; | |
| margin-top: 1rem; | |
| } | |
| """) as admin_ui: | |
| gr.Markdown("<div class='title-text'>π¨ββοΈ Doctor Account Creator</div>") | |
| gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel. Generated at 06:07 PM CET on Friday, May 16, 2025.</div>") | |
| with gr.Column(): | |
| full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins") | |
| email = gr.Textbox(label="Email", placeholder="e.g. doctor@clinic.org") | |
| matricule = gr.Textbox(label="Matricule", placeholder="e.g. DOC-1234") | |
| specialty = gr.Dropdown( | |
| label="Specialty", | |
| choices=[ | |
| "Cardiology", "Neurology", "Pediatrics", "Oncology", | |
| "General Practice", "Psychiatry", "Dermatology", "Orthopedics" | |
| ], | |
| value="Cardiology" | |
| ) | |
| password = gr.Textbox(label="Password", type="password", placeholder="Secure password") | |
| submit_btn = gr.Button("Create Doctor Account") | |
| output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"]) | |
| submit_btn.click( | |
| fn=create_doctor, | |
| inputs=[full_name, email, matricule, specialty, password], | |
| outputs=output | |
| ) | |
| # Mount Gradio at /admin | |
| app = gr.mount_gradio_app(app, admin_ui, path="/admin") |