Ellie5757575757 commited on
Commit
e23608b
·
verified ·
1 Parent(s): 4b9b681

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -4,28 +4,31 @@ import json
4
 
5
  def predict_aphasia(json_input):
6
  try:
7
- # 解析 JSON 輸入
8
  data = json.loads(json_input)
9
 
10
- # 預處理數據給你的模型
11
- processed_data = preprocess(data)
 
12
 
13
- # 模型推
14
  with torch.no_grad():
15
- prediction = model(processed_data)
16
- aphasia_type = get_aphasia_type(prediction)
 
17
 
18
- return f"預測的失語症類型: {aphasia_type}"
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="貼上的JSON數據..."
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="失語症類型分類器",