Upload folder using huggingface_hub
Browse files- home.py +28 -21
- modules/db.py +10 -3
home.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
from datetime import datetime
|
|
|
|
| 3 |
from typing import Dict, Any, List, Tuple
|
| 4 |
|
| 5 |
import gradio as gr
|
|
@@ -220,7 +221,11 @@ def add_patient_ui(user_email, name, age, gender):
|
|
| 220 |
if not user:
|
| 221 |
return "User not found"
|
| 222 |
pid = db.add_patient(user["_id"], name, age, gender)
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
| 225 |
|
| 226 |
def edit_patient_ui(patient_id, name, age, gender):
|
|
@@ -231,36 +236,38 @@ def edit_patient_ui(patient_id, name, age, gender):
|
|
| 231 |
return "β
Updated" if success else "β Patient not found"
|
| 232 |
|
| 233 |
|
| 234 |
-
def delete_patient_ui(patient_id):
|
| 235 |
db = get_db()
|
| 236 |
success = db.delete_patient(patient_id)
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
|
| 240 |
-
# ----- Gradio UI -----
|
| 241 |
# ----- Gradio UI (Sidebar Layout) -----
|
| 242 |
with gr.Blocks(
|
| 243 |
title=get_app_title(), theme=get_app_theme(), css=get_css(), fill_height=True
|
| 244 |
) as demo:
|
| 245 |
-
with gr.
|
| 246 |
-
|
| 247 |
-
gr.Markdown("### Sidebar")
|
| 248 |
-
|
| 249 |
-
email_in = gr.Textbox(label="User Email", placeholder="doctor1@sheami.com")
|
| 250 |
-
load_btn = gr.Button("π Load Patients")
|
| 251 |
|
| 252 |
-
|
|
|
|
| 253 |
|
| 254 |
-
|
| 255 |
-
new_name = gr.Textbox(label="Name")
|
| 256 |
-
new_age = gr.Number(label="Age")
|
| 257 |
-
new_gender = gr.Dropdown(["M", "F"], label="Gender")
|
| 258 |
-
add_btn = gr.Button("Add")
|
| 259 |
-
add_out = gr.Textbox(label="Status")
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
|
|
|
|
|
|
|
|
|
| 264 |
with gr.Column(scale=3): # Main area
|
| 265 |
with gr.Row():
|
| 266 |
edit_name = gr.Textbox(label="Edit Name")
|
|
@@ -335,11 +342,11 @@ with gr.Blocks(
|
|
| 335 |
add_btn.click(
|
| 336 |
add_patient_ui,
|
| 337 |
inputs=[email_in, new_name, new_age, new_gender],
|
| 338 |
-
outputs=add_out,
|
| 339 |
)
|
| 340 |
|
| 341 |
delete_btn.click(
|
| 342 |
-
delete_patient_ui, inputs=[patient_list], outputs=delete_out
|
| 343 |
)
|
| 344 |
|
| 345 |
edit_btn.click(
|
|
|
|
| 1 |
import os
|
| 2 |
from datetime import datetime
|
| 3 |
+
from random import choices
|
| 4 |
from typing import Dict, Any, List, Tuple
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 221 |
if not user:
|
| 222 |
return "User not found"
|
| 223 |
pid = db.add_patient(user["_id"], name, age, gender)
|
| 224 |
+
if pid:
|
| 225 |
+
(user_dict,patients) = load_user(user_email)
|
| 226 |
+
return f"β
Patient {name} added (ID: {pid})", gr.update(choices=patients)
|
| 227 |
+
else:
|
| 228 |
+
return f"β Error adding patient", gr.update()
|
| 229 |
|
| 230 |
|
| 231 |
def edit_patient_ui(patient_id, name, age, gender):
|
|
|
|
| 236 |
return "β
Updated" if success else "β Patient not found"
|
| 237 |
|
| 238 |
|
| 239 |
+
def delete_patient_ui(user_email, patient_id):
|
| 240 |
db = get_db()
|
| 241 |
success = db.delete_patient(patient_id)
|
| 242 |
+
if success:
|
| 243 |
+
(user,patients) = load_user(user_email)
|
| 244 |
+
return "β
Deleted", gr.update(choices=patients)
|
| 245 |
+
else:
|
| 246 |
+
return "β Patient not found", gr.update()
|
| 247 |
|
| 248 |
|
|
|
|
| 249 |
# ----- Gradio UI (Sidebar Layout) -----
|
| 250 |
with gr.Blocks(
|
| 251 |
title=get_app_title(), theme=get_app_theme(), css=get_css(), fill_height=True
|
| 252 |
) as demo:
|
| 253 |
+
with gr.Sidebar(): # Sidebar
|
| 254 |
+
# gr.Markdown("### Sidebar")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
+
email_in = gr.Textbox(label="User Email", placeholder="doctor1@sheami.com")
|
| 257 |
+
load_btn = gr.Button("π Load Patients")
|
| 258 |
|
| 259 |
+
patient_list = gr.Radio(label="Patients", choices=[], interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
|
| 261 |
+
with gr.Accordion("β Add Patient", open=False):
|
| 262 |
+
new_name = gr.Textbox(label="Name")
|
| 263 |
+
new_age = gr.Number(label="Age")
|
| 264 |
+
new_gender = gr.Dropdown(["M", "F"], label="Gender")
|
| 265 |
+
add_btn = gr.Button("Add")
|
| 266 |
+
add_out = gr.Textbox(label="Status")
|
| 267 |
|
| 268 |
+
delete_btn = gr.Button("ποΈ Delete Selected")
|
| 269 |
+
delete_out = gr.Textbox(label="Status")
|
| 270 |
+
with gr.Row():
|
| 271 |
with gr.Column(scale=3): # Main area
|
| 272 |
with gr.Row():
|
| 273 |
edit_name = gr.Textbox(label="Edit Name")
|
|
|
|
| 342 |
add_btn.click(
|
| 343 |
add_patient_ui,
|
| 344 |
inputs=[email_in, new_name, new_age, new_gender],
|
| 345 |
+
outputs=[add_out,patient_list],
|
| 346 |
)
|
| 347 |
|
| 348 |
delete_btn.click(
|
| 349 |
+
delete_patient_ui, inputs=[email_in, patient_list], outputs=[delete_out,patient_list]
|
| 350 |
)
|
| 351 |
|
| 352 |
edit_btn.click(
|
modules/db.py
CHANGED
|
@@ -7,6 +7,9 @@ from dotenv import load_dotenv
|
|
| 7 |
class SheamiDB:
|
| 8 |
def __init__(self, uri: str, db_name: str = "sheami"):
|
| 9 |
"""Initialize connection to MongoDB Atlas (or local Mongo)."""
|
|
|
|
|
|
|
|
|
|
| 10 |
self.client = MongoClient(uri)
|
| 11 |
self.db = self.client[db_name]
|
| 12 |
|
|
@@ -140,6 +143,10 @@ class SheamiDB:
|
|
| 140 |
result = self.patients.update_one({"_id": patient_id}, {"$set": fields})
|
| 141 |
return result.modified_count > 0
|
| 142 |
|
| 143 |
-
def delete_patient(self, patient_id):
|
| 144 |
-
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
class SheamiDB:
|
| 8 |
def __init__(self, uri: str, db_name: str = "sheami"):
|
| 9 |
"""Initialize connection to MongoDB Atlas (or local Mongo)."""
|
| 10 |
+
if not uri:
|
| 11 |
+
load_dotenv(override=True)
|
| 12 |
+
uri = os.getenv("MONGODB_URI")
|
| 13 |
self.client = MongoClient(uri)
|
| 14 |
self.db = self.client[db_name]
|
| 15 |
|
|
|
|
| 143 |
result = self.patients.update_one({"_id": patient_id}, {"$set": fields})
|
| 144 |
return result.modified_count > 0
|
| 145 |
|
| 146 |
+
def delete_patient(self, patient_id: str) -> bool:
|
| 147 |
+
try:
|
| 148 |
+
result = self.patients.delete_one({"_id": ObjectId(patient_id)})
|
| 149 |
+
return result.deleted_count > 0
|
| 150 |
+
except Exception as e:
|
| 151 |
+
print(f"Error deleting patient: {e}")
|
| 152 |
+
return False
|