Bennie12 commited on
Commit
f9a8a9b
·
verified ·
1 Parent(s): b08d402

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import gradio as gr
2
- import fastapi
3
  from bert_explainer import analyze_text, analyze_image
4
 
5
  # ⛳ 分析文字
@@ -13,7 +12,7 @@ def predict_image(file_path, mode):
13
  result = analyze_image(f.read(), explain_mode=mode)
14
  return result['status'], f"{result['confidence']}%", ', '.join(result['suspicious_keywords'])
15
 
16
- # 🚀 建立文字 API
17
  text_api = gr.Interface(
18
  fn=predict_text,
19
  inputs=[
@@ -25,11 +24,11 @@ text_api = gr.Interface(
25
  gr.Textbox(label="置信度"),
26
  gr.Textbox(label="可疑詞彙")
27
  ],
28
- title="詐騙文字分析 API",
29
- flagging_mode="never"
30
  )
31
 
32
- # 🚀 建立圖片 API
33
  image_api = gr.Interface(
34
  fn=predict_image,
35
  inputs=[
@@ -41,14 +40,12 @@ image_api = gr.Interface(
41
  gr.Textbox(label="置信度"),
42
  gr.Textbox(label="可疑詞彙")
43
  ],
44
- title="詐騙圖片分析 API",
45
- flagging_mode="never"
46
  )
47
 
48
- # 🌐 FastAPI 主應用
49
- app = fastapi.FastAPI()
50
- app = gr.mount_gradio_app(app, text_api, path="/run/predict_text")
51
- app = gr.mount_gradio_app(app, image_api, path="/run/predict_image")
52
-
53
- # ✅ 讓 Hugging Face 生成 /view=api 文件頁
54
- demo = text_api
 
1
  import gradio as gr
 
2
  from bert_explainer import analyze_text, analyze_image
3
 
4
  # ⛳ 分析文字
 
12
  result = analyze_image(f.read(), explain_mode=mode)
13
  return result['status'], f"{result['confidence']}%", ', '.join(result['suspicious_keywords'])
14
 
15
+ # 🧩 文字分析介面
16
  text_api = gr.Interface(
17
  fn=predict_text,
18
  inputs=[
 
24
  gr.Textbox(label="置信度"),
25
  gr.Textbox(label="可疑詞彙")
26
  ],
27
+ title="詐騙文字分析",
28
+ allow_flagging="never"
29
  )
30
 
31
+ # 🧩 圖片分析介面
32
  image_api = gr.Interface(
33
  fn=predict_image,
34
  inputs=[
 
40
  gr.Textbox(label="置信度"),
41
  gr.Textbox(label="可疑詞彙")
42
  ],
43
+ title="詐騙圖片分析",
44
+ allow_flagging="never"
45
  )
46
 
47
+ # 這是 Hugging Face Space 預設會尋找的變數,會觸發自動啟動 + 文件頁
48
+ demo = gr.TabbedInterface(
49
+ interface_list=[text_api, image_api],
50
+ tab_names=["文字模式", "圖片模式"]
51
+ )