Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import networkx as nx | |
| import matplotlib.pyplot as plt | |
| def draw_network(): | |
| # --- Construir el grafo --- | |
| G = nx.DiGraph() | |
| G.add_node("Cafeína") | |
| G.add_node("Memoria corto plazo") | |
| G.add_node("Memoria largo plazo") | |
| G.add_node("Sueño") | |
| G.add_node("Dosis moderada") | |
| G.add_node("Dosis alta") | |
| G.add_edge("Cafeína", "Memoria corto plazo") | |
| G.add_edge("Cafeína", "Memoria largo plazo") | |
| G.add_edge("Dosis alta", "Sueño") | |
| G.add_edge("Sueño", "Memoria largo plazo") | |
| # --- Dibujar con Matplotlib --- | |
| fig, ax = plt.subplots(figsize=(8, 6)) | |
| pos = nx.spring_layout(G, k=5, seed=42) | |
| nx.draw( | |
| G, pos, ax=ax, with_labels=True, | |
| node_size=1500, node_color="lightblue", | |
| font_size=10, font_weight="bold", | |
| arrowsize=20, edge_color="gray" | |
| ) | |
| plt.margins(0.2) | |
| plt.tight_layout() | |
| return fig | |
| # --- Interfaz con Gradio --- | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## ☕ Grafo: Cafeína y memoria") | |
| plot = gr.Plot() | |
| btn = gr.Button("Dibujar grafo") | |
| btn.click(draw_network, outputs=plot) | |
| if __name__ == "__main__": | |
| demo.launch() | |