Update app.py
Browse files
app.py
CHANGED
|
@@ -4,17 +4,17 @@ import datetime
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
|
| 7 |
-
from smolagents import CodeAgent, DuckDuckGoSearchTool,
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# ——————————————————————————————————————————————
|
| 12 |
-
# 1) Login to
|
| 13 |
# ——————————————————————————————————————————————
|
| 14 |
-
|
| 15 |
-
if not
|
| 16 |
-
raise RuntimeError("
|
| 17 |
-
login(
|
| 18 |
|
| 19 |
# ——————————————————————————————————————————————
|
| 20 |
# 2) Define your custom tools
|
|
@@ -41,19 +41,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
|
| 43 |
# ——————————————————————————————————————————————
|
| 44 |
-
# 3) Load your model via
|
| 45 |
# ——————————————————————————————————————————————
|
| 46 |
-
model =
|
| 47 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 48 |
max_tokens=2096,
|
| 49 |
temperature=0.5,
|
|
|
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
# ——————————————————————————————————————————————
|
| 53 |
# 4) Import additional tools from the Hub
|
| 54 |
# ——————————————————————————————————————————————
|
| 55 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 56 |
-
#
|
| 57 |
|
| 58 |
# ——————————————————————————————————————————————
|
| 59 |
# 5) Load & sanitize your prompt templates
|
|
@@ -61,11 +63,11 @@ image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_co
|
|
| 61 |
with open("prompts.yaml", "r") as f:
|
| 62 |
prompt_templates = yaml.safe_load(f)
|
| 63 |
|
| 64 |
-
# Ensure the required 'final_answer'
|
| 65 |
prompt_templates.setdefault("final_answer", "Final answer:\n{{answer}}")
|
| 66 |
|
| 67 |
# ——————————————————————————————————————————————
|
| 68 |
-
# 6) Instantiate the
|
| 69 |
# ——————————————————————————————————————————————
|
| 70 |
agent = CodeAgent(
|
| 71 |
model=model,
|
|
@@ -74,7 +76,7 @@ agent = CodeAgent(
|
|
| 74 |
my_custom_tool,
|
| 75 |
get_current_time_in_timezone,
|
| 76 |
image_generation_tool,
|
| 77 |
-
#
|
| 78 |
],
|
| 79 |
max_steps=6,
|
| 80 |
verbosity_level=1,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
|
| 7 |
+
from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel, load_tool, tool
|
| 8 |
from tools.final_answer import FinalAnswerTool
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# ——————————————————————————————————————————————
|
| 12 |
+
# 1) Login to Hugging Face using your HF_HUB_TOKEN secret
|
| 13 |
# ——————————————————————————————————————————————
|
| 14 |
+
hf_token = os.getenv("HF_HUB_TOKEN")
|
| 15 |
+
if not hf_token:
|
| 16 |
+
raise RuntimeError("HF_HUB_TOKEN env var not set")
|
| 17 |
+
login(hf_token)
|
| 18 |
|
| 19 |
# ——————————————————————————————————————————————
|
| 20 |
# 2) Define your custom tools
|
|
|
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
|
| 43 |
# ——————————————————————————————————————————————
|
| 44 |
+
# 3) Load your model via InferenceClientModel
|
| 45 |
# ——————————————————————————————————————————————
|
| 46 |
+
model = InferenceClientModel(
|
| 47 |
model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 48 |
max_tokens=2096,
|
| 49 |
temperature=0.5,
|
| 50 |
+
api_key=hf_token, # ensure the model client also sees your token
|
| 51 |
+
provider="huggingface" # bypasses Nebius routing if you prefer
|
| 52 |
)
|
| 53 |
|
| 54 |
# ——————————————————————————————————————————————
|
| 55 |
# 4) Import additional tools from the Hub
|
| 56 |
# ——————————————————————————————————————————————
|
| 57 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 58 |
+
# duck_duck_go = DuckDuckGoSearchTool() # uncomment if you need web search
|
| 59 |
|
| 60 |
# ——————————————————————————————————————————————
|
| 61 |
# 5) Load & sanitize your prompt templates
|
|
|
|
| 63 |
with open("prompts.yaml", "r") as f:
|
| 64 |
prompt_templates = yaml.safe_load(f)
|
| 65 |
|
| 66 |
+
# Ensure the required 'final_answer' template is present
|
| 67 |
prompt_templates.setdefault("final_answer", "Final answer:\n{{answer}}")
|
| 68 |
|
| 69 |
# ——————————————————————————————————————————————
|
| 70 |
+
# 6) Instantiate the CodeAgent
|
| 71 |
# ——————————————————————————————————————————————
|
| 72 |
agent = CodeAgent(
|
| 73 |
model=model,
|
|
|
|
| 76 |
my_custom_tool,
|
| 77 |
get_current_time_in_timezone,
|
| 78 |
image_generation_tool,
|
| 79 |
+
# duck_duck_go,
|
| 80 |
],
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|