Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # 使用 Hugging Face 上存储的模型 | |
| model_name = "Dominic0406/medical_gpt2" | |
| pipe = pipeline("text-generation", model=model_name) | |
| def generate_diagnosis(symptoms): | |
| input_text = f"患者症状: {symptoms}\n诊断: " | |
| response = pipe(input_text, max_length=150, num_return_sequences=1)[0]['generated_text'] | |
| diagnosis = response.split("诊断: ")[-1].strip() | |
| return diagnosis | |
| # 创建 Gradio 接口 | |
| iface = gr.Interface( | |
| fn=generate_diagnosis, | |
| inputs=gr.Textbox(lines=7, placeholder="输入患者症状..."), | |
| outputs="text", | |
| title="医疗诊断 AI", | |
| description="输入患者的症状,模型将生成一个可能的诊断结果。" | |
| ) | |
| # 启动接口 | |
| if __name__ == "__main__": | |
| iface.launch() | |