Skip to content

Commit 6f8eb9c

Browse files
authored
Generate tab now accepts copy & pasted json data (#15)
1 parent 18dba76 commit 6f8eb9c

9 files changed

+393
-350
lines changed

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pandas = "*"
1717
random-address = "*"
1818
openai = "*"
1919
numpy = "*"
20+
certifi = "*"
2021

2122
[dev-packages]
2223
mock-generators = {editable = true, path = "."}

Pipfile.lock

+289-293
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mock_generators/app.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import streamlit as st
22
from constants import *
33
from tabs.ideate_tab import ideate_tab
4-
from tabs.importing_tab import import_tab
4+
from tabs.generate_tab import import_tab
55
from tabs.design_tab import design_tab
66
from tabs.data_importer import data_importer_tab
77
from tabs.tutorial import tutorial_tab
88
from tabs.getting_help import get_help_tab
9+
from tabs.dashboard import dashboard_tab
910

1011
from config import setup_logging, preload_state, load_generators_to_streamlit
1112

@@ -16,21 +17,22 @@
1617
load_generators_to_streamlit()
1718

1819
# UI
19-
st.title("Mock Graph Data Generator")
20-
st.markdown("This is a collection of tools to generate mock graph data for [Neo4j](https://neo4j.com) graph databases. NOTE: Chromium browser recommended for best experience.")
20+
# st.title("Mock Graph Data Generator")
21+
# st.markdown("This is a collection of tools to generate mock graph data for [Neo4j](https://neo4j.com) graph databases. NOTE: Chromium browser recommended for best experience.")
2122

2223

2324
generators = None
2425
imported_file = None
2526

2627
# Streamlit runs from top-to-bottom from tabs 1 through 8. This is essentially one giant single page app. Earlier attempt to use Streamlit's multi-page app functionality resulted in an inconsistent state between pages.
2728

28-
t0, t1, t2, t3, t4, t5 = st.tabs([
29+
t0, t1, t2, t3, t4, t5, t6 = st.tabs([
2930
"⓪ Getting Started",
3031
"① Ideate",
3132
"② Design",
3233
"③ Generate",
33-
"④ Data Importer",
34+
"④ Import",
35+
"⑤ Dashboard",
3436
"Ⓘ Info"
3537
])
3638

@@ -45,4 +47,6 @@
4547
with t4:
4648
data_importer_tab()
4749
with t5:
50+
dashboard_tab()
51+
with t6:
4852
get_help_tab()

mock_generators/tabs/dashboard.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import streamlit as st
2+
import streamlit.components.v1 as components
3+
4+
def dashboard_tab():
5+
st.markdown("""
6+
Use Neodash below to create a simple data dashboard from a Neo4j database. Requires knowledge of [Cypher](https://neo4j.com/docs/getting-started/cypher-intro/)
7+
""")
8+
# Neodash interface
9+
components.iframe("https://neodash.graphapp.io", height=1000, scrolling=True)

mock_generators/tabs/data_importer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def data_importer_tab():
1212
# with col2:
1313
# st.write(f"Data Importer App.\n\nUse the [Data Importer Tool](https://data-importer.graphapp.io/) to upload generated .zip file to for review and ingesetion to a Neo4j database instance.")
1414
with st.expander('Instructions'):
15-
st.write("""
16-
1. Connect to your Neo4j instance
15+
st.markdown("""
16+
1. Connect to your Neo4j instance below or through [the console](https://console.neo4j.io)
1717
2. Click on the '...' options button in the Data Importer header
1818
3. Select 'Open model (with data)'
1919
4. Select the .zip file with the generated data

mock_generators/tabs/generate_tab.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Now the new Generate Tab
2+
3+
import streamlit as st
4+
from constants import *
5+
from io import StringIO
6+
from models.mapping import Mapping
7+
from logic.generate_mapping import mapping_from_json
8+
from generate import generate_zip
9+
10+
def import_tab():
11+
12+
with st.expander("Instructions"):
13+
st.write(
14+
"""
15+
1. Import a file created from the ① Ideate or ② Design tabs
16+
2. The mock graph data generator will automatically generate a .zip file containing .csv and .json files. The .csvs can be independently imported into any database that supports .csv imports. The .json file is specifically formatted for the Neo4j Data Importer.
17+
3. Download the .zip file
18+
4. Proceed to the '④ Data Importer' tab
19+
"""
20+
)
21+
22+
23+
st.markdown("--------")
24+
25+
c1, c2 = st.tabs(["Copy & Paste", "Import File"])
26+
with c1:
27+
filename = st.text_input("Name of file", value="mock_data")
28+
txt = st.text_area("Paste arrows.app JSON here", height=500, help="Click out of the text area to generate the .zip file.")
29+
if txt is not None and txt != "":
30+
# Process .json text
31+
st.session_state[MAPPINGS] = Mapping.empty()
32+
generators = st.session_state[GENERATORS]
33+
mapping = mapping_from_json(
34+
txt,
35+
generators)
36+
zip = generate_zip(mapping)
37+
st.download_button(
38+
label = "Download .zip file",
39+
data = zip,
40+
file_name = f"{filename}.zip",
41+
mime = "text/plain"
42+
)
43+
with c2:
44+
uploaded_file = st.file_uploader("Upload an arrows JSON file", type="json")
45+
if uploaded_file is not None:
46+
# To convert to a string based IO:
47+
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
48+
# To read file as string:
49+
current_file = stringio.read()
50+
51+
# Save to session state
52+
st.session_state[MAPPINGS] = Mapping.empty()
53+
54+
name = uploaded_file.name.split(".")[0]
55+
if current_file is not None:
56+
# TODO: Verfiy file is valid arrows JSON
57+
generators = st.session_state[GENERATORS]
58+
mapping = mapping_from_json(
59+
current_file,
60+
generators)
61+
zip = generate_zip(mapping)
62+
st.download_button(
63+
label = "Download .zip file",
64+
data = zip,
65+
file_name = f"{name}.zip",
66+
mime = "text/plain"
67+
)

mock_generators/tabs/getting_help.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import streamlit as st
22

33
def get_help_tab():
4-
st.write("Version 0.5.0")
5-
st.write("Email jason.koo@neo4j.com for help.")
4+
version = st.secrets["VERSION"]
5+
st.write(f"Version {version}")
6+
st.markdown("""
7+
Post issues and comments in this [github repo](https://github.com/jalakoo/mock-graph-data-generator/issues)
8+
""")

mock_generators/tabs/importing_tab.py

-48
This file was deleted.

mock_generators/tabs/tutorial.py

+11
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,16 @@
22
import streamlit as st
33

44
def tutorial_tab():
5+
st.title("Mock Graph Data Generator")
6+
st.markdown(
7+
"""
8+
This app is a central collection of existing tools for generating interconnected mock data that can also be imported directly into a [Neo4j](https://neo4j.com) graph database.
9+
10+
Move along each tab from left to right to define the model (or schema), generate the mock data, then optionally import and query the data. Instructions are available within each tab and a general walkthrough video is available below.
11+
12+
NOTES:
13+
- Chromium browser recommended for best experience.
14+
- Each tool may require independent logins with first use.
15+
""")
516
url = st.secrets["VIDEO_TUTORIAL_URL"]
617
st_player(url, height=600)

0 commit comments

Comments
 (0)