Files changed (1) hide show
  1. app.py +58 -14
app.py CHANGED
@@ -3,20 +3,66 @@ 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 my_custom_tool(arg1:str, arg2:int)-> 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 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
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,14 +101,12 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
- max_steps=6,
60
- verbosity_level=1,
61
- grammar=None,
62
- planning_interval=None,
63
- name=None,
64
- description=None,
65
- prompt_templates=prompt_templates
66
  )
67
 
68
 
 
3
  import requests
4
  import pytz
5
  import yaml
6
+ import os
7
+ import matplotlib.pyplot as plt
8
+ import networkx as nx
9
  from tools.final_answer import FinalAnswerTool
10
 
11
  from Gradio_UI import GradioUI
12
 
13
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
14
  @tool
15
+ def text_to_graph_tool(relationships: str) -> str:
16
+ """Generates a directed network graph image from relationships.
17
+
18
  Args:
19
+ relationships: Semicolon-separated edges like 'User -> WebServer: Requests; WebServer -> Database: Queries'
 
20
  """
21
+ try:
22
+ plt.figure(figsize=(9, 6))
23
+ G = nx.DiGraph()
24
+
25
+ lines = [r.strip() for r in relationships.replace("\n", ";").split(";") if r.strip()]
26
+ edge_labels = {}
27
+
28
+ for entry in lines:
29
+ if "->" in entry:
30
+ parts = entry.split("->")
31
+ source = parts[0].strip()
32
+ remainder = parts[1].strip()
33
+
34
+ if ":" in remainder:
35
+ target, label = remainder.split(":", 1)
36
+ target, label = target.strip(), label.strip()
37
+ else:
38
+ target, label = remainder, ""
39
+
40
+ G.add_edge(source, target)
41
+ if label:
42
+ edge_labels[(source, target)] = label
43
+
44
+ if len(G.nodes) == 0:
45
+ return "No valid relationships found. Use format: 'NodeA -> NodeB: Label'"
46
+
47
+ pos = nx.spring_layout(G, k=1.0, seed=42)
48
+ nx.draw_networkx_nodes(G, pos, node_size=2800, node_color="#4F46E5", alpha=0.9)
49
+ nx.draw_networkx_edges(G, pos, arrowstyle="->", arrowsize=18, edge_color="#64748B", width=2.0)
50
+ nx.draw_networkx_labels(G, pos, font_size=9, font_color="white", font_weight="bold")
51
+
52
+ if edge_labels:
53
+ nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8, font_color="#DC2626")
54
+
55
+ plt.axis("off")
56
+ plt.tight_layout()
57
+
58
+ os.makedirs("generated_graphs", exist_ok=True)
59
+ file_path = f"generated_graphs/graph_{int(datetime.datetime.now().timestamp())}.png"
60
+ plt.savefig(file_path, dpi=200, bbox_inches="tight")
61
+ plt.close()
62
+
63
+ return f"Graph successfully created and saved at: {file_path}"
64
+ except Exception as e:
65
+ return f"Error generating graph: {str(e)}"
66
 
67
  @tool
68
  def get_current_time_in_timezone(timezone: str) -> str:
 
101
 
102
  agent = CodeAgent(
103
  model=model,
104
+ tools=[
105
+ final_answer,
106
+ text_to_graph_tool,
107
+ image_generation_tool,
108
+ get_current_time_in_timezone
109
+ ],
 
 
110
  )
111
 
112