from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import RedirectResponse from api import api_router import gradio as gr import requests import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) logger.debug("Initializing application") app = FastAPI() # CORS app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) app.include_router(api_router) @app.get("/") def root(): logger.debug("Root endpoint accessed") return {"message": "🚀 FastAPI with MongoDB + JWT is running."} # Redirect /login to /auth/login @app.post("/login") async def redirect_login(request: Request): logger.info("Redirecting /login to /auth/login") return RedirectResponse(url="/auth/login", status_code=307) # 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, "password": password, "specialty": specialty, } try: res = requests.post(f"{BACKEND_URL}/auth/admin/doctors", json=payload) if res.status_code == 201: return "✅ Doctor created successfully!" return f"❌ {res.json().get('detail', 'Error occurred')}" except Exception as e: return f"❌ Network Error: {str(e)}" # Define Gradio interface as a separate function def setup_gradio(): logger.debug("Setting up Gradio interface") 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("