OpenIPOS commited on
Commit
f2604be
·
verified ·
1 Parent(s): 85f1538

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,17 +1,17 @@
1
  import os
2
  import gradio as gr
3
- import spaces
4
  import fitz
5
  import docx
6
  from huggingface_hub import InferenceClient
7
 
8
- # 1. 引擎配置:Qwen-2.5-72B-Instruct (目前最稳的 70B+ 免费通道)
9
  model_id = "Qwen/Qwen2.5-72B-Instruct"
10
  hf_token = os.getenv("HF_TOKEN")
11
 
12
  client = InferenceClient(
13
  model=model_id,
14
  token=hf_token,
 
15
  headers={"Authorization": f"Bearer {hf_token}"} if hf_token else None
16
  )
17
 
@@ -32,11 +32,10 @@ def extract_text(file_path):
32
  except:
33
  return ""
34
 
35
- @spaces.GPU(duration=60)
36
  def chat_fn(message, history):
37
  clean_messages = []
38
- # Qwen 专用的系统提示词
39
- clean_messages.append({"role": "system", "content": "You are a senior intellectual property expert and professional translator. Provide high-quality analysis."})
40
 
41
  for turn in history:
42
  clean_messages.append({"role": turn["role"], "content": str(turn["content"])})
@@ -55,12 +54,12 @@ def chat_fn(message, history):
55
 
56
  response = ""
57
  try:
58
- # Qwen-72B 专用调用
59
  stream = client.chat_completion(
60
  clean_messages,
61
  max_tokens=4096,
62
  stream=True,
63
- temperature=0.6
64
  )
65
 
66
  for msg in stream:
@@ -71,10 +70,10 @@ def chat_fn(message, history):
71
  yield response
72
 
73
  if response:
74
- yield response + "\n\n---\n> **OpenIPOS MegaNode | Qwen-2.5 全能专业节点**"
75
 
76
  except Exception as e:
77
- yield f"⚠️ 算力调度提示: {str(e)}。由于万亿级模型访问量大,若持续报错请刷新重试。"
78
 
79
  # 3. 统一品牌装修
80
  with gr.Blocks(fill_height=True) as demo:
@@ -88,6 +87,6 @@ with gr.Blocks(fill_height=True) as demo:
88
  </div>
89
  """)
90
  gr.ChatInterface(chat_fn, multimodal=True)
91
- gr.Markdown("© 2026 OpenIPOS Global Limited. 算力驱动:Hugging Face Inference Providers")
92
 
93
  demo.launch(theme=gr.themes.Soft())
 
1
  import os
2
  import gradio as gr
 
3
  import fitz
4
  import docx
5
  from huggingface_hub import InferenceClient
6
 
7
+ # 1. 引擎配置:Qwen-2.5-72B-Instruct (全能稳定版)
8
  model_id = "Qwen/Qwen2.5-72B-Instruct"
9
  hf_token = os.getenv("HF_TOKEN")
10
 
11
  client = InferenceClient(
12
  model=model_id,
13
  token=hf_token,
14
+ # 增加超时时间设置,防止翻译长文时断连
15
  headers={"Authorization": f"Bearer {hf_token}"} if hf_token else None
16
  )
17
 
 
32
  except:
33
  return ""
34
 
35
+ # 注意:这里移除了 @spaces.GPU,因为 API 模式下它反而会因超时导致报错
36
  def chat_fn(message, history):
37
  clean_messages = []
38
+ clean_messages.append({"role": "system", "content": "You are a professional patent and legal translation expert. Provide accurate translations."})
 
39
 
40
  for turn in history:
41
  clean_messages.append({"role": turn["role"], "content": str(turn["content"])})
 
54
 
55
  response = ""
56
  try:
57
+ # 增加流式输出
58
  stream = client.chat_completion(
59
  clean_messages,
60
  max_tokens=4096,
61
  stream=True,
62
+ temperature=0.4
63
  )
64
 
65
  for msg in stream:
 
70
  yield response
71
 
72
  if response:
73
+ yield response + "\n\n---\n> **OpenIPOS MegaNode | Qwen-2.5 专业算力出口**"
74
 
75
  except Exception as e:
76
+ yield f"⚠️ 算力调度提示: {str(e)}。由于翻译长文档耗时较长,请分段进行或刷新重试。"
77
 
78
  # 3. 统一品牌装修
79
  with gr.Blocks(fill_height=True) as demo:
 
87
  </div>
88
  """)
89
  gr.ChatInterface(chat_fn, multimodal=True)
90
+ gr.Markdown("© 2026 OpenIPOS Global Limited. 算力驱动:Novita API Cluster")
91
 
92
  demo.launch(theme=gr.themes.Soft())