Spaces:
Sleeping
Sleeping
Commit
•
39e69a8
1
Parent(s):
e1c0e8f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# 使用 Hugging Face 上存储的模型
|
5 |
+
model_name = "Dominic0406/medical_gpt2"
|
6 |
+
pipe = pipeline("text-generation", model=model_name)
|
7 |
+
|
8 |
+
def generate_diagnosis(symptoms):
|
9 |
+
input_text = f"患者症状: {symptoms}\n诊断: "
|
10 |
+
response = pipe(input_text, max_length=150, num_return_sequences=1)[0]['generated_text']
|
11 |
+
diagnosis = response.split("诊断: ")[-1].strip()
|
12 |
+
return diagnosis
|
13 |
+
|
14 |
+
# 创建 Gradio 接口
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=generate_diagnosis,
|
17 |
+
inputs=gr.Textbox(lines=7, placeholder="输入患者症状..."),
|
18 |
+
outputs="text",
|
19 |
+
title="医疗诊断 AI",
|
20 |
+
description="输入患者的症状,模型将生成一个可能的诊断结果。"
|
21 |
+
)
|
22 |
+
|
23 |
+
# 启动接口
|
24 |
+
if __name__ == "__main__":
|
25 |
+
iface.launch()
|