Upload app.py
Browse files
app.py
CHANGED
|
@@ -232,18 +232,26 @@ def update_capacity_table(selected_wards: List[str]) -> pd.DataFrame:
|
|
| 232 |
def on_upload(file, selected_wards):
|
| 233 |
df, msg = read_table(file)
|
| 234 |
if df is None:
|
| 235 |
-
return gr.update(value=msg, visible=True), "", None, None, None
|
| 236 |
# Show available columns
|
| 237 |
avail = available_columns_text(df)
|
| 238 |
# Auto-detect mapping (indices)
|
| 239 |
auto_idx = auto_map_columns(df, selected_wards or [])
|
| 240 |
# Prepare number inputs defaults
|
| 241 |
-
def
|
| 242 |
return int(auto_idx[key]) if key in auto_idx else None
|
| 243 |
-
name_num =
|
| 244 |
-
id_num =
|
| 245 |
-
|
| 246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
|
| 248 |
def collect_mapping_numbers(name_num, id_num, ward_nums, selected_wards, n_cols):
|
| 249 |
"""Validate numeric mapping and build mapping dict {Field: index}"""
|
|
@@ -401,11 +409,12 @@ with gr.Blocks(title=APP_TITLE) as demo:
|
|
| 401 |
psy_num = gr.Number(label="หมายเลขคอลัมน์ Psychiatric", precision=0)
|
| 402 |
obs_num = gr.Number(label="หมายเลขคอลัมน์ Obstetrics", precision=0)
|
| 403 |
|
| 404 |
-
auto_btn.click(
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
|
|
|
| 409 |
|
| 410 |
with gr.Row():
|
| 411 |
clean_btn = gr.Button("Clean data (ดูพรีวิว)", variant="primary")
|
|
|
|
| 232 |
def on_upload(file, selected_wards):
|
| 233 |
df, msg = read_table(file)
|
| 234 |
if df is None:
|
| 235 |
+
return gr.update(value=msg, visible=True), "", None, None, None, None, None, None, None, None, None, None
|
| 236 |
# Show available columns
|
| 237 |
avail = available_columns_text(df)
|
| 238 |
# Auto-detect mapping (indices)
|
| 239 |
auto_idx = auto_map_columns(df, selected_wards or [])
|
| 240 |
# Prepare number inputs defaults
|
| 241 |
+
def idx_or_none(key):
|
| 242 |
return int(auto_idx[key]) if key in auto_idx else None
|
| 243 |
+
name_num = idx_or_none("NAME")
|
| 244 |
+
id_num = idx_or_none("ID")
|
| 245 |
+
med_num = idx_or_none("Medical")
|
| 246 |
+
med1_num = idx_or_none("Medical_1")
|
| 247 |
+
med2_num = idx_or_none("Medical_2")
|
| 248 |
+
surg_num = idx_or_none("Surgical")
|
| 249 |
+
ped_num = idx_or_none("Pediatric")
|
| 250 |
+
comm_num = idx_or_none("Community")
|
| 251 |
+
psy_num = idx_or_none("Psychiatric")
|
| 252 |
+
obs_num = idx_or_none("Obstetrics")
|
| 253 |
+
return (gr.update(value="✓ อ่านไฟล์สำเร็จ", visible=True), avail, name_num, id_num,
|
| 254 |
+
med_num, med1_num, med2_num, surg_num, ped_num, comm_num, psy_num, obs_num)
|
| 255 |
|
| 256 |
def collect_mapping_numbers(name_num, id_num, ward_nums, selected_wards, n_cols):
|
| 257 |
"""Validate numeric mapping and build mapping dict {Field: index}"""
|
|
|
|
| 409 |
psy_num = gr.Number(label="หมายเลขคอลัมน์ Psychiatric", precision=0)
|
| 410 |
obs_num = gr.Number(label="หมายเลขคอลัมน์ Obstetrics", precision=0)
|
| 411 |
|
| 412 |
+
auto_btn.click(
|
| 413 |
+
fn=on_upload,
|
| 414 |
+
inputs=[file, selected_wards],
|
| 415 |
+
outputs=[status, available, name_num, id_num,
|
| 416 |
+
med_num, med1_num, med2_num, surg_num, ped_num, comm_num, psy_num, obs_num]
|
| 417 |
+
)
|
| 418 |
|
| 419 |
with gr.Row():
|
| 420 |
clean_btn = gr.Button("Clean data (ดูพรีวิว)", variant="primary")
|