Skip to content

Commit

Permalink
Generate tab now accepts copy & pasted json data (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalakoo authored Jun 18, 2023
1 parent 18dba76 commit 6f8eb9c
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 350 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pandas = "*"
random-address = "*"
openai = "*"
numpy = "*"
certifi = "*"

[dev-packages]
mock-generators = {editable = true, path = "."}
Expand Down
582 changes: 289 additions & 293 deletions Pipfile.lock

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions mock_generators/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import streamlit as st
from constants import *
from tabs.ideate_tab import ideate_tab
from tabs.importing_tab import import_tab
from tabs.generate_tab import import_tab
from tabs.design_tab import design_tab
from tabs.data_importer import data_importer_tab
from tabs.tutorial import tutorial_tab
from tabs.getting_help import get_help_tab
from tabs.dashboard import dashboard_tab

from config import setup_logging, preload_state, load_generators_to_streamlit

Expand All @@ -16,21 +17,22 @@
load_generators_to_streamlit()

# UI
st.title("Mock Graph Data Generator")
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.")
# st.title("Mock Graph Data Generator")
# 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.")


generators = None
imported_file = None

# 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.

t0, t1, t2, t3, t4, t5 = st.tabs([
t0, t1, t2, t3, t4, t5, t6 = st.tabs([
"⓪ Getting Started",
"① Ideate",
"② Design",
"③ Generate",
"④ Data Importer",
"④ Import",
"⑤ Dashboard",
"Ⓘ Info"
])

Expand All @@ -45,4 +47,6 @@
with t4:
data_importer_tab()
with t5:
dashboard_tab()
with t6:
get_help_tab()
9 changes: 9 additions & 0 deletions mock_generators/tabs/dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import streamlit as st
import streamlit.components.v1 as components

def dashboard_tab():
st.markdown("""
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/)
""")
# Neodash interface
components.iframe("https://neodash.graphapp.io", height=1000, scrolling=True)
4 changes: 2 additions & 2 deletions mock_generators/tabs/data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def data_importer_tab():
# with col2:
# 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.")
with st.expander('Instructions'):
st.write("""
1. Connect to your Neo4j instance
st.markdown("""
1. Connect to your Neo4j instance below or through [the console](https://console.neo4j.io)
2. Click on the '...' options button in the Data Importer header
3. Select 'Open model (with data)'
4. Select the .zip file with the generated data
Expand Down
67 changes: 67 additions & 0 deletions mock_generators/tabs/generate_tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Now the new Generate Tab

import streamlit as st
from constants import *
from io import StringIO
from models.mapping import Mapping
from logic.generate_mapping import mapping_from_json
from generate import generate_zip

def import_tab():

with st.expander("Instructions"):
st.write(
"""
1. Import a file created from the ① Ideate or ② Design tabs
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.
3. Download the .zip file
4. Proceed to the '④ Data Importer' tab
"""
)


st.markdown("--------")

c1, c2 = st.tabs(["Copy & Paste", "Import File"])
with c1:
filename = st.text_input("Name of file", value="mock_data")
txt = st.text_area("Paste arrows.app JSON here", height=500, help="Click out of the text area to generate the .zip file.")
if txt is not None and txt != "":
# Process .json text
st.session_state[MAPPINGS] = Mapping.empty()
generators = st.session_state[GENERATORS]
mapping = mapping_from_json(
txt,
generators)
zip = generate_zip(mapping)
st.download_button(
label = "Download .zip file",
data = zip,
file_name = f"{filename}.zip",
mime = "text/plain"
)
with c2:
uploaded_file = st.file_uploader("Upload an arrows JSON file", type="json")
if uploaded_file is not None:
# To convert to a string based IO:
stringio = StringIO(uploaded_file.getvalue().decode("utf-8"))
# To read file as string:
current_file = stringio.read()

# Save to session state
st.session_state[MAPPINGS] = Mapping.empty()

name = uploaded_file.name.split(".")[0]
if current_file is not None:
# TODO: Verfiy file is valid arrows JSON
generators = st.session_state[GENERATORS]
mapping = mapping_from_json(
current_file,
generators)
zip = generate_zip(mapping)
st.download_button(
label = "Download .zip file",
data = zip,
file_name = f"{name}.zip",
mime = "text/plain"
)
7 changes: 5 additions & 2 deletions mock_generators/tabs/getting_help.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import streamlit as st

def get_help_tab():
st.write("Version 0.5.0")
st.write("Email [email protected] for help.")
version = st.secrets["VERSION"]
st.write(f"Version {version}")
st.markdown("""
Post issues and comments in this [github repo](https://github.com/jalakoo/mock-graph-data-generator/issues)
""")
48 changes: 0 additions & 48 deletions mock_generators/tabs/importing_tab.py

This file was deleted.

11 changes: 11 additions & 0 deletions mock_generators/tabs/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
import streamlit as st

def tutorial_tab():
st.title("Mock Graph Data Generator")
st.markdown(
"""
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.
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.
NOTES:
- Chromium browser recommended for best experience.
- Each tool may require independent logins with first use.
""")
url = st.secrets["VIDEO_TUTORIAL_URL"]
st_player(url, height=600)

0 comments on commit 6f8eb9c

Please sign in to comment.