Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,29 @@ def value_to_hex(value):
|
|
61 |
return "#{:02X}{:02X}{:02X}".format(int(rgba_color[0] * 255), int(rgba_color[1] * 255), int(rgba_color[2] * 255))
|
62 |
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
def visualize_isnad(taraf_num, yaxis):
|
@@ -109,27 +131,7 @@ def visualize_isnad(taraf_num, yaxis):
|
|
109 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
110 |
|
111 |
for node, pos in isnad_pos.items():
|
112 |
-
node_info
|
113 |
-
student_narrations = node_info['Number of Narrations'].to_list()
|
114 |
-
if len(student_narrations):
|
115 |
-
student_narrations = student_narrations[0]
|
116 |
-
else:
|
117 |
-
student_narrations = 1
|
118 |
-
student_gen = node_info['Generation'].to_list()
|
119 |
-
if len(student_gen):
|
120 |
-
student_gen = student_gen[0]
|
121 |
-
else:
|
122 |
-
student_gen = -1
|
123 |
-
student_rank = node_info["Narrator Rank"].to_list()
|
124 |
-
if len(student_rank):
|
125 |
-
student_rank = student_rank[0]
|
126 |
-
else:
|
127 |
-
student_rank = 'ููุงู'
|
128 |
-
node_name = node_info['Famous Name'].to_list()
|
129 |
-
if len(node_name):
|
130 |
-
node_name = node_name[0]
|
131 |
-
else:
|
132 |
-
node_name = 'ููุงู'
|
133 |
if node == '99999':
|
134 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
135 |
elif node in end_nodes:
|
@@ -152,7 +154,6 @@ def visualize_isnad(taraf_num, yaxis):
|
|
152 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , df.drop('Hdth Num', axis=1)
|
153 |
|
154 |
|
155 |
-
|
156 |
def visualize_subTaraf(taraf_num, hadith_str, yaxis):
|
157 |
hadith_list = hadith_str.split(',')
|
158 |
hadith_list = [hadith.strip() for hadith in hadith_list]
|
@@ -205,27 +206,7 @@ def visualize_subTaraf(taraf_num, hadith_str, yaxis):
|
|
205 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
206 |
|
207 |
for node, pos in isnad_pos.items():
|
208 |
-
node_info
|
209 |
-
student_narrations = node_info['Number of Narrations'].to_list()
|
210 |
-
if len(student_narrations):
|
211 |
-
student_narrations = student_narrations[0]
|
212 |
-
else:
|
213 |
-
student_narrations = 1
|
214 |
-
student_gen = node_info['Generation'].to_list()
|
215 |
-
if len(student_gen):
|
216 |
-
student_gen = student_gen[0]
|
217 |
-
else:
|
218 |
-
student_gen = -1
|
219 |
-
student_rank = node_info["Narrator Rank"].to_list()
|
220 |
-
if len(student_rank):
|
221 |
-
student_rank = student_rank[0]
|
222 |
-
else:
|
223 |
-
student_rank = 'ููุงู'
|
224 |
-
node_name = node_info['Famous Name'].to_list()
|
225 |
-
if len(node_name):
|
226 |
-
node_name = node_name[0]
|
227 |
-
else:
|
228 |
-
node_name = 'ููุงู'
|
229 |
if node == '99999':
|
230 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
231 |
else:
|
@@ -267,27 +248,7 @@ def visualize_hadith_isnad(df, yaxis):
|
|
267 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
268 |
|
269 |
for node, pos in isnad_pos.items():
|
270 |
-
node_info
|
271 |
-
student_narrations = node_info['Number of Narrations'].to_list()
|
272 |
-
if len(student_narrations):
|
273 |
-
student_narrations = student_narrations[0]
|
274 |
-
else:
|
275 |
-
student_narrations = 1
|
276 |
-
student_gen = node_info['Generation'].to_list()
|
277 |
-
if len(student_gen):
|
278 |
-
student_gen = student_gen[0]
|
279 |
-
else:
|
280 |
-
student_gen = -1
|
281 |
-
student_rank = node_info["Narrator Rank"].to_list()
|
282 |
-
if len(student_rank):
|
283 |
-
student_rank = student_rank[0]
|
284 |
-
else:
|
285 |
-
student_rank = 'ููุงู'
|
286 |
-
node_name = node_info['Famous Name'].to_list()
|
287 |
-
if len(node_name):
|
288 |
-
node_name = node_name[0]
|
289 |
-
else:
|
290 |
-
node_name = 'ููุงู'
|
291 |
if node == '99999':
|
292 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
293 |
else:
|
@@ -325,11 +286,6 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
|
|
325 |
# nodes = list(G.nodes)
|
326 |
# nodes = [node for node in nodes if node not in list(nx.ancestors(G, narrator)) + list(nx.descendants(G, narrator)) and node !=narrator]
|
327 |
# [G.remove_nodes_from(nodes)]
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
matns_with_narrator = []
|
334 |
end_node = {}
|
335 |
for i in range(len(taraf_hadith_split)):
|
@@ -358,32 +314,7 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
|
|
358 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
359 |
|
360 |
for node, pos in isnad_pos.items():
|
361 |
-
node_info
|
362 |
-
|
363 |
-
student_narrations = node_info['Number of Narrations'].to_list()
|
364 |
-
if len(student_narrations):
|
365 |
-
student_narrations = student_narrations[0]
|
366 |
-
else:
|
367 |
-
student_narrations = 1
|
368 |
-
|
369 |
-
student_gen = node_info['Generation'].to_list()
|
370 |
-
if len(student_gen):
|
371 |
-
student_gen = student_gen[0]
|
372 |
-
else:
|
373 |
-
student_gen = -1
|
374 |
-
|
375 |
-
student_rank = node_info["Narrator Rank"].to_list()
|
376 |
-
if len(student_rank):
|
377 |
-
student_rank = student_rank[0]
|
378 |
-
else:
|
379 |
-
student_rank = 'ููุงู'
|
380 |
-
|
381 |
-
node_name = node_info['Famous Name'].to_list()
|
382 |
-
if len(node_name):
|
383 |
-
node_name = node_name[0]
|
384 |
-
else:
|
385 |
-
node_name = 'ููุงู'
|
386 |
-
|
387 |
if node == '99999':
|
388 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
389 |
elif node in list(end_node.keys()):
|
@@ -405,7 +336,6 @@ def visualize_narrator_taraf(taraf_num, narrator, yaxis):
|
|
405 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , narrator_matn_info[['matn', 'Book_Name', 'Author', 'Book_ID', 'Hadith Number', 'Index', 'Subset Index']]
|
406 |
|
407 |
|
408 |
-
|
409 |
with gr.Blocks() as demo:
|
410 |
with gr.Tab("Whole Taraf Visualizer"):
|
411 |
Yaxis = gr.Dropdown(choices = ['Taraf', 'Hadith', 'Isnad', 'Book'], value = 'Taraf', label = 'Variable to Display', info = 'Choose the variable to visualize.')
|
|
|
61 |
return "#{:02X}{:02X}{:02X}".format(int(rgba_color[0] * 255), int(rgba_color[1] * 255), int(rgba_color[2] * 255))
|
62 |
|
63 |
|
64 |
+
def get_node_info(node):
|
65 |
+
node_info = narrator_bios[narrator_bios['Rawi ID'] == int(node)]
|
66 |
+
student_narrations = node_info['Number of Narrations'].to_list()
|
67 |
+
if len(student_narrations):
|
68 |
+
student_narrations = student_narrations[0]
|
69 |
+
else:
|
70 |
+
student_narrations = 1
|
71 |
+
student_gen = node_info['Generation'].to_list()
|
72 |
+
if len(student_gen):
|
73 |
+
student_gen = student_gen[0]
|
74 |
+
else:
|
75 |
+
student_gen = -1
|
76 |
+
student_rank = node_info["Narrator Rank"].to_list()
|
77 |
+
if len(student_rank):
|
78 |
+
student_rank = student_rank[0]
|
79 |
+
else:
|
80 |
+
student_rank = 'ููุงู'
|
81 |
+
node_name = node_info['Famous Name'].to_list()
|
82 |
+
if len(node_name):
|
83 |
+
node_name = node_name[0]
|
84 |
+
else:
|
85 |
+
node_name = 'ููุงู'
|
86 |
+
return node_info,student_narrations,student_gen, student_rank, node_name
|
87 |
|
88 |
|
89 |
def visualize_isnad(taraf_num, yaxis):
|
|
|
131 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
132 |
|
133 |
for node, pos in isnad_pos.items():
|
134 |
+
node_info,student_narrations,student_gen, student_rank, node_name = get_node_info(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
if node == '99999':
|
136 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
137 |
elif node in end_nodes:
|
|
|
154 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , df.drop('Hdth Num', axis=1)
|
155 |
|
156 |
|
|
|
157 |
def visualize_subTaraf(taraf_num, hadith_str, yaxis):
|
158 |
hadith_list = hadith_str.split(',')
|
159 |
hadith_list = [hadith.strip() for hadith in hadith_list]
|
|
|
206 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
207 |
|
208 |
for node, pos in isnad_pos.items():
|
209 |
+
node_info,student_narrations,student_gen, student_rank, node_name = get_node_info(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
if node == '99999':
|
211 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
212 |
else:
|
|
|
248 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
249 |
|
250 |
for node, pos in isnad_pos.items():
|
251 |
+
node_info,student_narrations,student_gen, student_rank, node_name = get_node_info(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
if node == '99999':
|
253 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
254 |
else:
|
|
|
286 |
# nodes = list(G.nodes)
|
287 |
# nodes = [node for node in nodes if node not in list(nx.ancestors(G, narrator)) + list(nx.descendants(G, narrator)) and node !=narrator]
|
288 |
# [G.remove_nodes_from(nodes)]
|
|
|
|
|
|
|
|
|
|
|
289 |
matns_with_narrator = []
|
290 |
end_node = {}
|
291 |
for i in range(len(taraf_hadith_split)):
|
|
|
314 |
net = Network(directed =True, select_menu=True, cdn_resources='remote')
|
315 |
|
316 |
for node, pos in isnad_pos.items():
|
317 |
+
node_info,student_narrations,student_gen, student_rank, node_name = get_node_info(node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
if node == '99999':
|
319 |
net.add_node(node, font = {'size':50, 'color': 'black'}, color = '#000000', label = f'{node_name} \n ID: {node} - Gen {student_gen}', x= pos[0]*x_stretch, y= -1*pos[1]*y_stretch, size= 70)
|
320 |
elif node in list(end_node.keys()):
|
|
|
336 |
allowpaymentrequest="" frameborder="0" srcdoc='{html}'></iframe>""" , narrator_matn_info[['matn', 'Book_Name', 'Author', 'Book_ID', 'Hadith Number', 'Index', 'Subset Index']]
|
337 |
|
338 |
|
|
|
339 |
with gr.Blocks() as demo:
|
340 |
with gr.Tab("Whole Taraf Visualizer"):
|
341 |
Yaxis = gr.Dropdown(choices = ['Taraf', 'Hadith', 'Isnad', 'Book'], value = 'Taraf', label = 'Variable to Display', info = 'Choose the variable to visualize.')
|