Spaces:
Running on Zero
Running on Zero
zhang commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,35 +2,40 @@ 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 = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
# 使用流式输出,体验更好
|
| 15 |
-
for message in client.chat_completion(
|
| 16 |
-
messages,
|
| 17 |
max_tokens=2048,
|
| 18 |
stream=True,
|
| 19 |
-
)
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|
|
|
|
| 2 |
import spaces
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
# 初始化客户端,指向 DeepSeek-R1-32B
|
| 6 |
client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
|
| 7 |
|
| 8 |
@spaces.GPU
|
| 9 |
def chat_fn(message, history):
|
| 10 |
+
# 构建符合 OpenIPOS 标准的对话上下文
|
| 11 |
+
messages = []
|
| 12 |
+
for turn in history:
|
| 13 |
+
messages.append({"role": "user", "content": turn[0]})
|
| 14 |
+
messages.append({"role": "assistant", "content": turn[1]})
|
| 15 |
+
messages.append({"role": "user", "content": message})
|
| 16 |
|
| 17 |
+
generate_kwargs = dict(
|
|
|
|
|
|
|
|
|
|
| 18 |
max_tokens=2048,
|
| 19 |
stream=True,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
response = ""
|
| 23 |
+
# 流式获取,确保文字一个一个跳出来,更有算力质感
|
| 24 |
+
for msg in client.chat_completion(messages, **generate_kwargs):
|
| 25 |
+
token = msg.choices[0].delta.content
|
| 26 |
if token:
|
| 27 |
response += token
|
| 28 |
yield response
|
| 29 |
|
| 30 |
+
# 构建 OpenIPOS 品牌界面
|
| 31 |
with gr.Blocks(fill_height=True) as demo:
|
| 32 |
gr.Markdown("# 🚀 OpenIPOS Global 算力节点")
|
| 33 |
gr.Markdown("### DeepSeek-R1 32B 满血版演示站")
|
| 34 |
|
| 35 |
+
# 核心聊天组件(彻底删除了报错的 type 参数)
|
| 36 |
gr.ChatInterface(
|
| 37 |
+
fn=chat_fn,
|
| 38 |
+
description="本节点由 OpenIPOS 提供法律级高逻辑推理算力支持。支持 DeepSeek-R1 完整思考链路。",
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
demo.launch()
|