Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,27 +6,22 @@ import requests
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
#
|
| 10 |
app.add_middleware(
|
| 11 |
CORSMiddleware,
|
| 12 |
-
allow_origins=["*"],
|
| 13 |
-
|
| 14 |
-
allow_methods=["*"],
|
| 15 |
-
allow_headers=["*"],
|
| 16 |
)
|
| 17 |
|
| 18 |
-
# --- Include your API routes ---
|
| 19 |
app.include_router(api_router)
|
| 20 |
|
| 21 |
-
# --- Root endpoint ---
|
| 22 |
@app.get("/")
|
| 23 |
def root():
|
| 24 |
-
return {"message": "π FastAPI
|
| 25 |
|
| 26 |
-
#
|
| 27 |
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space"
|
| 28 |
|
| 29 |
-
# --- Gradio logic to create doctor ---
|
| 30 |
def create_doctor(full_name, email, matricule, password, specialty):
|
| 31 |
payload = {
|
| 32 |
"full_name": full_name,
|
|
@@ -38,59 +33,80 @@ def create_doctor(full_name, email, matricule, password, specialty):
|
|
| 38 |
try:
|
| 39 |
res = requests.post(f"{BACKEND_URL}/admin/create-doctor", json=payload)
|
| 40 |
if res.status_code == 200:
|
| 41 |
-
return "β
Doctor
|
| 42 |
-
|
| 43 |
-
return f"β {res.json().get('detail', 'Something went wrong')}"
|
| 44 |
except Exception as e:
|
| 45 |
-
return f"β
|
| 46 |
|
| 47 |
-
#
|
| 48 |
with gr.Blocks(css="""
|
| 49 |
.gradio-container {
|
| 50 |
-
background-color: #
|
| 51 |
-
font-family: '
|
| 52 |
-
padding:
|
| 53 |
-
max-width: 640px;
|
| 54 |
-
margin: auto;
|
| 55 |
}
|
| 56 |
-
.
|
| 57 |
text-align: center;
|
| 58 |
font-size: 2rem;
|
| 59 |
font-weight: 800;
|
| 60 |
color: #002538;
|
| 61 |
margin-bottom: 0.5rem;
|
| 62 |
}
|
| 63 |
-
.
|
| 64 |
text-align: center;
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
""") as admin_ui:
|
| 73 |
-
gr.Markdown("<div class='title-text'>π©Ί Doctor Account Registration</div>")
|
| 74 |
-
gr.Markdown("<div class='description-text'>Admin-only panel to create and assign new doctor accounts securely.</div>")
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
specialty = gr.Dropdown(
|
| 81 |
-
label="
|
| 82 |
choices=[
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"Psychiatrist", "Radiologist", "Surgeon", "Urologist"
|
| 86 |
],
|
| 87 |
-
value="
|
| 88 |
)
|
| 89 |
-
password = gr.Textbox(label="
|
| 90 |
-
submit_btn = gr.Button("β Create Doctor Account", size="lg", variant="primary")
|
| 91 |
-
output = gr.Textbox(label="", show_label=False)
|
| 92 |
|
| 93 |
-
submit_btn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
#
|
| 96 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# CORS
|
| 10 |
app.add_middleware(
|
| 11 |
CORSMiddleware,
|
| 12 |
+
allow_origins=["*"], allow_credentials=True,
|
| 13 |
+
allow_methods=["*"], allow_headers=["*"],
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
|
|
|
|
| 16 |
app.include_router(api_router)
|
| 17 |
|
|
|
|
| 18 |
@app.get("/")
|
| 19 |
def root():
|
| 20 |
+
return {"message": "π FastAPI with MongoDB + JWT is running."}
|
| 21 |
|
| 22 |
+
# Gradio doctor creation logic
|
| 23 |
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space"
|
| 24 |
|
|
|
|
| 25 |
def create_doctor(full_name, email, matricule, password, specialty):
|
| 26 |
payload = {
|
| 27 |
"full_name": full_name,
|
|
|
|
| 33 |
try:
|
| 34 |
res = requests.post(f"{BACKEND_URL}/admin/create-doctor", json=payload)
|
| 35 |
if res.status_code == 200:
|
| 36 |
+
return "β
Doctor created successfully!"
|
| 37 |
+
return f"β {res.json().get('detail', 'Error occurred')}"
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
+
return f"β Network Error: {str(e)}"
|
| 40 |
|
| 41 |
+
# Modern admin UI
|
| 42 |
with gr.Blocks(css="""
|
| 43 |
.gradio-container {
|
| 44 |
+
background-color: #f0f4f8;
|
| 45 |
+
font-family: 'Segoe UI', sans-serif;
|
| 46 |
+
padding: 2rem;
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
+
.header {
|
| 49 |
text-align: center;
|
| 50 |
font-size: 2rem;
|
| 51 |
font-weight: 800;
|
| 52 |
color: #002538;
|
| 53 |
margin-bottom: 0.5rem;
|
| 54 |
}
|
| 55 |
+
.subheader {
|
| 56 |
text-align: center;
|
| 57 |
+
color: #5c6670;
|
| 58 |
+
margin-bottom: 2.2rem;
|
| 59 |
+
font-size: 0.95rem;
|
| 60 |
+
}
|
| 61 |
+
.form-box {
|
| 62 |
+
background: white;
|
| 63 |
+
max-width: 600px;
|
| 64 |
+
margin: auto;
|
| 65 |
+
padding: 2rem;
|
| 66 |
+
border-radius: 12px;
|
| 67 |
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
|
| 68 |
+
}
|
| 69 |
+
label {
|
| 70 |
+
font-weight: 600;
|
| 71 |
+
color: #333;
|
| 72 |
+
margin-bottom: 0.2rem;
|
| 73 |
}
|
| 74 |
+
input, select, textarea {
|
| 75 |
+
font-size: 0.95rem;
|
| 76 |
+
}
|
| 77 |
+
button {
|
| 78 |
+
font-weight: bold;
|
| 79 |
+
background-color: #002538 !important;
|
| 80 |
+
color: white !important;
|
| 81 |
+
border-radius: 30px !important;
|
| 82 |
}
|
| 83 |
""") as admin_ui:
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
gr.Markdown("<div class='header'>π§ββοΈ Doctor Account Creator</div>")
|
| 86 |
+
gr.Markdown("<div class='subheader'>Admins can register new doctors using this secure panel.</div>")
|
| 87 |
+
|
| 88 |
+
with gr.Column(elem_classes=["form-box"]):
|
| 89 |
+
full_name = gr.Textbox(label="Full Name", placeholder="Dr. Sarah Hopkins")
|
| 90 |
+
email = gr.Textbox(label="Email", placeholder="doctor@clinic.org")
|
| 91 |
+
matricule = gr.Textbox(label="Matricule", placeholder="DOC-8932")
|
| 92 |
specialty = gr.Dropdown(
|
| 93 |
+
label="Specialty",
|
| 94 |
choices=[
|
| 95 |
+
"Cardiology", "Dermatology", "Endocrinology", "Neurology", "Psychiatry",
|
| 96 |
+
"Surgery", "Oncology", "Orthopedics", "Pediatrics", "Radiology", "Urology"
|
|
|
|
| 97 |
],
|
| 98 |
+
value="Cardiology",
|
| 99 |
)
|
| 100 |
+
password = gr.Textbox(label="Password", type="password", placeholder="Secure password")
|
|
|
|
|
|
|
| 101 |
|
| 102 |
+
submit_btn = gr.Button("Create Doctor Account", size="lg")
|
| 103 |
+
output = gr.Textbox(show_label=False)
|
| 104 |
+
|
| 105 |
+
submit_btn.click(
|
| 106 |
+
fn=create_doctor,
|
| 107 |
+
inputs=[full_name, email, matricule, password, specialty],
|
| 108 |
+
outputs=output,
|
| 109 |
+
)
|
| 110 |
|
| 111 |
+
# Mount Gradio at /admin
|
| 112 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|