Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,8 +62,12 @@ def parse_input(num_nodes, edges_str, node_features_str):
|
|
62 |
# ---------- VISUALIZACIÓN ----------
|
63 |
|
64 |
def draw_graph(G, pred_label):
|
|
|
|
|
|
|
65 |
pos = nx.spring_layout(G)
|
66 |
-
node_colors = 'lightgreen' if pred_label == 1 else 'lightcoral'
|
|
|
67 |
plt.figure(figsize=(4, 4))
|
68 |
nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color='gray', node_size=800)
|
69 |
plt.title("Grafo de entrada")
|
@@ -71,10 +75,9 @@ def draw_graph(G, pred_label):
|
|
71 |
buf = io.BytesIO()
|
72 |
plt.savefig(buf, format='png')
|
73 |
buf.seek(0)
|
74 |
-
img_base64 = base64.b64encode(buf.read()).decode('utf-8')
|
75 |
plt.close()
|
76 |
|
77 |
-
return
|
78 |
|
79 |
# ---------- FUNCIÓN DE PREDICCIÓN ----------
|
80 |
|
@@ -92,8 +95,7 @@ def predict_graph(num_nodes, edges_str, node_features_str):
|
|
92 |
pred = out.argmax(dim=1).item()
|
93 |
|
94 |
label_text = "Mutagénico ✅" if pred == 1 else "No mutagénico ❌"
|
95 |
-
|
96 |
-
return label_text, img
|
97 |
|
98 |
# ---------- INTERFAZ GRADIO ----------
|
99 |
|
|
|
62 |
# ---------- VISUALIZACIÓN ----------
|
63 |
|
64 |
def draw_graph(G, pred_label):
|
65 |
+
import matplotlib.pyplot as plt
|
66 |
+
import io
|
67 |
+
|
68 |
pos = nx.spring_layout(G)
|
69 |
+
node_colors = ['lightgreen' if pred_label == 1 else 'lightcoral'] * G.number_of_nodes()
|
70 |
+
|
71 |
plt.figure(figsize=(4, 4))
|
72 |
nx.draw(G, pos, with_labels=True, node_color=node_colors, edge_color='gray', node_size=800)
|
73 |
plt.title("Grafo de entrada")
|
|
|
75 |
buf = io.BytesIO()
|
76 |
plt.savefig(buf, format='png')
|
77 |
buf.seek(0)
|
|
|
78 |
plt.close()
|
79 |
|
80 |
+
return buf # Devuelve un objeto tipo archivo
|
81 |
|
82 |
# ---------- FUNCIÓN DE PREDICCIÓN ----------
|
83 |
|
|
|
95 |
pred = out.argmax(dim=1).item()
|
96 |
|
97 |
label_text = "Mutagénico ✅" if pred == 1 else "No mutagénico ❌"
|
98 |
+
return label_text, draw_graph(G, pred)
|
|
|
99 |
|
100 |
# ---------- INTERFAZ GRADIO ----------
|
101 |
|