Hellowish commited on
Commit
a2dd7ca
·
verified ·
1 Parent(s): 35c9fc4

Update app.py

Browse files

fix Text Mode bug

Files changed (1) hide show
  1. app.py +23 -4
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
- clear_textbox = gr.update(value="")
354
-
355
- return result_text, feature_text, plot_image, image_result, image_label_text, clear_textbox
 
 
 
 
 
 
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()