JoseferEins commited on
Commit
66bf097
·
verified ·
1 Parent(s): ff2a1ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -20
app.py CHANGED
@@ -8,24 +8,6 @@ import matplotlib.pyplot as plt
8
  import numpy as np
9
  from Gradio_UI import GradioUI
10
 
11
- @tool
12
- def plot_omocentric_circles(distance: float, n: int)-> None:
13
- """A tool that plots n omocentric circles with a given seed distance, each in a different color.
14
- Args:
15
- distance: Distance between consecutive circles.
16
- n: Number of circles to plot.
17
- """
18
- fig, ax = plt.subplots()
19
- ax.set_aspect('equal')
20
-
21
- colors = plt.cm.viridis(np.linspace(0, 1, n)) # Generate n distinct colors
22
-
23
- for i in range(n):
24
- ax.add_patch(plt.Circle((0, 0), (i + 1) * seed, fill=False, color=colors[i]))
25
-
26
- plt.xlim(-n * seed, n * seed)
27
- plt.ylim(-n * seed, n * seed)
28
- plt.show()
29
 
30
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
31
  @tool
@@ -54,12 +36,57 @@ def get_current_time_in_timezone(timezone: str) -> str:
54
  except Exception as e:
55
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  final_answer = FinalAnswerTool()
59
  model = HfApiModel(
60
  max_tokens=2096,
61
  temperature=0.5,
62
- model_id='deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',# it is possible that this model may be overloaded
63
  custom_role_conversions=None,
64
  )
65
 
@@ -72,7 +99,14 @@ with open("prompts.yaml", 'r') as stream:
72
 
73
  agent = CodeAgent(
74
  model=model,
75
- tools=[final_answer, DuckDuckGoSearchTool(), image_generation_tool, plot_omocentric_circles], ## add your tools here (don't remove final answer)
 
 
 
 
 
 
 
76
  max_steps=6,
77
  verbosity_level=1,
78
  grammar=None,
 
8
  import numpy as np
9
  from Gradio_UI import GradioUI
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
 
36
  except Exception as e:
37
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
 
39
+ #########################################################################
40
+ # NEW TOOL: GET CULTURAL INFO (via Wikipedia)
41
+ #########################################################################
42
+ @tool
43
+ def get_cultural_info(topic: str) -> str:
44
+ """
45
+ A tool that retrieves cultural or general info from Wikipedia for a given topic.
46
+ Args:
47
+ topic: A string representing the subject to lookup (e.g., 'Renaissance art').
48
+ Returns:
49
+ A short summary text from Wikipedia for the specified topic.
50
+ """
51
+ try:
52
+ # Query the Wikipedia API for an extract
53
+ # Using the "summary" approach with 'exintro' to get the first paragraph
54
+ url = (
55
+ "https://en.wikipedia.org/w/api.php?"
56
+ "action=query&prop=extracts&exintro&explaintext&format=json&titles=" + topic
57
+ )
58
+ response = requests.get(url)
59
+ data = response.json()
60
+
61
+ # Extract the page data
62
+ pages = data.get("query", {}).get("pages", {})
63
+ if not pages:
64
+ return f"No Wikipedia pages found for topic: {topic}"
65
+
66
+ # Wikipedia returns a dictionary keyed by page ID
67
+ page_id = next(iter(pages))
68
+ page_content = pages[page_id]
69
+
70
+ # Check for missing page or missing extract
71
+ if "missing" in page_content:
72
+ return f"No page found on Wikipedia for topic: {topic}"
73
+
74
+ extract = page_content.get("extract", "")
75
+ if not extract:
76
+ return f"No extract available for '{topic}'."
77
+
78
+ return extract.strip()
79
+
80
+ except Exception as e:
81
+ return f"Error retrieving cultural info for '{topic}': {str(e)}"
82
+ #########################################################################
83
+
84
 
85
  final_answer = FinalAnswerTool()
86
  model = HfApiModel(
87
  max_tokens=2096,
88
  temperature=0.5,
89
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
90
  custom_role_conversions=None,
91
  )
92
 
 
99
 
100
  agent = CodeAgent(
101
  model=model,
102
+ tools=[
103
+ final_answer,
104
+ DuckDuckGoSearchTool(),
105
+ VisitWebpageTool(),
106
+ get_current_time_in_timezone,
107
+ get_cultural_info, # <-- Our new cultural info tool
108
+ image_generation_tool
109
+ ],
110
  max_steps=6,
111
  verbosity_level=1,
112
  grammar=None,