stevengu9999 commited on
Commit
113183f
·
verified ·
1 Parent(s): d9a862c

Update app.py

Browse files

路线 A(推荐,最简单,课程学习优先):**移除文生图工具,不再需要 GPU,直接去掉`@spaces.GPU`**
因为:`Qwen/Qwen2.5-Coder-32B-Instruct` 是 HF 云端 API,**完全不需要你的 Space 本地 GPU**;只有`text-to-image`工具才占用 ZeroGPU。删掉这个工具,就不需要 ZeroGPU,所有`@spaces.GPU`全部删掉,不会再有 worker 报错。

Files changed (1) hide show
  1. app.py +5 -18
app.py CHANGED
@@ -4,7 +4,6 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
- import spaces
8
 
9
  from Gradio_UI import GradioUI
10
 
@@ -47,17 +46,15 @@ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may
47
  custom_role_conversions=None,
48
  )
49
 
50
-
51
- # Import tool from Hub
52
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
53
 
54
  with open("prompts.yaml", 'r') as stream:
55
  prompt_templates = yaml.safe_load(stream)
56
 
57
-
58
  agent = CodeAgent(
59
  model=model,
60
- tools=[final_answer, my_custom_tool, get_current_time_in_timezone, image_generation_tool], ## add your tools here (don't remove final answer)
61
  max_steps=6,
62
  verbosity_level=1,
63
  grammar=None,
@@ -67,15 +64,5 @@ agent = CodeAgent(
67
  prompt_templates=prompt_templates
68
  )
69
 
70
- # ====================== 【核心修复】======================
71
- # 不要修改agent.run!我们新建带GPU装饰器的入口函数
72
- @spaces.GPU
73
- def run_agent_query(user_input):
74
- return agent.run(user_input)
75
-
76
- # 覆盖GradioUI内部的submit函数,调用我们带@spaces.GPU的包装函数
77
- ui = GradioUI(agent)
78
- # 替换ui内部的predict函数
79
- ui.predict = run_agent_query
80
-
81
- ui.launch()
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
46
  custom_role_conversions=None,
47
  )
48
 
49
+ # ========= 删掉文生图工具,不再需要GPU =========
50
+ # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
51
 
52
  with open("prompts.yaml", 'r') as stream:
53
  prompt_templates = yaml.safe_load(stream)
54
 
 
55
  agent = CodeAgent(
56
  model=model,
57
+ tools=[final_answer, my_custom_tool, get_current_time_in_timezone], # 移除image_generation_tool
58
  max_steps=6,
59
  verbosity_level=1,
60
  grammar=None,
 
64
  prompt_templates=prompt_templates
65
  )
66
 
67
+ # 完全删除import spaces、@spaces.GPU相关全部代码!
68
+ GradioUI(agent).launch()