Spaces:
Sleeping
Sleeping
Hanson commited on
Commit ·
8cc83e2
1
Parent(s): 204a2e7
fix: add @spaces.GPU decorator for Zero GPU environment
Browse files
app.py
CHANGED
|
@@ -11,18 +11,22 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
|
|
|
|
|
|
| 14 |
|
| 15 |
class BasicAgent:
|
| 16 |
-
def __init__(self):
|
| 17 |
hf_token = os.getenv("HF_TOKEN")
|
| 18 |
|
| 19 |
self.model = LiteLLMModel(
|
| 20 |
model_id="huggingface/Qwen/Qwen2.5-72B-Instruct",
|
| 21 |
-
token=hf_token
|
| 22 |
)
|
| 23 |
self.search_tool = DuckDuckGoSearchTool()
|
| 24 |
self.agent = CodeAgent(tools=[self.search_tool], model=self.model)
|
| 25 |
|
|
|
|
|
|
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
try:
|
| 28 |
return str(self.agent.run(question))
|
|
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool
|
| 14 |
+
import os
|
| 15 |
+
import spaces # 💡 1. 引入 Hugging Face 的 GPU 空間套件
|
| 16 |
|
| 17 |
class BasicAgent:
|
| 18 |
+
def __init__(self):
|
| 19 |
hf_token = os.getenv("HF_TOKEN")
|
| 20 |
|
| 21 |
self.model = LiteLLMModel(
|
| 22 |
model_id="huggingface/Qwen/Qwen2.5-72B-Instruct",
|
| 23 |
+
token=hf_token
|
| 24 |
)
|
| 25 |
self.search_tool = DuckDuckGoSearchTool()
|
| 26 |
self.agent = CodeAgent(tools=[self.search_tool], model=self.model)
|
| 27 |
|
| 28 |
+
# 💡 2. 在實際執行的函式上方加上這個裝飾器,滿足 Zero GPU 的啟動檢查
|
| 29 |
+
@spaces.GPU
|
| 30 |
def __call__(self, question: str) -> str:
|
| 31 |
try:
|
| 32 |
return str(self.agent.run(question))
|