ALYYAN commited on
Commit
02f30a7
·
unverified ·
1 Parent(s): 9818f66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -21,9 +21,38 @@ except FileNotFoundError:
21
 
22
  # --- Core Logic Functions (Unchanged and Correct) ---
23
  async def process_analysis(patient_name, patient_age, image_list, is_sample=False):
24
- # ... (code is the same)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  async def refresh_history_table():
26
- # ... (code is the same)
 
 
 
 
27
 
28
  # --- Gradio UI Definition ---
29
  css = """
 
21
 
22
  # --- Core Logic Functions (Unchanged and Correct) ---
23
  async def process_analysis(patient_name, patient_age, image_list, is_sample=False):
24
+ if not is_sample and (not patient_name or patient_age is None):
25
+ raise gr.Error("Patient Name and Age are required.")
26
+ if not image_list:
27
+ raise gr.Error("At least one image is required.")
28
+
29
+ result = prediction_pipeline.predict(image_list)
30
+ if "error" in result:
31
+ raise gr.Error(result.get("details", result["error"]))
32
+
33
+ final_pred = result["final_prediction"]
34
+ final_conf = result["final_confidence"]
35
+
36
+ if not is_sample:
37
+ await add_patient_record(str(patient_name), int(patient_age), final_pred, final_conf)
38
+
39
+ confidences = {"NORMAL": 0.0, "PNEUMONIA": 0.0}
40
+ confidences[final_pred] = final_conf
41
+ confidences["NORMAL" if final_pred == "PNEUMONIA" else "PNEUMONIA"] = 1 - final_conf
42
+
43
+ return [
44
+ gr.update(visible=False),
45
+ gr.update(visible=True),
46
+ gr.update(value=result["watermarked_images"]),
47
+ gr.update(value=confidences)
48
+ ]
49
+
50
  async def refresh_history_table():
51
+ records = await get_all_records()
52
+ data_for_df = []
53
+ if records:
54
+ data_for_df = [[r.get('name'), r.get('age'), r.get('prediction_result'), f"{r.get('confidence_score', 0):.2%}", r.get('timestamp').strftime('%Y-%m-%d %H:%M')] for r in records]
55
+ return gr.update(value=data_for_df)
56
 
57
  # --- Gradio UI Definition ---
58
  css = """