Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,38 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from bert_explainer import analyze_text
|
| 3 |
-
|
| 4 |
-
def
|
| 5 |
-
result = analyze_text(text=text, explain_mode=mode)
|
| 6 |
-
status = result['status']
|
| 7 |
-
confidence = f"{result['confidence']}%"
|
| 8 |
-
keywords = ', '.join(result['suspicious_keywords'])
|
| 9 |
-
return status, confidence, keywords
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
]
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from bert_explainer import analyze_text, analyze_image
|
| 3 |
+
|
| 4 |
+
def predict_text(text, mode):
|
| 5 |
+
result = analyze_text(text=text, explain_mode=mode)
|
| 6 |
+
status = result['status']
|
| 7 |
+
confidence = f"{result['confidence']}%"
|
| 8 |
+
keywords = ', '.join(result['suspicious_keywords'])
|
| 9 |
+
return status, confidence, keywords
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def predict_image(file, mode):
|
| 13 |
+
result = analyze_image(file.read(), explain_mode= mode)
|
| 14 |
+
status = result['status']
|
| 15 |
+
confidence = f"{result['confidence']}%"
|
| 16 |
+
keywords = ', '.join(result['suspicious_keywords'])
|
| 17 |
+
return status, confidence, keywords
|
| 18 |
+
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Markdown("## 📩 預測詐騙訊息 (文字 + 圖片)")
|
| 21 |
+
|
| 22 |
+
with gr.Tab("文字預測"):
|
| 23 |
+
text_inputs = gr.TextArea(label="輸入訊息"),
|
| 24 |
+
mode_radio_1 = gr.Radio(choices=["cnn", "bert", "both"], label="分析模式", value="cnn")
|
| 25 |
+
text_buotton = gr.Button("開始分析")
|
| 26 |
+
text_result =[gr.Textbox(label = "判斷結果"),gr.Textbox(label = "可疑分數"),gr.Textbox(label = "可疑詞彙")]
|
| 27 |
+
text_buotton.click(fn=predict_text, inputs=[text_inputs, mode_radio_1], outputs=text_result)
|
| 28 |
+
|
| 29 |
+
with gr.Tab("圖片預測"):
|
| 30 |
+
image_inputs = gr.TextArea(label="上傳圖片"),
|
| 31 |
+
mode_radio_2 = gr.Radio(choices=["cnn", "bert", "both"], label="分析模式", value="cnn")
|
| 32 |
+
image_buotton = gr.Button("開始分析")
|
| 33 |
+
image_result =[gr.Textbox(label = "判斷結果"),gr.Textbox(label = "可疑分數"),gr.Textbox(label = "可疑詞彙")]
|
| 34 |
+
image_buotton.click(fn=predict_image, inputs=[image_inputs, mode_radio_2], outputs=image_result)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
demo.launch()
|