Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,62 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from api.routes import router as api_router
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
| 7 |
app.add_middleware(
|
| 8 |
CORSMiddleware,
|
| 9 |
-
allow_origins=["*"],
|
| 10 |
allow_credentials=True,
|
| 11 |
allow_methods=["*"],
|
| 12 |
allow_headers=["*"],
|
| 13 |
)
|
| 14 |
|
|
|
|
| 15 |
app.include_router(api_router)
|
| 16 |
|
|
|
|
| 17 |
@app.get("/")
|
| 18 |
def root():
|
| 19 |
-
return {"message": "π FastAPI MongoDB
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from api.routes import router as api_router
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import requests
|
| 6 |
|
| 7 |
+
# Your FastAPI app
|
| 8 |
app = FastAPI()
|
| 9 |
|
| 10 |
+
# CORS middleware
|
| 11 |
app.add_middleware(
|
| 12 |
CORSMiddleware,
|
| 13 |
+
allow_origins=["*"], # Change to your frontend domain in prod
|
| 14 |
allow_credentials=True,
|
| 15 |
allow_methods=["*"],
|
| 16 |
allow_headers=["*"],
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# Include API router
|
| 20 |
app.include_router(api_router)
|
| 21 |
|
| 22 |
+
# Root endpoint
|
| 23 |
@app.get("/")
|
| 24 |
def root():
|
| 25 |
+
return {"message": "π FastAPI with MongoDB + JWT is running"}
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# --- Gradio Interface Logic ---
|
| 29 |
+
|
| 30 |
+
BACKEND_URL = "https://rocketfarmstudios-cps-api.hf.space" # π change to your Space URL if deployed
|
| 31 |
+
|
| 32 |
+
def create_doctor_api(full_name, email, matricule, password):
|
| 33 |
+
try:
|
| 34 |
+
payload = {
|
| 35 |
+
"full_name": full_name,
|
| 36 |
+
"email": email,
|
| 37 |
+
"matricule": matricule,
|
| 38 |
+
"password": password,
|
| 39 |
+
}
|
| 40 |
+
response = requests.post(f"{BACKEND_URL}/admin/create-doctor", json=payload)
|
| 41 |
+
if response.status_code == 200:
|
| 42 |
+
return "β
Doctor created successfully!"
|
| 43 |
+
else:
|
| 44 |
+
return f"β Error: {response.json().get('detail', 'Unknown error')}"
|
| 45 |
+
except Exception as e:
|
| 46 |
+
return f"β Failed to connect: {str(e)}"
|
| 47 |
+
|
| 48 |
+
gradio_ui = gr.Interface(
|
| 49 |
+
fn=create_doctor_api,
|
| 50 |
+
inputs=[
|
| 51 |
+
gr.Textbox(label="Full Name"),
|
| 52 |
+
gr.Textbox(label="Email"),
|
| 53 |
+
gr.Textbox(label="Matricule"),
|
| 54 |
+
gr.Textbox(label="Password", type="password")
|
| 55 |
+
],
|
| 56 |
+
outputs=gr.Textbox(label="Status"),
|
| 57 |
+
title="π¨ββοΈ Admin - Create Doctor Account",
|
| 58 |
+
description="Fill in the fields to register a doctor.",
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Mount Gradio inside FastAPI app
|
| 62 |
+
app = gr.mount_gradio_app(app, gradio_ui, path="/admin")
|