zhang commited on
Commit
6fe1378
·
verified ·
1 Parent(s): 85b9af1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -1,24 +1,36 @@
1
  import gradio as gr
2
  import spaces
 
 
 
 
3
 
4
- # 定义推理逻辑
5
  @spaces.GPU
6
  def chat_fn(message, history):
7
- # 使用 gr.load 远程调用模型,这是在 Space 中最稳定的方案
8
- model = gr.load("models/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
9
- # 获取返回结果
10
- response = model(message)
11
- return response
 
 
 
 
 
 
 
 
 
12
 
13
- # 构建 OpenIPOS 品牌界面
14
  with gr.Blocks(fill_height=True) as demo:
15
  gr.Markdown("# 🚀 OpenIPOS Global 算力节点")
16
  gr.Markdown("### DeepSeek-R1 32B 满血版演示站")
17
 
18
- # 核心聊天组件(去掉了导致报错的 type 参数)
19
  gr.ChatInterface(
20
  chat_fn,
21
  description="本节点由 OpenIPOS 提供法律级高逻辑推理算力支持。",
 
22
  )
23
 
24
  demo.launch()
 
1
  import gradio as gr
2
  import spaces
3
+ from huggingface_hub import InferenceClient
4
+
5
+ # 初始化客户端
6
+ client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
7
 
 
8
  @spaces.GPU
9
  def chat_fn(message, history):
10
+ # 构建对话流
11
+ messages = [{"role": "user", "content": message}]
12
+
13
+ response = ""
14
+ # 使用流式输出,体验更好
15
+ for message in client.chat_completion(
16
+ messages,
17
+ max_tokens=2048,
18
+ stream=True,
19
+ ):
20
+ token = message.choices[0].delta.content
21
+ if token:
22
+ response += token
23
+ yield response
24
 
25
+ # 构建 OpenIPOS 界面
26
  with gr.Blocks(fill_height=True) as demo:
27
  gr.Markdown("# 🚀 OpenIPOS Global 算力节点")
28
  gr.Markdown("### DeepSeek-R1 32B 满血版演示站")
29
 
 
30
  gr.ChatInterface(
31
  chat_fn,
32
  description="本节点由 OpenIPOS 提供法律级高逻辑推理算力支持。",
33
+ type="messages" # 在最新的流式接口中建议带上
34
  )
35
 
36
  demo.launch()