Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import networkx as nx
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import uuid
|
| 5 |
+
|
| 6 |
+
# Diccionario para almacenar los aportes y sus conexiones
|
| 7 |
+
aportes = {}
|
| 8 |
+
graph = nx.Graph()
|
| 9 |
+
|
| 10 |
+
def agregar_aporte(texto):
|
| 11 |
+
global aportes, graph
|
| 12 |
+
|
| 13 |
+
# Crear un identificador 煤nico para el aporte
|
| 14 |
+
node_id = str(uuid.uuid4())[:8]
|
| 15 |
+
aportes[node_id] = texto
|
| 16 |
+
graph.add_node(node_id, label=texto)
|
| 17 |
+
|
| 18 |
+
# L贸gica de conexi贸n entre nodos (por ahora, conecta con el 煤ltimo aporte)
|
| 19 |
+
if len(aportes) > 1:
|
| 20 |
+
prev_node = list(aportes.keys())[-2] # 脷ltimo nodo agregado
|
| 21 |
+
graph.add_edge(prev_node, node_id)
|
| 22 |
+
|
| 23 |
+
return visualizar_grafo()
|
| 24 |
+
|
| 25 |
+
def visualizar_grafo():
|
| 26 |
+
plt.figure(figsize=(8, 6))
|
| 27 |
+
pos = nx.spring_layout(graph)
|
| 28 |
+
labels = nx.get_node_attributes(graph, 'label')
|
| 29 |
+
nx.draw(graph, pos, with_labels=True, labels=labels, node_color='lightblue', edge_color='gray', node_size=2000, font_size=10)
|
| 30 |
+
plt.title("Red de Aportes")
|
| 31 |
+
plt.savefig("graph.png")
|
| 32 |
+
plt.close()
|
| 33 |
+
return "graph.png"
|
| 34 |
+
|
| 35 |
+
iface = gr.Interface(fn=agregar_aporte, inputs="text", outputs="image", title="Foro Din谩mico con Visualizaci贸n de Red")
|
| 36 |
+
iface.launch()
|