Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,31 +6,34 @@ import requests
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
# --- CORS ---
|
| 10 |
app.add_middleware(
|
| 11 |
CORSMiddleware,
|
| 12 |
-
allow_origins=["*"], # Adjust
|
| 13 |
allow_credentials=True,
|
| 14 |
allow_methods=["*"],
|
| 15 |
allow_headers=["*"],
|
| 16 |
)
|
| 17 |
|
|
|
|
| 18 |
app.include_router(api_router)
|
| 19 |
|
|
|
|
| 20 |
@app.get("/")
|
| 21 |
def root():
|
| 22 |
return {"message": "π FastAPI + MongoDB + JWT is running"}
|
| 23 |
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
# --- Gradio
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
def create_doctor(full_name, email, matricule, password):
|
| 29 |
payload = {
|
| 30 |
"full_name": full_name,
|
| 31 |
"email": email,
|
| 32 |
"matricule": matricule,
|
| 33 |
"password": password,
|
|
|
|
| 34 |
}
|
| 35 |
try:
|
| 36 |
res = requests.post(f"{BACKEND_URL}/admin/create-doctor", json=payload)
|
|
@@ -41,45 +44,53 @@ def create_doctor(full_name, email, matricule, password):
|
|
| 41 |
except Exception as e:
|
| 42 |
return f"β Connection error: {str(e)}"
|
| 43 |
|
| 44 |
-
|
| 45 |
-
# --- Gradio Interface ---
|
| 46 |
with gr.Blocks(css="""
|
| 47 |
.gradio-container {
|
| 48 |
background-color: #f9fbfd;
|
| 49 |
font-family: 'Inter', sans-serif;
|
| 50 |
-
padding:
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
.title-text {
|
| 53 |
text-align: center;
|
| 54 |
font-size: 2rem;
|
| 55 |
-
font-weight:
|
| 56 |
color: #002538;
|
| 57 |
-
margin-bottom:
|
| 58 |
}
|
| 59 |
.description-text {
|
| 60 |
text-align: center;
|
| 61 |
font-size: 1rem;
|
| 62 |
-
color: #
|
| 63 |
-
margin-bottom:
|
| 64 |
}
|
| 65 |
-
.gr-
|
| 66 |
-
|
| 67 |
-
margin: 0 auto;
|
| 68 |
}
|
| 69 |
""") as admin_ui:
|
| 70 |
-
gr.Markdown("<div class='title-text'
|
| 71 |
-
gr.Markdown("<div class='description-text'>Admin-only panel to
|
| 72 |
-
|
| 73 |
-
with gr.Column(elem_classes=["gr-input"]):
|
| 74 |
-
full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Alice Johnson")
|
| 75 |
-
email = gr.Textbox(label="Email", placeholder="e.g. alice@example.com")
|
| 76 |
-
matricule = gr.Textbox(label="Matricule", placeholder="e.g. DOC-7891")
|
| 77 |
-
password = gr.Textbox(label="Password", type="password", placeholder="Enter a secure password")
|
| 78 |
-
submit_btn = gr.Button("β
Create Doctor Account", size="lg")
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
output = gr.Textbox(label="", show_label=False)
|
| 81 |
|
| 82 |
-
submit_btn.click(fn=create_doctor, inputs=[full_name, email, matricule, password], outputs=output)
|
| 83 |
|
| 84 |
-
# Mount Gradio at /admin
|
| 85 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
+
# --- CORS Middleware ---
|
| 10 |
app.add_middleware(
|
| 11 |
CORSMiddleware,
|
| 12 |
+
allow_origins=["*"], # Adjust in production
|
| 13 |
allow_credentials=True,
|
| 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 + MongoDB + JWT is running"}
|
| 25 |
|
| 26 |
+
# --- Backend API URL ---
|
| 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,
|
| 33 |
"email": email,
|
| 34 |
"matricule": matricule,
|
| 35 |
"password": password,
|
| 36 |
+
"specialty": specialty,
|
| 37 |
}
|
| 38 |
try:
|
| 39 |
res = requests.post(f"{BACKEND_URL}/admin/create-doctor", json=payload)
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"β Connection error: {str(e)}"
|
| 46 |
|
| 47 |
+
# --- Gradio Admin Dashboard ---
|
|
|
|
| 48 |
with gr.Blocks(css="""
|
| 49 |
.gradio-container {
|
| 50 |
background-color: #f9fbfd;
|
| 51 |
font-family: 'Inter', sans-serif;
|
| 52 |
+
padding: 2.5rem;
|
| 53 |
+
max-width: 640px;
|
| 54 |
+
margin: auto;
|
| 55 |
}
|
| 56 |
.title-text {
|
| 57 |
text-align: center;
|
| 58 |
font-size: 2rem;
|
| 59 |
+
font-weight: 800;
|
| 60 |
color: #002538;
|
| 61 |
+
margin-bottom: 0.5rem;
|
| 62 |
}
|
| 63 |
.description-text {
|
| 64 |
text-align: center;
|
| 65 |
font-size: 1rem;
|
| 66 |
+
color: #444;
|
| 67 |
+
margin-bottom: 2rem;
|
| 68 |
}
|
| 69 |
+
.gr-form {
|
| 70 |
+
gap: 1.2rem;
|
|
|
|
| 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 |
+
with gr.Column(elem_classes=["gr-form"]):
|
| 77 |
+
full_name = gr.Textbox(label="π€ Full Name", placeholder="Dr. Alice Johnson")
|
| 78 |
+
email = gr.Textbox(label="π§ Email", placeholder="alice@clinic.com")
|
| 79 |
+
matricule = gr.Textbox(label="π Matricule", placeholder="DOC-1021")
|
| 80 |
+
specialty = gr.Dropdown(
|
| 81 |
+
label="π₯ Specialty",
|
| 82 |
+
choices=[
|
| 83 |
+
"Cardiologist", "Dermatologist", "Endocrinologist", "Gastroenterologist",
|
| 84 |
+
"Neurologist", "Oncologist", "Orthopedist", "Pediatrician",
|
| 85 |
+
"Psychiatrist", "Radiologist", "Surgeon", "Urologist"
|
| 86 |
+
],
|
| 87 |
+
value="Cardiologist"
|
| 88 |
+
)
|
| 89 |
+
password = gr.Textbox(label="π Password", type="password", placeholder="Strong password")
|
| 90 |
+
submit_btn = gr.Button("β Create Doctor Account", size="lg", variant="primary")
|
| 91 |
output = gr.Textbox(label="", show_label=False)
|
| 92 |
|
| 93 |
+
submit_btn.click(fn=create_doctor, inputs=[full_name, email, matricule, password, specialty], outputs=output)
|
| 94 |
|
| 95 |
+
# --- Mount Gradio at /admin ---
|
| 96 |
app = gr.mount_gradio_app(app, admin_ui, path="/admin")
|