Spaces:
Sleeping
Sleeping
Update app.py
Browse filesfix Text Mode bug
app.py
CHANGED
|
@@ -339,8 +339,21 @@ def process_input(mode, text, file, image):
|
|
| 339 |
image_result = None
|
| 340 |
image_label_text = ""
|
| 341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
if mode == "Text Mode":
|
| 343 |
result_text, feature_text, plot_image = analyze_text(text, file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
else: # 圖片模式
|
| 345 |
if image is not None:
|
| 346 |
if isinstance(image, Image.Image):
|
|
@@ -350,9 +363,15 @@ def process_input(mode, text, file, image):
|
|
| 350 |
image_result = img
|
| 351 |
image_label_text, prob = predict_image(img)
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 358 |
gr.Markdown("## 🤖 AI Detection System")
|
|
@@ -422,7 +441,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 422 |
btn.click(
|
| 423 |
process_input,
|
| 424 |
inputs=[mode_selector, input_text, input_file, input_image],
|
| 425 |
-
outputs=[output_label, output_feats, output_plot, output_image, output_image_label, input_text]
|
| 426 |
)
|
| 427 |
|
| 428 |
demo.launch()
|
|
|
|
| 339 |
image_result = None
|
| 340 |
image_label_text = ""
|
| 341 |
|
| 342 |
+
# 預設不清空任何輸入(等會視情況覆蓋)
|
| 343 |
+
clear_textbox = gr.update()
|
| 344 |
+
clear_filebox = gr.update()
|
| 345 |
+
|
| 346 |
if mode == "Text Mode":
|
| 347 |
result_text, feature_text, plot_image = analyze_text(text, file)
|
| 348 |
+
|
| 349 |
+
# ★ 如果是在用「文字輸入」分析 → 清空 Word 上傳框
|
| 350 |
+
if file is None and text.strip() != "":
|
| 351 |
+
clear_filebox = gr.update(value=None)
|
| 352 |
+
|
| 353 |
+
# ★ 如果是在用「Word 檔」分析 → 清空文字輸入框
|
| 354 |
+
elif file is not None:
|
| 355 |
+
clear_textbox = gr.update(value="")
|
| 356 |
+
|
| 357 |
else: # 圖片模式
|
| 358 |
if image is not None:
|
| 359 |
if isinstance(image, Image.Image):
|
|
|
|
| 363 |
image_result = img
|
| 364 |
image_label_text, prob = predict_image(img)
|
| 365 |
|
| 366 |
+
return (
|
| 367 |
+
result_text,
|
| 368 |
+
feature_text,
|
| 369 |
+
plot_image,
|
| 370 |
+
image_result,
|
| 371 |
+
image_label_text,
|
| 372 |
+
clear_textbox, # 清文字輸入框
|
| 373 |
+
clear_filebox # 清 Word 上傳框
|
| 374 |
+
)
|
| 375 |
|
| 376 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 377 |
gr.Markdown("## 🤖 AI Detection System")
|
|
|
|
| 441 |
btn.click(
|
| 442 |
process_input,
|
| 443 |
inputs=[mode_selector, input_text, input_file, input_image],
|
| 444 |
+
outputs=[output_label, output_feats, output_plot, output_image, output_image_label, input_text, input_file ]
|
| 445 |
)
|
| 446 |
|
| 447 |
demo.launch()
|