Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,6 +53,7 @@ if os.path.exists(MODEL_PATH):
|
|
| 53 |
scaler_ccmq = joblib.load(f"scaler_ccmq_fold_{FOLD}.pkl")
|
| 54 |
scaler_osdi = joblib.load(f"scaler_osdi_fold_{FOLD}.pkl")
|
| 55 |
|
|
|
|
| 56 |
def analyze_and_predict(*all_answers):
|
| 57 |
ccmq_map = {"總是": 5, "經常": 4, "有時": 3, "很少": 2, "沒有": 1}
|
| 58 |
osdi_map = {"總是": 4, "經常": 3, "一半一半": 2, "偶而": 1, "完全不曾": 0}
|
|
@@ -61,7 +62,9 @@ def analyze_and_predict(*all_answers):
|
|
| 61 |
osdi_ans_raw = all_answers[24:]
|
| 62 |
|
| 63 |
if any(a is None for a in all_answers):
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
|
| 66 |
x1_raw = np.array([[ccmq_map[a] for a in ccmq_ans]])
|
| 67 |
x2_raw = np.array([[osdi_map[a] for a in osdi_ans_raw[:10]]])
|
|
@@ -104,7 +107,7 @@ def analyze_and_predict(*all_answers):
|
|
| 104 |
def reset_system():
|
| 105 |
return [gr.update(visible=True), gr.update(visible=False), gr.update(selected=0)] + [None] * 36
|
| 106 |
|
| 107 |
-
with gr.Blocks(theme=gr.themes.Soft(), css=
|
| 108 |
gr.Markdown("# 中醫AI診斷系統")
|
| 109 |
|
| 110 |
with gr.Column(visible=True) as stage_1:
|
|
@@ -130,10 +133,10 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".scroll-box { height: 450px; overflo
|
|
| 130 |
o10 = gr.Radio(["總是", "經常","一半一半","偶而","完全不曾"], label="12. 區域使用空調?")
|
| 131 |
all_osdi = [o1, o2, o3, o4, o5, o6, o7, o8, o9, o10]
|
| 132 |
|
| 133 |
-
submit_btn = gr.Button("
|
| 134 |
|
| 135 |
with gr.Column(visible=False) as stage_2:
|
| 136 |
-
gr.Markdown("##
|
| 137 |
with gr.Row():
|
| 138 |
res_table = gr.Dataframe(headers=["項目", "回答", "狀態"], interactive=False)
|
| 139 |
with gr.Column():
|
|
@@ -144,7 +147,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".scroll-box { height: 450px; overflo
|
|
| 144 |
plot_2 = gr.Plot()
|
| 145 |
finish_btn = gr.Button("結束並重新開始", size="lg", variant="secondary")
|
| 146 |
|
| 147 |
-
|
| 148 |
all_inputs = all_ccmq + all_osdi
|
| 149 |
btn_next.click(fn=lambda: gr.Tabs(selected=1), outputs=survey_tabs)
|
| 150 |
submit_btn.click(fn=analyze_and_predict, inputs=all_inputs, outputs=[stage_1, stage_2, res_title, res_desc, res_prob, res_table, plot_1, plot_2])
|
|
|
|
| 53 |
scaler_ccmq = joblib.load(f"scaler_ccmq_fold_{FOLD}.pkl")
|
| 54 |
scaler_osdi = joblib.load(f"scaler_osdi_fold_{FOLD}.pkl")
|
| 55 |
|
| 56 |
+
|
| 57 |
def analyze_and_predict(*all_answers):
|
| 58 |
ccmq_map = {"總是": 5, "經常": 4, "有時": 3, "很少": 2, "沒有": 1}
|
| 59 |
osdi_map = {"總是": 4, "經常": 3, "一半一半": 2, "偶而": 1, "完全不曾": 0}
|
|
|
|
| 62 |
osdi_ans_raw = all_answers[24:]
|
| 63 |
|
| 64 |
if any(a is None for a in all_answers):
|
| 65 |
+
missing_indices = [i+1 for i, a in enumerate(all_answers) if a is None]
|
| 66 |
+
print(f"DEBUG - 未填寫題目索引: {missing_indices}")
|
| 67 |
+
raise gr.Error(f"還有題目沒填完喔!未填索引: {missing_indices}")
|
| 68 |
|
| 69 |
x1_raw = np.array([[ccmq_map[a] for a in ccmq_ans]])
|
| 70 |
x2_raw = np.array([[osdi_map[a] for a in osdi_ans_raw[:10]]])
|
|
|
|
| 107 |
def reset_system():
|
| 108 |
return [gr.update(visible=True), gr.update(visible=False), gr.update(selected=0)] + [None] * 36
|
| 109 |
|
| 110 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 111 |
gr.Markdown("# 中醫AI診斷系統")
|
| 112 |
|
| 113 |
with gr.Column(visible=True) as stage_1:
|
|
|
|
| 133 |
o10 = gr.Radio(["總是", "經常","一半一半","偶而","完全不曾"], label="12. 區域使用空調?")
|
| 134 |
all_osdi = [o1, o2, o3, o4, o5, o6, o7, o8, o9, o10]
|
| 135 |
|
| 136 |
+
submit_btn = gr.Button("生成診斷報告", variant="primary")
|
| 137 |
|
| 138 |
with gr.Column(visible=False) as stage_2:
|
| 139 |
+
gr.Markdown("## AI 診斷分析報告")
|
| 140 |
with gr.Row():
|
| 141 |
res_table = gr.Dataframe(headers=["項目", "回答", "狀態"], interactive=False)
|
| 142 |
with gr.Column():
|
|
|
|
| 147 |
plot_2 = gr.Plot()
|
| 148 |
finish_btn = gr.Button("結束並重新開始", size="lg", variant="secondary")
|
| 149 |
|
| 150 |
+
|
| 151 |
all_inputs = all_ccmq + all_osdi
|
| 152 |
btn_next.click(fn=lambda: gr.Tabs(selected=1), outputs=survey_tabs)
|
| 153 |
submit_btn.click(fn=analyze_and_predict, inputs=all_inputs, outputs=[stage_1, stage_2, res_title, res_desc, res_prob, res_table, plot_1, plot_2])
|