Update app.py
Browse files
app.py
CHANGED
@@ -72,27 +72,34 @@ def inicializar_grafo():
|
|
72 |
df = cargar_desde_airtable()
|
73 |
|
74 |
for _, row in df.iterrows():
|
75 |
-
nombre = row["Nombre"]
|
76 |
-
conceptos = row["Conceptos"]
|
77 |
-
|
78 |
if not nombre or not conceptos:
|
79 |
continue # Skip empty rows
|
80 |
-
|
|
|
81 |
if not G.has_node(nombre):
|
82 |
G.add_node(nombre, color='gray')
|
83 |
-
|
84 |
-
for termino in conceptos.split(','):
|
85 |
termino = termino.strip()
|
86 |
-
if
|
87 |
-
G.
|
88 |
-
|
89 |
-
G.
|
90 |
-
|
91 |
-
|
92 |
-
print("Graph
|
|
|
93 |
|
94 |
def visualizar_grafo():
|
95 |
plt.figure(figsize=(10, 6))
|
|
|
|
|
|
|
|
|
|
|
96 |
pos = nx.spring_layout(G)
|
97 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
98 |
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray', node_size=2000, font_size=10)
|
@@ -100,6 +107,7 @@ def visualizar_grafo():
|
|
100 |
plt.title("Red de Aportes")
|
101 |
plt.savefig("graph.png")
|
102 |
plt.close()
|
|
|
103 |
return "graph.png"
|
104 |
|
105 |
def guardar_en_airtable(nombre, conceptos):
|
|
|
72 |
df = cargar_desde_airtable()
|
73 |
|
74 |
for _, row in df.iterrows():
|
75 |
+
nombre = row["Nombre"].strip()
|
76 |
+
conceptos = row["Conceptos"].strip()
|
77 |
+
|
78 |
if not nombre or not conceptos:
|
79 |
continue # Skip empty rows
|
80 |
+
|
81 |
+
# ✅ Ensure name is added as a node first
|
82 |
if not G.has_node(nombre):
|
83 |
G.add_node(nombre, color='gray')
|
84 |
+
|
85 |
+
for termino in conceptos.split(','):
|
86 |
termino = termino.strip()
|
87 |
+
if termino: # ✅ Fix empty terms issue
|
88 |
+
if not G.has_node(termino):
|
89 |
+
G.add_node(termino, color='gray')
|
90 |
+
if not G.has_edge(nombre, termino):
|
91 |
+
G.add_edge(nombre, termino)
|
92 |
+
|
93 |
+
print("✅ Graph Nodes:", list(G.nodes))
|
94 |
+
print("✅ Graph Edges:", list(G.edges))
|
95 |
|
96 |
def visualizar_grafo():
|
97 |
plt.figure(figsize=(10, 6))
|
98 |
+
|
99 |
+
if len(G.nodes) == 0:
|
100 |
+
print("⚠️ Warning: The graph is empty! Check if data was loaded correctly.")
|
101 |
+
plt.text(0.5, 0.5, "No data available", fontsize=12, ha='center')
|
102 |
+
|
103 |
pos = nx.spring_layout(G)
|
104 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
105 |
nx.draw(G, pos, with_labels=True, node_color='lightblue', edge_color='gray', node_size=2000, font_size=10)
|
|
|
107 |
plt.title("Red de Aportes")
|
108 |
plt.savefig("graph.png")
|
109 |
plt.close()
|
110 |
+
|
111 |
return "graph.png"
|
112 |
|
113 |
def guardar_en_airtable(nombre, conceptos):
|