Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from bert_explainer import analyze_text, analyze_image
|
| 3 |
-
|
| 4 |
# 🧠 預測函式:供 UI 和 API 共用
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def predict_text(text, mode):
|
| 6 |
result = analyze_text(text=text, explain_mode=mode)
|
| 7 |
return result["status"], f"{result['confidence']}%", ", ".join(result["suspicious_keywords"])
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from bert_explainer import analyze_text, analyze_image
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
# 🧠 預測函式:供 UI 和 API 共用
|
| 5 |
+
api = FastAPI()
|
| 6 |
+
|
| 7 |
+
@api.get("/test")
|
| 8 |
+
def test_predict_text():
|
| 9 |
+
# 測試文字直接寫死,不需輸入
|
| 10 |
+
result = analyze_text("這是測試訊息", explain_mode="cnn")
|
| 11 |
+
return {
|
| 12 |
+
"status": result["status"],
|
| 13 |
+
"confidence": f'{result["confidence"]}%',
|
| 14 |
+
"suspicious_keywords": result["suspicious_keywords"]
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
def predict_text(text, mode):
|
| 18 |
result = analyze_text(text=text, explain_mode=mode)
|
| 19 |
return result["status"], f"{result['confidence']}%", ", ".join(result["suspicious_keywords"])
|