Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
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
|
13 |
-
- 'degree':
|
14 |
-
- 'betweenness':
|
15 |
-
- 'closeness':
|
16 |
|
17 |
Returns:
|
18 |
-
str: A formatted string
|
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 |
-
#
|
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 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
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}")
|