Update app.py
Browse files
app.py
CHANGED
|
@@ -4,28 +4,31 @@ import json
|
|
| 4 |
|
| 5 |
def predict_aphasia(json_input):
|
| 6 |
try:
|
| 7 |
-
# 解析
|
| 8 |
data = json.loads(json_input)
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
with torch.no_grad():
|
| 15 |
-
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
return f"預測的失語症類型: {
|
| 19 |
|
| 20 |
except Exception as e:
|
| 21 |
return f"錯誤: {str(e)}"
|
| 22 |
|
|
|
|
| 23 |
demo = gr.Interface(
|
| 24 |
fn=predict_aphasia,
|
| 25 |
inputs=gr.Textbox(
|
| 26 |
label="輸入對話數據 (JSON格式)",
|
| 27 |
lines=20,
|
| 28 |
-
placeholder="貼上
|
| 29 |
),
|
| 30 |
outputs=gr.Textbox(label="分類結果"),
|
| 31 |
title="失語症類型分類器",
|
|
|
|
| 4 |
|
| 5 |
def predict_aphasia(json_input):
|
| 6 |
try:
|
| 7 |
+
# 解析JSON輸入
|
| 8 |
data = json.loads(json_input)
|
| 9 |
|
| 10 |
+
# 載入你的模型
|
| 11 |
+
model = torch.load('pytorch_model.bin', map_location='cpu')
|
| 12 |
+
model.eval()
|
| 13 |
|
| 14 |
+
# 處理數據並預測
|
| 15 |
with torch.no_grad():
|
| 16 |
+
# 這裡放你的資料前處理和模型推理代碼
|
| 17 |
+
result = model(processed_data)
|
| 18 |
+
predicted_type = result # 例如 "BROCA", "WERNICKE" 等
|
| 19 |
|
| 20 |
+
return f"預測的失語症類型: {predicted_type}"
|
| 21 |
|
| 22 |
except Exception as e:
|
| 23 |
return f"錯誤: {str(e)}"
|
| 24 |
|
| 25 |
+
# 建立界面
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=predict_aphasia,
|
| 28 |
inputs=gr.Textbox(
|
| 29 |
label="輸入對話數據 (JSON格式)",
|
| 30 |
lines=20,
|
| 31 |
+
placeholder="請貼上您的JSON數據..."
|
| 32 |
),
|
| 33 |
outputs=gr.Textbox(label="分類結果"),
|
| 34 |
title="失語症類型分類器",
|