Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import torch | |
| import json | |
| def predict_aphasia(json_input): | |
| try: | |
| # 解析JSON輸入 | |
| data = json.loads(json_input) | |
| # 載入你的模型 | |
| model = torch.load('pytorch_model.bin', map_location='cpu') | |
| model.eval() | |
| # 處理數據並預測 | |
| with torch.no_grad(): | |
| # 這裡放你的資料前處理和模型推理代碼 | |
| result = model(processed_data) | |
| predicted_type = result # 例如 "BROCA", "WERNICKE" 等 | |
| return f"預測的失語症類型: {predicted_type}" | |
| except Exception as e: | |
| return f"錯誤: {str(e)}" | |
| # 建立界面 | |
| demo = gr.Interface( | |
| fn=predict_aphasia, | |
| inputs=gr.Textbox( | |
| label="輸入對話數據 (JSON格式)", | |
| lines=20, | |
| placeholder="請貼上您的JSON數據..." | |
| ), | |
| outputs=gr.Textbox(label="分類結果"), | |
| title="失語症類型分類器", | |
| description="上傳對話數據,AI會分析並預測失語症類型" | |
| ) |