Update app.py
Browse files
app.py
CHANGED
@@ -53,36 +53,76 @@ def cargar_desde_airtable():
|
|
53 |
if response.status_code != 200:
|
54 |
print(f"Error: {response.status_code} - {response.text}")
|
55 |
return pd.DataFrame(columns=["Nombre", "Conceptos"])
|
|
|
56 |
records = response.json().get("records", [])
|
57 |
-
aportes = [
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
def inicializar_grafo():
|
64 |
df = cargar_desde_airtable()
|
|
|
65 |
for _, row in df.iterrows():
|
66 |
-
nombre
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
if not G.has_node(termino):
|
69 |
G.add_node(termino, color='gray')
|
70 |
if not G.has_edge(nombre, termino):
|
71 |
G.add_edge(nombre, termino)
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
requests.post(url, headers=headers, json=data)
|
76 |
|
77 |
-
def
|
78 |
-
|
79 |
-
|
|
|
80 |
for termino in conceptos.split():
|
81 |
if not G.has_node(termino):
|
82 |
G.add_node(termino, color='gray')
|
83 |
if not G.has_edge(nombre, termino):
|
84 |
G.add_edge(nombre, termino)
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
guardar_en_airtable(nombre, conceptos)
|
87 |
return visualizar_grafo()
|
88 |
|
|
|
53 |
if response.status_code != 200:
|
54 |
print(f"Error: {response.status_code} - {response.text}")
|
55 |
return pd.DataFrame(columns=["Nombre", "Conceptos"])
|
56 |
+
|
57 |
records = response.json().get("records", [])
|
58 |
+
aportes = []
|
59 |
+
|
60 |
+
for record in records:
|
61 |
+
nombre = record["fields"].get("Nombre", "").strip()
|
62 |
+
conceptos = record["fields"].get("Conceptos", "").strip()
|
63 |
+
aportes.append([nombre, conceptos])
|
64 |
+
|
65 |
+
df = pd.DataFrame(aportes, columns=["Nombre", "Conceptos"])
|
66 |
+
|
67 |
+
print("Loaded Airtable Data:")
|
68 |
+
print(df) # 🔍 Debugging: Print the loaded data
|
69 |
+
return df
|
70 |
|
71 |
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 not G.has_node(termino):
|
87 |
G.add_node(termino, color='gray')
|
88 |
if not G.has_edge(nombre, termino):
|
89 |
G.add_edge(nombre, termino)
|
90 |
|
91 |
+
print("Graph Initialized with Nodes:", G.nodes()) # 🔍 Debugging: Print nodes
|
92 |
+
print("Graph Initialized with Edges:", G.edges()) # 🔍 Debugging: Print edges
|
|
|
93 |
|
94 |
+
def inicializar_grafo():
|
95 |
+
df = cargar_desde_airtable()
|
96 |
+
for _, row in df.iterrows():
|
97 |
+
nombre, conceptos = row["Nombre"], row["Conceptos"]
|
98 |
for termino in conceptos.split():
|
99 |
if not G.has_node(termino):
|
100 |
G.add_node(termino, color='gray')
|
101 |
if not G.has_edge(nombre, termino):
|
102 |
G.add_edge(nombre, termino)
|
103 |
|
104 |
+
def guardar_en_airtable(nombre, conceptos):
|
105 |
+
if isinstance(conceptos, str):
|
106 |
+
conceptos = [c.strip() for c in conceptos.split(',') if c.strip()] # Ensure it's a list
|
107 |
+
data = {"fields": {"Nombre": nombre, "Conceptos": ", ".join(conceptos)}}
|
108 |
+
response = requests.post(url, headers=headers, json=data)
|
109 |
+
if response.status_code != 200:
|
110 |
+
print(f"Error saving to Airtable: {response.status_code} - {response.text}")
|
111 |
+
|
112 |
+
def agregar_aporte(nombre, texto):
|
113 |
+
conceptos = extract_concepts(texto) # ✅ Extract concepts dynamically
|
114 |
+
print(f"Extracted Concepts: {conceptos}") # 🔍 Debugging
|
115 |
+
|
116 |
+
if not G.has_node(nombre):
|
117 |
+
G.add_node(nombre, color='gray')
|
118 |
+
|
119 |
+
for termino in conceptos:
|
120 |
+
termino = termino.strip()
|
121 |
+
if not G.has_node(termino):
|
122 |
+
G.add_node(termino, color='gray')
|
123 |
+
if not G.has_edge(nombre, termino):
|
124 |
+
G.add_edge(nombre, termino)
|
125 |
+
|
126 |
guardar_en_airtable(nombre, conceptos)
|
127 |
return visualizar_grafo()
|
128 |
|