awacke1/Self-Modifying-Graph-Visualization
1
1import streamlit as st2from graphviz import Digraph3import time4import random5 6# Define the emoji to use for the swim lanes7SWIM_LANES = {8 "Data Pipelines": "๐",9 "Build and Train Models": "๐งช",10 "Deploy and Predict": "๐"11}12 13# Define the graph structure14graph = Digraph()15graph.attr(rankdir="TB") # Top to Bottom or LR Left to Right16graph.attr(fontsize="20")17graph.attr(compound="true")18graph.attr(nodesep="0.5")19 20# Define the nodes21nodes = [22 "๐ Data Collection",23 "๐งน Data Cleaning",24 "๐ง Data Transformation",25 "๐ Feature Engineering",26 "โ๏ธ Model Selection",27 "๐ Model Training",28 "๐ข Model Deployment",29 "๐ก Model Serving",30 "๐ฎ Predictions",31 "๐ Feedback Collection",32 "๐ค Feedback Processing",33 "โ๏ธ Model Updating"34]35 36for node in nodes:37 graph.node(node)38 39# Add the swim lanes40with graph.subgraph(name="cluster_0") as c:41 c.attr(rank="1")42 c.attr(label=SWIM_LANES["Data Pipelines"])43 c.edge("๐ Data Collection", "๐งน Data Cleaning", style="invis")44 c.edge("๐งน Data Cleaning", "๐ง Data Transformation", style="invis")45 46with graph.subgraph(name="cluster_1") as c:47 c.attr(rank="2")48 c.attr(label=SWIM_LANES["Build and Train Models"])49 c.edge("๐ Feature Engineering", "โ๏ธ Model Selection", style="invis")50 c.edge("โ๏ธ Model Selection", "๐ Model Training", style="invis")51 52with graph.subgraph(name="cluster_2") as c:53 c.attr(rank="3")54 c.attr(label=SWIM_LANES["Deploy and Predict"])55 c.edge("๐ข Model Deployment", "๐ก Model Serving", style="invis")56 c.edge("๐ก Model Serving", "๐ฎ Predictions", style="invis")57 58with graph.subgraph(name="cluster_3") as c:59 c.attr(rank="4")60 c.attr(label="Reinforcement Learning Human Feedback")61 c.edge("๐ฎ Predictions", "๐ Feedback Collection", style="invis")62 c.edge("๐ Feedback Collection", "๐ค Feedback Processing", style="invis")63 c.edge("๐ค Feedback Processing", "โ๏ธ Model Updating", style="invis")64 65def render_graph():66 st.graphviz_chart(graph.source)67 68def update_graph():69 for i in range(10):70 # Randomly select two nodes and add an edge between them71 node1, node2 = random.sample(nodes, 2)72 graph.edge(node1, node2)73 74 # Render the updated graph75 render_graph()76 77 # Wait for 1 second78 time.sleep(1)79 80# Render the initial graph81render_graph()82 83# Update the graph every second for 60 seconds84update_graph()85 