mohammadKa143 commited on
Commit
e41a4af
·
verified ·
1 Parent(s): 947e96f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -71
app.py CHANGED
@@ -1,78 +1,33 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
- import datetime
3
- import requests
4
- import pytz
5
- import yaml
6
- from tools.final_answer import FinalAnswerTool
7
 
8
- from Gradio_UI import GradioUI
 
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
- @tool
12
- def search(arg:str)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
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
- @tool
21
- def get_current_time_in_timezone(timezone: str) -> str:
22
- """A tool that fetches the current local time in a specified timezone.
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
- 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,
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
- # GradioUI(agent).launch()
71
 
72
- try:
73
- result = agent.run("what is the weather in aleppo city in syria?") # Or another test message
74
- print("Agent Result:", result)
75
- except Exception as e:
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(...)