Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# 使用 Hugging Face Inference API 调用云端模型(无需本地加载)
|
5 |
# 正确方法1:从环境变量读取
|
@@ -11,13 +16,22 @@ def medical_chat(user_input, history):
|
|
11 |
prompt = f"患者:{user_input}\n医生:"
|
12 |
|
13 |
# 调用云端模型(示例使用微软BioGPT)
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
prompt=prompt,
|
16 |
model="microsoft/BioGPT-Large",
|
17 |
-
max_new_tokens=150
|
18 |
-
temperature=0.7,
|
19 |
-
repetition_penalty=1.2
|
20 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# 提取医生回复部分
|
23 |
doctor_response = response.split("医生:")[-1].strip()
|
@@ -40,3 +54,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
40 |
# 启动应用(Hugging Face Spaces 会自动处理)
|
41 |
demo.launch(debug=False)
|
42 |
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
# 在 app.py 顶部添加
|
4 |
+
import os
|
5 |
+
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" # 中国大陆加速
|
6 |
+
|
7 |
+
|
8 |
|
9 |
# 使用 Hugging Face Inference API 调用云端模型(无需本地加载)
|
10 |
# 正确方法1:从环境变量读取
|
|
|
16 |
prompt = f"患者:{user_input}\n医生:"
|
17 |
|
18 |
# 调用云端模型(示例使用微软BioGPT)
|
19 |
+
from tenacity import retry, stop_after_attempt, wait_exponential
|
20 |
+
|
21 |
+
@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=1, min=2, max=10))
|
22 |
+
def safe_model_call(prompt):
|
23 |
+
return client.text_generation(
|
24 |
prompt=prompt,
|
25 |
model="microsoft/BioGPT-Large",
|
26 |
+
max_new_tokens=150
|
|
|
|
|
27 |
)
|
28 |
+
# response = client.text_generation(
|
29 |
+
# prompt=prompt,
|
30 |
+
# model="microsoft/BioGPT-Large",
|
31 |
+
# max_new_tokens=150,
|
32 |
+
# temperature=0.7,
|
33 |
+
# repetition_penalty=1.2
|
34 |
+
# )
|
35 |
|
36 |
# 提取医生回复部分
|
37 |
doctor_response = response.split("医生:")[-1].strip()
|
|
|
54 |
# 启动应用(Hugging Face Spaces 会自动处理)
|
55 |
demo.launch(debug=False)
|
56 |
|
57 |
+
|
58 |
+
|
59 |
+
|