File size: 1,492 Bytes
184a0b8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import streamlit as st
from py2neo import Graph, Node, Relationship
from scripts.vis 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) |