Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,27 +32,26 @@ def splitIsnad(dataframe):
|
|
32 |
return dataframe
|
33 |
|
34 |
|
35 |
-
def network_visualizer(city, year, num_nodes):
|
36 |
-
edges = splitIsnad(subsetEdges(city, year))[['Teacher', 'Student',
|
|
|
37 |
if edges.shape[0] > num_nodes:
|
38 |
edge_15 = edges.sample(num_nodes)
|
39 |
else:
|
40 |
edge_15 = edges.copy()
|
41 |
-
teacher_hadiths = edge_15[['Teacher',
|
42 |
-
student_hadiths = edge_15[['Student',
|
43 |
net = Network()
|
44 |
-
|
45 |
-
node_roles = {}
|
46 |
-
node_colors = {}
|
47 |
|
48 |
|
49 |
for _, row in edge_15.iterrows():
|
50 |
source = row['Teacher']
|
51 |
target = row['Student']
|
52 |
-
attribute_value = row[
|
53 |
edge_color = value_to_hex(attribute_value)
|
54 |
-
hadith_count = teacher_hadiths[teacher_hadiths['Teacher'] == source][
|
55 |
-
student_count = student_hadiths[student_hadiths['Student'] == target][
|
56 |
edge_color = value_to_hex(attribute_value)
|
57 |
|
58 |
net.add_node(source, color=value_to_hex(hadith_count), font = {'size':30, 'color': 'orange'}, label = f"{source}\nHadiths: {hadith_count}")
|
@@ -73,10 +72,11 @@ def network_visualizer(city, year, num_nodes):
|
|
73 |
|
74 |
|
75 |
with gr.Blocks() as demo:
|
|
|
76 |
Places = gr.Dropdown(choices = cities, value = 'المدينه', label = 'Location')
|
77 |
Last_Year = gr.Slider(min_year, max_year, value = 9, label = 'End', info = 'Choose the year to display Narrators')
|
78 |
num_narrators = gr.Slider(0, 700, value = 400, label = 'Narrators', info = 'Choose the number of Narrators to display')
|
79 |
|
80 |
btn = gr.Button('Submit')
|
81 |
-
btn.click(fn = network_visualizer, inputs = [Places, Last_Year, num_narrators], outputs = gr.HTML())
|
82 |
demo.launch()
|
|
|
32 |
return dataframe
|
33 |
|
34 |
|
35 |
+
def network_visualizer(yaxis, city, year, num_nodes):
|
36 |
+
edges = splitIsnad(subsetEdges(city, year))[['Teacher', 'Student', yaxis]].reset_index()
|
37 |
+
#.groupby(['Teacher', 'Student']).sum()
|
38 |
if edges.shape[0] > num_nodes:
|
39 |
edge_15 = edges.sample(num_nodes)
|
40 |
else:
|
41 |
edge_15 = edges.copy()
|
42 |
+
teacher_hadiths = edge_15[['Teacher', yaxis]].groupby('Teacher').sum().reset_index()
|
43 |
+
student_hadiths = edge_15[['Student', yaxis]].groupby('Student').sum().reset_index()
|
44 |
net = Network()
|
45 |
+
|
|
|
|
|
46 |
|
47 |
|
48 |
for _, row in edge_15.iterrows():
|
49 |
source = row['Teacher']
|
50 |
target = row['Student']
|
51 |
+
attribute_value = row[yaxis]
|
52 |
edge_color = value_to_hex(attribute_value)
|
53 |
+
hadith_count = teacher_hadiths[teacher_hadiths['Teacher'] == source][yaxis].to_list()[0]
|
54 |
+
student_count = student_hadiths[student_hadiths['Student'] == target][yaxis].to_list()[0]
|
55 |
edge_color = value_to_hex(attribute_value)
|
56 |
|
57 |
net.add_node(source, color=value_to_hex(hadith_count), font = {'size':30, 'color': 'orange'}, label = f"{source}\nHadiths: {hadith_count}")
|
|
|
72 |
|
73 |
|
74 |
with gr.Blocks() as demo:
|
75 |
+
Yaxis = gr.Dropdown(choices = ['Taraf', 'Hadith', 'Isnad'], value = 'Taraf', label = 'Variable to Display', info = 'Choose the variable to visualize.')
|
76 |
Places = gr.Dropdown(choices = cities, value = 'المدينه', label = 'Location')
|
77 |
Last_Year = gr.Slider(min_year, max_year, value = 9, label = 'End', info = 'Choose the year to display Narrators')
|
78 |
num_narrators = gr.Slider(0, 700, value = 400, label = 'Narrators', info = 'Choose the number of Narrators to display')
|
79 |
|
80 |
btn = gr.Button('Submit')
|
81 |
+
btn.click(fn = network_visualizer, inputs = [Yaxis, Places, Last_Year, num_narrators], outputs = gr.HTML())
|
82 |
demo.launch()
|