Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from graphviz import Digraph
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def create_graph_from_json_text(json_text):
|
| 6 |
+
# Konvertieren des JSON-Texts in ein Python Dictionary
|
| 7 |
+
json_data = json.loads(json_text)
|
| 8 |
+
|
| 9 |
+
graph = Digraph()
|
| 10 |
+
for key, value in json_data.items():
|
| 11 |
+
if isinstance(value, list):
|
| 12 |
+
for item in value:
|
| 13 |
+
graph.edge(key, item)
|
| 14 |
+
else:
|
| 15 |
+
graph.edge(key, value)
|
| 16 |
+
return graph
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
st.title("Graph Visualization with Graphviz and Streamlit")
|
| 20 |
+
|
| 21 |
+
# JSON-Text in Streamlit
|
| 22 |
+
json_text = """
|
| 23 |
+
{
|
| 24 |
+
"foo": "bar",
|
| 25 |
+
"baz": "boz",
|
| 26 |
+
"stuff": [
|
| 27 |
+
"stuff 1",
|
| 28 |
+
"stuff 2",
|
| 29 |
+
"stuff 3",
|
| 30 |
+
"stuff 5"
|
| 31 |
+
]
|
| 32 |
+
}
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
# Erstellen des Diagramms aus dem JSON-Text
|
| 36 |
+
graph = create_graph_from_json_text(json_text)
|
| 37 |
+
|
| 38 |
+
# Anzeige des Diagramms in Streamlit
|
| 39 |
+
st.graphviz_chart(graph.source)
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
main()
|