Skip to content

Commit

Permalink
Plot processing graph (#1132)
Browse files Browse the repository at this point in the history
* add processing graph drawing

* add requirements

* add system dependency (graphviz)

* install libcommons from path (for local app version only)

* update gradio (to fix plots size displaying)

* update readme: add yaml with updated python and gradio versions

* update poetry.lock

* update python env files

* update graph creation according to the latest change in libcommon

* update requirements
  • Loading branch information
polinaeterna authored May 12, 2023
1 parent b9f4c56 commit 798f0c8
Show file tree
Hide file tree
Showing 6 changed files with 1,250 additions and 93 deletions.
16 changes: 16 additions & 0 deletions front/admin_ui/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
---
title: Datasets Server Admin UI
emoji: 📊
colorFrom: gray
colorTo: purple
sdk: gradio
sdk_version: 3.28.1
python_version: 3.9.15
app_file: app.py
pinned: false
---

## Datasets-server Admin UI

Deployed at (internal) https://huggingface.co/spaces/datasets-maintainers/datasets-server-admin-ui
Expand All @@ -21,3 +33,7 @@ To connect to your local DEV endpoint:
```
DEV=1 HF_TOKEN=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 poetry run python app.py
```
or to enable auto reloading:
```
DEV=1 HF_TOKEN=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 poetry run gradio app.py
```
24 changes: 23 additions & 1 deletion front/admin_ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import pandas as pd
import requests
import gradio as gr
from libcommon.processing_graph import ProcessingGraph
from libcommon.config import ProcessingGraphConfig
import matplotlib
import matplotlib.pyplot as plt
import networkx as nx
import huggingface_hub as hfh
import duckdb
import json
Expand Down Expand Up @@ -35,6 +39,16 @@ def healthcheck():
return f"❌ Failed to connect to {DSS_ENDPOINT} (error {response.status_code})"


def draw_graph(width, height):
config = ProcessingGraphConfig()
graph = ProcessingGraph(config.specification)._nx_graph

pos = nx.nx_agraph.graphviz_layout(graph, prog="dot")
fig = plt.figure(figsize=(width, height))
nx.draw_networkx(graph, pos=pos)
return fig


with gr.Blocks() as demo:
gr.Markdown(" ## Datasets-server admin page")
gr.Markdown(healthcheck)
Expand Down Expand Up @@ -82,7 +96,15 @@ def healthcheck():
backfill_plan_table = gr.DataFrame(visible=False)
backfill_execute_button = gr.Button("Execute backfill plan", visible=False)
backfill_execute_error = gr.Markdown("", visible=False)

with gr.Tab("Processing graph"):
gr.Markdown("## 💫 Please, don't forget to rebuild (factory reboot) this space immediately after each deploy 💫")
gr.Markdown("### so that we get the 🚀 production 🚀 version of the graph here ")
with gr.Row():
width = gr.Slider(1, 30, 19, step=1, label="Width")
height = gr.Slider(1, 30, 15, step=1, label="Height")
output = gr.Plot()
draw_button = gr.Button("Plot processing graph")
draw_button.click(draw_graph, inputs=[width, height], outputs=output)

def auth(token):
if not token:
Expand Down
2 changes: 2 additions & 0 deletions front/admin_ui/packages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
graphviz
graphviz-dev
Loading

0 comments on commit 798f0c8

Please sign in to comment.