Spaces:
Sleeping
Sleeping
eaglelandsonce
commited on
Commit
•
54df6fe
1
Parent(s):
ee54ebd
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from py2neo import Graph, Node, Relationship
|
3 |
from scripts.viz import draw
|
@@ -41,4 +138,97 @@ for relationship in graph.match(rel_type="LIKES"):
|
|
41 |
|
42 |
st.write("Manufacturers:")
|
43 |
for manufacturer in graph.match(rel_type="MAKES"):
|
44 |
-
st.write(manufacturer)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
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 |
+
st.title('Json File Reader')
|
9 |
+
|
10 |
+
@st.cache_data
|
11 |
+
def get_json(url):
|
12 |
+
js = requests.get(url)
|
13 |
+
data = js.json()
|
14 |
+
return data
|
15 |
+
|
16 |
+
st.markdown("""Reads the Json file of Comments data extracted from Youtube API & creates graph""")
|
17 |
+
st.sidebar.header('File Upload')
|
18 |
+
your_file = st.sidebar.file_uploader(label="Upload the file here")
|
19 |
+
|
20 |
+
if your_file is not None:
|
21 |
+
bytes_data = your_file.getvalue()
|
22 |
+
|
23 |
+
json_data = json.loads(bytes_data)
|
24 |
+
|
25 |
+
else:
|
26 |
+
st.write("Example api file can be located here")
|
27 |
+
|
28 |
+
st.write("""https://raw.githubusercontent.com/insightbuilder/python_de_learners_data/main/code_script_notebooks/python_scripts/json_reader/toplevel_comment_zGAkhN1YZXM.json""")
|
29 |
+
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")
|
30 |
+
try:
|
31 |
+
length = len(json_data)
|
32 |
+
if length < 15:
|
33 |
+
indices = st.sidebar.slider("Start n End",0,length,(0,10))
|
34 |
+
else:
|
35 |
+
indices = st.sidebar.slider("Start n End",0,length,(0,int(length/15)))
|
36 |
+
|
37 |
+
selected_indices = json_data[indices[0]:indices[1]]
|
38 |
+
#st.write(selected_indices)
|
39 |
+
#creating the graph of the connection
|
40 |
+
|
41 |
+
nodes = []
|
42 |
+
edges = []
|
43 |
+
authors = []
|
44 |
+
|
45 |
+
video_id = selected_indices[0]['snippet']['videoId']
|
46 |
+
|
47 |
+
|
48 |
+
nodes.append(Node(id=video_id,lable='Youtube Video',
|
49 |
+
size = 25, symbolType='square'))
|
50 |
+
|
51 |
+
for data in selected_indices:
|
52 |
+
author = data['snippet']['topLevelComment']['snippet']['authorDisplayName'].split(' ')[0]
|
53 |
+
author_img = data['snippet']['topLevelComment']['snippet']['authorProfileImageUrl']
|
54 |
+
if author not in authors:
|
55 |
+
nodes.append(Node(id=author,
|
56 |
+
size=25,
|
57 |
+
shape="circularImage",
|
58 |
+
image=author_img) )
|
59 |
+
authors.append(author)
|
60 |
+
if 'replies' in data:
|
61 |
+
replies = data['replies']['comments']
|
62 |
+
for reply in replies:
|
63 |
+
reply_author = reply['snippet']['authorDisplayName'].split(' ')[0]
|
64 |
+
reply_author_img = reply['snippet']['authorProfileImageUrl']
|
65 |
+
if reply_author not in authors:
|
66 |
+
nodes.append(Node(id=reply_author,
|
67 |
+
size=15,
|
68 |
+
shape="circularImage",
|
69 |
+
image=reply_author_img) )
|
70 |
+
authors.append(reply_author)
|
71 |
+
|
72 |
+
edges.append( Edge(source=reply_author,
|
73 |
+
target=author,
|
74 |
+
type="CURVE_SMOOTH"))
|
75 |
+
|
76 |
+
edges.append(Edge(source=author, target=video_id,type="CURVE_SMOOTH"))
|
77 |
+
|
78 |
+
#st.write(authors)
|
79 |
+
|
80 |
+
config = Config(width=750,
|
81 |
+
height=950,
|
82 |
+
directed=True,
|
83 |
+
physics=False,
|
84 |
+
hierarchical=False,
|
85 |
+
node={'labelProperty':'label','renderLabel':True})
|
86 |
+
|
87 |
+
return_value = agraph(nodes = nodes, edges = edges, config = config)
|
88 |
+
|
89 |
+
except Exception as e:
|
90 |
+
st.write(e)
|
91 |
+
st.markdown("Provided Json is not Youtube API data. Unable to Parse")
|
92 |
+
#st.write(json_data)
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
"""
|
97 |
+
|
98 |
import streamlit as st
|
99 |
from py2neo import Graph, Node, Relationship
|
100 |
from scripts.viz import draw
|
|
|
138 |
|
139 |
st.write("Manufacturers:")
|
140 |
for manufacturer in graph.match(rel_type="MAKES"):
|
141 |
+
st.write(manufacturer)
|
142 |
+
|
143 |
+
import streamlit as st
|
144 |
+
import json
|
145 |
+
import base64
|
146 |
+
import requests
|
147 |
+
from io import StringIO
|
148 |
+
from streamlit_agraph import agraph, Node, Edge, Config
|
149 |
+
|
150 |
+
st.title('Json File Reader')
|
151 |
+
|
152 |
+
@st.cache_data
|
153 |
+
def get_json(url):
|
154 |
+
js = requests.get(url)
|
155 |
+
data = js.json()
|
156 |
+
return data
|
157 |
+
|
158 |
+
st.markdown("""Reads the Json file of Comments data extracted from Youtube API & creates graph""")
|
159 |
+
st.sidebar.header('File Upload')
|
160 |
+
your_file = st.sidebar.file_uploader(label="Upload the file here")
|
161 |
+
|
162 |
+
if your_file is not None:
|
163 |
+
bytes_data = your_file.getvalue()
|
164 |
+
|
165 |
+
json_data = json.loads(bytes_data)
|
166 |
+
|
167 |
+
else:
|
168 |
+
st.write("Example api file can be located here")
|
169 |
+
|
170 |
+
st.write("""https://raw.githubusercontent.com/insightbuilder/python_de_learners_data/main/code_script_notebooks/python_scripts/json_reader/toplevel_comment_zGAkhN1YZXM.json""")
|
171 |
+
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")
|
172 |
+
try:
|
173 |
+
length = len(json_data)
|
174 |
+
if length < 15:
|
175 |
+
indices = st.sidebar.slider("Start n End",0,length,(0,10))
|
176 |
+
else:
|
177 |
+
indices = st.sidebar.slider("Start n End",0,length,(0,int(length/15)))
|
178 |
+
|
179 |
+
selected_indices = json_data[indices[0]:indices[1]]
|
180 |
+
#st.write(selected_indices)
|
181 |
+
#creating the graph of the connection
|
182 |
+
|
183 |
+
nodes = []
|
184 |
+
edges = []
|
185 |
+
authors = []
|
186 |
+
|
187 |
+
video_id = selected_indices[0]['snippet']['videoId']
|
188 |
+
|
189 |
+
|
190 |
+
nodes.append(Node(id=video_id,lable='Youtube Video',
|
191 |
+
size = 25, symbolType='square'))
|
192 |
+
|
193 |
+
for data in selected_indices:
|
194 |
+
author = data['snippet']['topLevelComment']['snippet']['authorDisplayName'].split(' ')[0]
|
195 |
+
author_img = data['snippet']['topLevelComment']['snippet']['authorProfileImageUrl']
|
196 |
+
if author not in authors:
|
197 |
+
nodes.append(Node(id=author,
|
198 |
+
size=25,
|
199 |
+
shape="circularImage",
|
200 |
+
image=author_img) )
|
201 |
+
authors.append(author)
|
202 |
+
if 'replies' in data:
|
203 |
+
replies = data['replies']['comments']
|
204 |
+
for reply in replies:
|
205 |
+
reply_author = reply['snippet']['authorDisplayName'].split(' ')[0]
|
206 |
+
reply_author_img = reply['snippet']['authorProfileImageUrl']
|
207 |
+
if reply_author not in authors:
|
208 |
+
nodes.append(Node(id=reply_author,
|
209 |
+
size=15,
|
210 |
+
shape="circularImage",
|
211 |
+
image=reply_author_img) )
|
212 |
+
authors.append(reply_author)
|
213 |
+
|
214 |
+
edges.append( Edge(source=reply_author,
|
215 |
+
target=author,
|
216 |
+
type="CURVE_SMOOTH"))
|
217 |
+
|
218 |
+
edges.append(Edge(source=author, target=video_id,type="CURVE_SMOOTH"))
|
219 |
+
|
220 |
+
#st.write(authors)
|
221 |
+
|
222 |
+
config = Config(width=750,
|
223 |
+
height=950,
|
224 |
+
directed=True,
|
225 |
+
physics=False,
|
226 |
+
hierarchical=False,
|
227 |
+
node={'labelProperty':'label','renderLabel':True})
|
228 |
+
|
229 |
+
return_value = agraph(nodes = nodes, edges = edges, config = config)
|
230 |
+
|
231 |
+
except Exception as e:
|
232 |
+
st.write(e)
|
233 |
+
st.markdown("Provided Json is not Youtube API data. Unable to Parse")
|
234 |
+
#st.write(json_data)
|