dwb2023 commited on
Commit
ff00b17
·
verified ·
1 Parent(s): db88c4e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -1,21 +1,24 @@
 
 
 
1
  import networkx as nx
2
  from smolagents import CodeAgent, HfApiModel, tool
3
  import gradio as gr
4
 
5
- # Define a tool for analyzing the Florentine Families graph
6
  @tool
7
  def analyze_florentine_graph(metric: str) -> str:
8
  """
9
  Analyze the Florentine Families graph using a specified centrality metric.
10
 
11
  Args:
12
- metric (str): The name of the centrality metric to calculate. Supported values are:
13
- - 'degree': Calculate degree centrality for each node.
14
- - 'betweenness': Calculate betweenness centrality for each node.
15
- - 'closeness': Calculate closeness centrality for each node.
16
 
17
  Returns:
18
- str: A formatted string displaying the centrality values for each node in the graph.
19
  """
20
  # Load the Florentine Families graph
21
  graph = nx.florentine_families_graph()
@@ -36,7 +39,7 @@ def analyze_florentine_graph(metric: str) -> str:
36
 
37
  return analysis
38
 
39
- # Create the CodeAgent
40
  class FlorentineGraphAgentUI:
41
  def __init__(self):
42
  self.model = HfApiModel("meta-llama/Llama-3.3-70B-Instruct")
@@ -73,7 +76,11 @@ class FlorentineGraphAgentUI:
73
  )
74
  interface.launch()
75
 
76
- if __name__ == "__main__":
77
- # Initialize and launch the app
78
- app = FlorentineGraphAgentUI()
79
- app.launch()
 
 
 
 
 
1
+ # Validate the updated code by checking for syntax and logical errors
2
+
3
+ # Importing necessary modules for testing
4
  import networkx as nx
5
  from smolagents import CodeAgent, HfApiModel, tool
6
  import gradio as gr
7
 
8
+ # Test tool definition
9
  @tool
10
  def analyze_florentine_graph(metric: str) -> str:
11
  """
12
  Analyze the Florentine Families graph using a specified centrality metric.
13
 
14
  Args:
15
+ metric (str): The centrality metric to calculate. Supported values are:
16
+ - 'degree': Degree centrality
17
+ - 'betweenness': Betweenness centrality
18
+ - 'closeness': Closeness centrality
19
 
20
  Returns:
21
+ str: A formatted string showing the centrality values for each node in the graph.
22
  """
23
  # Load the Florentine Families graph
24
  graph = nx.florentine_families_graph()
 
39
 
40
  return analysis
41
 
42
+ # Test Agent Class
43
  class FlorentineGraphAgentUI:
44
  def __init__(self):
45
  self.model = HfApiModel("meta-llama/Llama-3.3-70B-Instruct")
 
76
  )
77
  interface.launch()
78
 
79
+ # Instance of the app to simulate the behavior
80
+ app = FlorentineGraphAgentUI()
81
+
82
+ # Simulate a query
83
+ try:
84
+ print(app.process_query("Analyze degree centrality"))
85
+ except Exception as e:
86
+ print(f"Error during execution: {e}")