Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,233 +1,34 @@
|
|
| 1 |
-
import streamlit
|
| 2 |
-
import json
|
| 3 |
-
import base64
|
| 4 |
-
import requests
|
| 5 |
-
from io import StringIO
|
| 6 |
from streamlit_agraph import agraph, Node, Edge, Config
|
| 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 |
-
nodes = []
|
| 41 |
-
edges = []
|
| 42 |
-
authors = []
|
| 43 |
-
|
| 44 |
-
video_id = selected_indices[0]['snippet']['videoId']
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
nodes.append(Node(id=video_id,lable='Youtube Video',
|
| 48 |
-
size = 25, symbolType='square'))
|
| 49 |
-
|
| 50 |
-
for data in selected_indices:
|
| 51 |
-
author = data['snippet']['topLevelComment']['snippet']['authorDisplayName'].split(' ')[0]
|
| 52 |
-
author_img = data['snippet']['topLevelComment']['snippet']['authorProfileImageUrl']
|
| 53 |
-
if author not in authors:
|
| 54 |
-
nodes.append(Node(id=author,
|
| 55 |
-
size=25,
|
| 56 |
-
shape="circularImage",
|
| 57 |
-
image=author_img) )
|
| 58 |
-
authors.append(author)
|
| 59 |
-
if 'replies' in data:
|
| 60 |
-
replies = data['replies']['comments']
|
| 61 |
-
for reply in replies:
|
| 62 |
-
reply_author = reply['snippet']['authorDisplayName'].split(' ')[0]
|
| 63 |
-
reply_author_img = reply['snippet']['authorProfileImageUrl']
|
| 64 |
-
if reply_author not in authors:
|
| 65 |
-
nodes.append(Node(id=reply_author,
|
| 66 |
-
size=15,
|
| 67 |
-
shape="circularImage",
|
| 68 |
-
image=reply_author_img) )
|
| 69 |
-
authors.append(reply_author)
|
| 70 |
-
|
| 71 |
-
edges.append( Edge(source=reply_author,
|
| 72 |
-
target=author,
|
| 73 |
-
type="CURVE_SMOOTH"))
|
| 74 |
-
|
| 75 |
-
edges.append(Edge(source=author, target=video_id,type="CURVE_SMOOTH"))
|
| 76 |
-
|
| 77 |
-
#st.write(authors)
|
| 78 |
-
|
| 79 |
-
config = Config(width=750,
|
| 80 |
-
height=950,
|
| 81 |
-
directed=True,
|
| 82 |
-
physics=False,
|
| 83 |
-
hierarchical=False,
|
| 84 |
-
node={'labelProperty':'label','renderLabel':True})
|
| 85 |
-
|
| 86 |
-
return_value = agraph(nodes = nodes, edges = edges, config = config)
|
| 87 |
-
|
| 88 |
-
except Exception as e:
|
| 89 |
-
st.write(e)
|
| 90 |
-
st.markdown("Provided Json is not Youtube API data. Unable to Parse")
|
| 91 |
-
#st.write(json_data)
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
"""
|
| 96 |
-
|
| 97 |
-
import streamlit as st
|
| 98 |
-
from py2neo import Graph, Node, Relationship
|
| 99 |
-
from scripts.viz import draw
|
| 100 |
-
|
| 101 |
-
# Initialize a Neo4j graph instance
|
| 102 |
-
graph = Graph()
|
| 103 |
-
graph.delete_all()
|
| 104 |
-
|
| 105 |
-
# Create nodes and relationships
|
| 106 |
-
nicole = Node("Person", name="Nicole", age=24)
|
| 107 |
-
drew = Node("Person", name="Drew", age=20)
|
| 108 |
-
mtdew = Node("Drink", name="Mountain Dew", calories=9000)
|
| 109 |
-
cokezero = Node("Drink", name="Coke Zero", calories=0)
|
| 110 |
-
coke = Node("Manufacturer", name="Coca Cola")
|
| 111 |
-
pepsi = Node("Manufacturer", name="Pepsi")
|
| 112 |
-
|
| 113 |
-
graph.create(nicole | drew | mtdew | cokezero | coke | pepsi)
|
| 114 |
-
graph.create(Relationship(nicole, "LIKES", cokezero))
|
| 115 |
-
graph.create(Relationship(nicole, "LIKES", mtdew))
|
| 116 |
-
graph.create(Relationship(drew, "LIKES", mtdew))
|
| 117 |
-
graph.create(Relationship(coke, "MAKES", cokezero))
|
| 118 |
-
graph.create(Relationship(pepsi, "MAKES", mtdew))
|
| 119 |
-
|
| 120 |
-
# Streamlit interface
|
| 121 |
-
st.title("Py2neo Application with Streamlit")
|
| 122 |
-
|
| 123 |
-
# Display graph visualization using Py2neo's draw function
|
| 124 |
-
st.subheader("Graph Visualization")
|
| 125 |
-
options = {"Person": "name", "Drink": "name", "Manufacturer": "name"}
|
| 126 |
-
draw(graph, options)
|
| 127 |
-
|
| 128 |
-
# Display node and relationship information
|
| 129 |
-
st.subheader("Node and Relationship Information")
|
| 130 |
-
st.write("Nodes:")
|
| 131 |
-
for node in [nicole, drew, mtdew, cokezero, coke, pepsi]:
|
| 132 |
-
st.write(f"{node.labels}: {node}")
|
| 133 |
-
|
| 134 |
-
st.write("Relationships:")
|
| 135 |
-
for relationship in graph.match(rel_type="LIKES"):
|
| 136 |
-
st.write(relationship)
|
| 137 |
-
|
| 138 |
-
st.write("Manufacturers:")
|
| 139 |
-
for manufacturer in graph.match(rel_type="MAKES"):
|
| 140 |
-
st.write(manufacturer)
|
| 141 |
-
|
| 142 |
-
import streamlit as st
|
| 143 |
-
import json
|
| 144 |
-
import base64
|
| 145 |
-
import requests
|
| 146 |
-
from io import StringIO
|
| 147 |
-
from streamlit_agraph import agraph, Node, Edge, Config
|
| 148 |
-
|
| 149 |
-
st.title('Json File Reader')
|
| 150 |
-
|
| 151 |
-
@st.cache_data
|
| 152 |
-
def get_json(url):
|
| 153 |
-
js = requests.get(url)
|
| 154 |
-
data = js.json()
|
| 155 |
-
return data
|
| 156 |
-
|
| 157 |
-
st.sidebar.header('File Upload')
|
| 158 |
-
your_file = st.sidebar.file_uploader(label="Upload the file here")
|
| 159 |
-
|
| 160 |
-
if your_file is not None:
|
| 161 |
-
bytes_data = your_file.getvalue()
|
| 162 |
-
|
| 163 |
-
json_data = json.loads(bytes_data)
|
| 164 |
-
|
| 165 |
-
else:
|
| 166 |
-
st.write("Example api file can be located here")
|
| 167 |
-
|
| 168 |
-
json_data = get_json("https://raw.githubusercontent.com/insightbuilder/python_de_learners_data/main/code_script_notebooks/python_scripts/json_reader/toplevel_comment_zGAkhN1YZXM.json")
|
| 169 |
-
try:
|
| 170 |
-
length = len(json_data)
|
| 171 |
-
if length < 15:
|
| 172 |
-
indices = st.sidebar.slider("Start n End",0,length,(0,10))
|
| 173 |
-
else:
|
| 174 |
-
indices = st.sidebar.slider("Start n End",0,length,(0,int(length/15)))
|
| 175 |
-
|
| 176 |
-
selected_indices = json_data[indices[0]:indices[1]]
|
| 177 |
-
#st.write(selected_indices)
|
| 178 |
-
#creating the graph of the connection
|
| 179 |
-
|
| 180 |
-
nodes = []
|
| 181 |
-
edges = []
|
| 182 |
-
authors = []
|
| 183 |
-
|
| 184 |
-
video_id = selected_indices[0]['snippet']['videoId']
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
nodes.append(Node(id=video_id,lable='Youtube Video',
|
| 188 |
-
size = 25, symbolType='square'))
|
| 189 |
-
|
| 190 |
-
for data in selected_indices:
|
| 191 |
-
author = data['snippet']['topLevelComment']['snippet']['authorDisplayName'].split(' ')[0]
|
| 192 |
-
author_img = data['snippet']['topLevelComment']['snippet']['authorProfileImageUrl']
|
| 193 |
-
if author not in authors:
|
| 194 |
-
nodes.append(Node(id=author,
|
| 195 |
-
size=25,
|
| 196 |
-
shape="circularImage",
|
| 197 |
-
image=author_img) )
|
| 198 |
-
authors.append(author)
|
| 199 |
-
if 'replies' in data:
|
| 200 |
-
replies = data['replies']['comments']
|
| 201 |
-
for reply in replies:
|
| 202 |
-
reply_author = reply['snippet']['authorDisplayName'].split(' ')[0]
|
| 203 |
-
reply_author_img = reply['snippet']['authorProfileImageUrl']
|
| 204 |
-
if reply_author not in authors:
|
| 205 |
-
nodes.append(Node(id=reply_author,
|
| 206 |
-
size=15,
|
| 207 |
-
shape="circularImage",
|
| 208 |
-
image=reply_author_img) )
|
| 209 |
-
authors.append(reply_author)
|
| 210 |
-
|
| 211 |
-
edges.append( Edge(source=reply_author,
|
| 212 |
-
target=author,
|
| 213 |
-
type="CURVE_SMOOTH"))
|
| 214 |
-
|
| 215 |
-
edges.append(Edge(source=author, target=video_id,type="CURVE_SMOOTH"))
|
| 216 |
-
|
| 217 |
-
#st.write(authors)
|
| 218 |
-
|
| 219 |
-
config = Config(width=750,
|
| 220 |
-
height=950,
|
| 221 |
-
directed=True,
|
| 222 |
-
physics=False,
|
| 223 |
-
hierarchical=False,
|
| 224 |
-
node={'labelProperty':'label','renderLabel':True})
|
| 225 |
-
|
| 226 |
-
return_value = agraph(nodes = nodes, edges = edges, config = config)
|
| 227 |
-
|
| 228 |
-
except Exception as e:
|
| 229 |
-
st.write(e)
|
| 230 |
-
st.markdown("Provided Json is not Youtube API data. Unable to Parse")
|
| 231 |
-
#st.write(json_data)
|
| 232 |
-
|
| 233 |
-
"""
|
|
|
|
| 1 |
+
import streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from streamlit_agraph import agraph, Node, Edge, Config
|
| 3 |
|
| 4 |
+
nodes = []
|
| 5 |
+
edges = []
|
| 6 |
+
nodes.append( Node(id="Spiderman",
|
| 7 |
+
label="Peter Parker",
|
| 8 |
+
size=25,
|
| 9 |
+
shape="circularImage",
|
| 10 |
+
image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_spiderman.png")
|
| 11 |
+
) # includes **kwargs
|
| 12 |
+
nodes.append( Node(id="Captain_Marvel",
|
| 13 |
+
size=25,
|
| 14 |
+
shape="circularImage",
|
| 15 |
+
image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_captainmarvel.png")
|
| 16 |
+
)
|
| 17 |
+
edges.append( Edge(source="Captain_Marvel",
|
| 18 |
+
label="friend_of",
|
| 19 |
+
target="Spiderman",
|
| 20 |
+
# **kwargs
|
| 21 |
+
)
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
config = Config(width=750,
|
| 25 |
+
height=950,
|
| 26 |
+
directed=True,
|
| 27 |
+
physics=True,
|
| 28 |
+
hierarchical=False,
|
| 29 |
+
# **kwargs
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
return_value = agraph(nodes=nodes,
|
| 33 |
+
edges=edges,
|
| 34 |
+
config=config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|