Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 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="詐騙文字分析
|
| 29 |
-
|
| 30 |
)
|
| 31 |
|
| 32 |
-
#
|
| 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="詐騙圖片分析
|
| 45 |
-
|
| 46 |
)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 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 |
+
)
|
|
|
|
|
|