CoolFace
Apppublic

awacke1/Self-Modifying-Graph-Visualization

sourceHugging Facemitupdated 4y agoView on Hugging Face
1likes
app.py85 linesDownload Raw Back to root
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