Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,78 +1,33 @@
|
|
1 |
-
|
2 |
-
import
|
3 |
-
import
|
4 |
-
import pytz
|
5 |
-
import yaml
|
6 |
-
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
"""A tool that searches on the web and return the results
|
15 |
-
Args:
|
16 |
-
arg: the topic to search about
|
17 |
-
"""
|
18 |
-
return DuckDuckGoSearchTool(arg)
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
"
|
23 |
-
Args:
|
24 |
-
timezone: A string representing a valid timezone (e.g., 'America/New_York').
|
25 |
-
"""
|
26 |
-
try:
|
27 |
-
# Create timezone object
|
28 |
-
tz = pytz.timezone(timezone)
|
29 |
-
# Get current time in that timezone
|
30 |
-
local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
|
31 |
-
return f"The current local time in {timezone} is: {local_time}"
|
32 |
-
except Exception as e:
|
33 |
-
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
34 |
-
|
35 |
-
search_tool = DuckDuckGoSearchTool()
|
36 |
-
final_answer = FinalAnswerTool()
|
37 |
-
|
38 |
-
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
39 |
-
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
40 |
-
|
41 |
-
model = HfApiModel(
|
42 |
-
max_tokens=2096,
|
43 |
-
temperature=0.5,
|
44 |
-
model_id='mistralai/Mistral-7B-Instruct-v0.2',# it is possible that this model may be overloaded
|
45 |
-
custom_role_conversions=None,
|
46 |
-
)
|
47 |
-
|
48 |
-
|
49 |
-
# Import tool from Hub
|
50 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
get_current_time_in_timezone,
|
59 |
-
search_tool], ## add your tools here (don't remove final answer)
|
60 |
-
max_steps=6,
|
61 |
-
verbosity_level=1,
|
62 |
-
grammar=None,
|
63 |
-
planning_interval=None,
|
64 |
-
name=None,
|
65 |
-
description=None,
|
66 |
-
prompt_templates=prompt_templates
|
67 |
-
)
|
68 |
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
print("An error occurred during agent run:", e)
|
77 |
-
import traceback
|
78 |
-
traceback.print_exc() # <--- This will print the full error
|
|
|
1 |
+
import os
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
+
import traceback
|
|
|
|
|
|
|
4 |
|
5 |
+
print("--- Starting Direct HF Hub Test ---")
|
6 |
+
token = os.environ.get("HF_TOKEN")
|
7 |
|
8 |
+
if token:
|
9 |
+
print("HF_TOKEN secret FOUND.")
|
10 |
+
else:
|
11 |
+
print("!!! HF_TOKEN secret IS *NOT* SET! !!!")
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
try:
|
14 |
+
client = InferenceClient(token=token)
|
15 |
+
print("InferenceClient initialized.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
response = client.chat_completion(
|
18 |
+
messages=[{"role": "user", "content": "Hello!"}],
|
19 |
+
model="mistralai/Mistral-7B-Instruct-v0.2",
|
20 |
+
max_tokens=10,
|
21 |
+
)
|
22 |
+
print("Direct client test SUCCESS:", response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
except Exception as e:
|
25 |
+
print("Direct client test FAILED:")
|
26 |
+
traceback.print_exc() # <--- This will print the full error
|
27 |
|
28 |
+
print("--- Finished Direct HF Hub Test ---")
|
29 |
|
30 |
+
# --- Comment out the rest of your code for this test ---
|
31 |
+
# from smolagents import CodeAgent, HfApiModel # etc...
|
32 |
+
# agent = CodeAgent(...)
|
33 |
+
# agent.run(...)
|
|
|
|
|
|