File size: 4,509 Bytes
119a07a
b29925a
119a07a
d02bad2
6c71d89
 
3456970
 
 
 
 
b29925a
 
 
ce9fa5a
b29925a
 
9e1f79a
 
 
 
b29925a
 
 
 
 
 
3456970
ce9fa5a
6c71d89
119a07a
 
 
 
 
 
ce9fa5a
0f3fd66
6c71d89
0f3fd66
38b6139
 
 
3456970
38b6139
0f3fd66
38b6139
6c71d89
9e1f79a
3456970
ce9fa5a
 
6c71d89
ce9fa5a
38b6139
3456970
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119a07a
3456970
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119a07a
3456970
 
 
 
 
 
119a07a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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("<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 03:43 PM CET on Saturday, May 17, 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
            )
    return admin_ui

# Mount Gradio at /admin
if __name__ == "__main__":
    logger.debug("Running main block")
    admin_ui = setup_gradio()
    app = gr.mount_gradio_app(app, admin_ui, path="/admin")
    logger.debug("Gradio mounted, starting app")
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=7860)  # Hugging Face Spaces default port