Spaces:
Sleeping
Sleeping
import streamlit as st | |
from py2neo import Graph, Node, Relationship | |
from scripts.viz import draw | |
# Initialize a Neo4j graph instance | |
graph = Graph() | |
graph.delete_all() | |
# Create nodes and relationships | |
nicole = Node("Person", name="Nicole", age=24) | |
drew = Node("Person", name="Drew", age=20) | |
mtdew = Node("Drink", name="Mountain Dew", calories=9000) | |
cokezero = Node("Drink", name="Coke Zero", calories=0) | |
coke = Node("Manufacturer", name="Coca Cola") | |
pepsi = Node("Manufacturer", name="Pepsi") | |
graph.create(nicole | drew | mtdew | cokezero | coke | pepsi) | |
graph.create(Relationship(nicole, "LIKES", cokezero)) | |
graph.create(Relationship(nicole, "LIKES", mtdew)) | |
graph.create(Relationship(drew, "LIKES", mtdew)) | |
graph.create(Relationship(coke, "MAKES", cokezero)) | |
graph.create(Relationship(pepsi, "MAKES", mtdew)) | |
# Streamlit interface | |
st.title("Py2neo Application with Streamlit") | |
# Display graph visualization using Py2neo's draw function | |
st.subheader("Graph Visualization") | |
options = {"Person": "name", "Drink": "name", "Manufacturer": "name"} | |
draw(graph, options) | |
# Display node and relationship information | |
st.subheader("Node and Relationship Information") | |
st.write("Nodes:") | |
for node in [nicole, drew, mtdew, cokezero, coke, pepsi]: | |
st.write(f"{node.labels}: {node}") | |
st.write("Relationships:") | |
for relationship in graph.match(rel_type="LIKES"): | |
st.write(relationship) | |
st.write("Manufacturers:") | |
for manufacturer in graph.match(rel_type="MAKES"): | |
st.write(manufacturer) |