Ali2206 commited on
Commit
9e1f79a
Β·
verified Β·
1 Parent(s): 5cb3ecd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -25
app.py CHANGED
@@ -9,8 +9,10 @@ app = FastAPI()
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)
@@ -26,13 +28,14 @@ def create_doctor(full_name, email, matricule, password, specialty):
26
  payload = {
27
  "full_name": full_name,
28
  "email": email,
29
- "matricule": matricule,
30
  "password": password,
31
  "specialty": specialty,
32
  }
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:
@@ -105,7 +108,7 @@ with gr.Blocks(css="""
105
  }
106
  """) as admin_ui:
107
  gr.Markdown("<div class='title-text'>πŸ‘¨β€βš•οΈ Doctor Account Creator</div>")
108
- gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel.</div>")
109
 
110
  with gr.Column():
111
  full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
@@ -123,24 +126,6 @@ with gr.Blocks(css="""
123
  submit_btn = gr.Button("Create Doctor Account")
124
  output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"])
125
 
126
- def create_doctor(full_name, email, matricule, specialty, password):
127
- import requests
128
- payload = {
129
- "full_name": full_name,
130
- "email": email,
131
- "matricule": matricule,
132
- "specialty": specialty,
133
- "password": password
134
- }
135
- try:
136
- res = requests.post("https://rocketfarmstudios-cps-api.hf.space/admin/create-doctor", json=payload)
137
- if res.status_code == 200:
138
- return "βœ… Doctor account successfully created!"
139
- else:
140
- return f"❌ {res.json().get('detail', 'Something went wrong')}"
141
- except Exception as e:
142
- return f"❌ Connection error: {str(e)}"
143
-
144
  submit_btn.click(
145
  fn=create_doctor,
146
  inputs=[full_name, email, matricule, specialty, password],
@@ -148,4 +133,4 @@ with gr.Blocks(css="""
148
  )
149
 
150
  # Mount Gradio at /admin
151
- app = gr.mount_gradio_app(app, admin_ui, path="/admin")
 
9
  # CORS
10
  app.add_middleware(
11
  CORSMiddleware,
12
+ allow_origins=["*"],
13
+ allow_credentials=True,
14
+ allow_methods=["*"],
15
+ allow_headers=["*"],
16
  )
17
 
18
  app.include_router(api_router)
 
28
  payload = {
29
  "full_name": full_name,
30
  "email": email,
31
+ "license_number": matricule, # Map 'matricule' to 'license_number' as expected by the backend
32
  "password": password,
33
  "specialty": specialty,
34
  }
35
  try:
36
+ # Updated endpoint to match the actual route in auth.py
37
+ res = requests.post(f"{BACKEND_URL}/auth/admin/doctors", json=payload)
38
+ if res.status_code == 201: # Status code for successful creation
39
  return "βœ… Doctor created successfully!"
40
  return f"❌ {res.json().get('detail', 'Error occurred')}"
41
  except Exception as e:
 
108
  }
109
  """) as admin_ui:
110
  gr.Markdown("<div class='title-text'>πŸ‘¨β€βš•οΈ Doctor Account Creator</div>")
111
+ gr.Markdown("<div class='description-text'>Admins can register new doctors using this secure panel. Generated at 05:44 PM CET on Friday, May 16, 2025.</div>")
112
 
113
  with gr.Column():
114
  full_name = gr.Textbox(label="Full Name", placeholder="e.g. Dr. Sarah Hopkins")
 
126
  submit_btn = gr.Button("Create Doctor Account")
127
  output = gr.Textbox(label="", show_label=False, elem_classes=["output-box"])
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  submit_btn.click(
130
  fn=create_doctor,
131
  inputs=[full_name, email, matricule, specialty, password],
 
133
  )
134
 
135
  # Mount Gradio at /admin
136
+ app = gr.mount_gradio_app(app, admin_ui, path="/admin")