eaglelandsonce
commited on
Commit
•
e66f6ab
1
Parent(s):
9d7b6d7
Create appy.py
Browse files
appy.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from py2neo import Graph, Node, Relationship
|
3 |
+
from scripts.vis import draw
|
4 |
+
|
5 |
+
# Initialize a Neo4j graph instance
|
6 |
+
graph = Graph()
|
7 |
+
graph.delete_all()
|
8 |
+
|
9 |
+
# Create nodes and relationships
|
10 |
+
nicole = Node("Person", name="Nicole", age=24)
|
11 |
+
drew = Node("Person", name="Drew", age=20)
|
12 |
+
mtdew = Node("Drink", name="Mountain Dew", calories=9000)
|
13 |
+
cokezero = Node("Drink", name="Coke Zero", calories=0)
|
14 |
+
coke = Node("Manufacturer", name="Coca Cola")
|
15 |
+
pepsi = Node("Manufacturer", name="Pepsi")
|
16 |
+
|
17 |
+
graph.create(nicole | drew | mtdew | cokezero | coke | pepsi)
|
18 |
+
graph.create(Relationship(nicole, "LIKES", cokezero))
|
19 |
+
graph.create(Relationship(nicole, "LIKES", mtdew))
|
20 |
+
graph.create(Relationship(drew, "LIKES", mtdew))
|
21 |
+
graph.create(Relationship(coke, "MAKES", cokezero))
|
22 |
+
graph.create(Relationship(pepsi, "MAKES", mtdew))
|
23 |
+
|
24 |
+
# Streamlit interface
|
25 |
+
st.title("Py2neo Application with Streamlit")
|
26 |
+
|
27 |
+
# Display graph visualization using Py2neo's draw function
|
28 |
+
st.subheader("Graph Visualization")
|
29 |
+
options = {"Person": "name", "Drink": "name", "Manufacturer": "name"}
|
30 |
+
draw(graph, options)
|
31 |
+
|
32 |
+
# Display node and relationship information
|
33 |
+
st.subheader("Node and Relationship Information")
|
34 |
+
st.write("Nodes:")
|
35 |
+
for node in [nicole, drew, mtdew, cokezero, coke, pepsi]:
|
36 |
+
st.write(f"{node.labels}: {node}")
|
37 |
+
|
38 |
+
st.write("Relationships:")
|
39 |
+
for relationship in graph.match(rel_type="LIKES"):
|
40 |
+
st.write(relationship)
|
41 |
+
|
42 |
+
st.write("Manufacturers:")
|
43 |
+
for manufacturer in graph.match(rel_type="MAKES"):
|
44 |
+
st.write(manufacturer)
|