InnaV commited on
Commit
de6aef8
·
verified ·
1 Parent(s): cbf9978

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -41
app.py CHANGED
@@ -1,60 +1,49 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
 
 
 
2
  import yaml
3
  from tools.final_answer import FinalAnswerTool
4
- from bertopic import BERTopic
5
- from Gradio_UI import GradioUI
6
 
7
- # Load BERTopic model
8
- topic_model = BERTopic.load("MaartenGr/BERTopic_ArXiv")
9
 
10
- @tool
11
- def my_custom_tool(arg1: str) -> str:
12
- """
13
- Processes input text and returns a modified version.
14
 
 
 
 
15
  Args:
16
- arg1 (str): The input text to process.
17
-
18
- Returns:
19
- str: The processed text output.
20
  """
21
- return f"Processed text: {arg1}"
22
 
23
- @tool
24
- def extract_main_topic(arg1: str) -> str:
25
- """
26
- Extracts the main topic from a given text using BERTopic.
27
 
 
 
28
  Args:
29
- arg1 (str): The input text to analyze.
30
-
31
- Returns:
32
- str: The extracted main topic.
33
  """
34
- topics, probs = topic_model.transform([arg1])
35
- topic_id = topics[0]
 
 
 
 
 
 
36
 
37
- if topic_id == -1: # BERTopic assigns -1 to noise (no topic detected)
38
- return "No clear topic detected."
39
-
40
- topic_words = topic_model.get_topic(topic_id)
41
-
42
- if topic_words:
43
- keywords = ", ".join([word for word, _ in topic_words])
44
- return f"Main Topic Keywords: {keywords}"
45
- else:
46
- return "No topic detected."
47
 
48
  final_answer = FinalAnswerTool()
49
-
50
  model = HfApiModel(
51
- max_tokens=2096,
52
- temperature=0.5,
53
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # This model may be overloaded
54
- custom_role_conversions=None,
55
  )
56
 
57
- # Import tool from Hugging Face
 
58
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
59
 
60
  with open("prompts.yaml", 'r') as stream:
@@ -62,7 +51,7 @@ with open("prompts.yaml", 'r') as stream:
62
 
63
  agent = CodeAgent(
64
  model=model,
65
- tools=[final_answer, my_custom_tool, extract_main_topic], # Added extract_main_topic
66
  max_steps=6,
67
  verbosity_level=1,
68
  grammar=None,
@@ -72,4 +61,5 @@ agent = CodeAgent(
72
  prompt_templates=prompt_templates
73
  )
74
 
 
75
  GradioUI(agent).launch()
 
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
 
12
+ def my_custom_tool(arg1:str, arg2:int)-> str: # it's important to specify the return type
13
+ # Keep this format for the tool description / args description but feel free to modify the tool
14
+ """A tool that does nothing yet
15
  Args:
16
+ arg1: the first argument
17
+ arg2: the second argument
 
 
18
  """
19
+ return "What magic will you build ?"
20
 
 
 
 
 
21
 
22
+ def get_current_time_in_timezone(timezone: str) -> str:
23
+ """A tool that fetches the current local time in a specified timezone.
24
  Args:
25
+ timezone: A string representing a valid timezone (e.g., 'America/New_York').
 
 
 
26
  """
27
+ try:
28
+ # Create timezone object
29
+ tz = pytz.timezone(timezone)
30
+ # Get current time in that timezone
31
+ local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
32
+ return f"The current local time in {timezone} is: {local_time}"
33
+ except Exception as e:
34
+ return f"Error fetching time for timezone '{timezone}': {str(e)}"
35
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  final_answer = FinalAnswerTool()
 
38
  model = HfApiModel(
39
+ max_tokens=2096,
40
+ temperature=0.5,
41
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
42
+ custom_role_conversions=None,
43
  )
44
 
45
+
46
+ # Import tool from Hub
47
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
48
 
49
  with open("prompts.yaml", 'r') as stream:
 
51
 
52
  agent = CodeAgent(
53
  model=model,
54
+ tools=[final_answer], # add your tools here (don't remove final_answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,
 
61
  prompt_templates=prompt_templates
62
  )
63
 
64
+
65
  GradioUI(agent).launch()