Ali2206 commited on
Commit
ce9fa5a
Β·
verified Β·
1 Parent(s): 0f3fd66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -43
app.py CHANGED
@@ -6,27 +6,22 @@ import requests
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,
@@ -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 account successfully created!"
42
- else:
43
- return f"❌ {res.json().get('detail', 'Something went wrong')}"
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")
 
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")