FDSRashid commited on
Commit
d5207f2
·
verified ·
1 Parent(s): 02d71bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -31
app.py CHANGED
@@ -120,37 +120,37 @@ def taraf_booknum(taraf_num):
120
  taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
121
  return taraf[['matn', 'Book ID', 'Hadith Number']]
122
 
123
- def visualize_subTaraf(df):
124
- df['bookid_hadithid'] = df['Book ID'].astype(str) + '_' + df['Hadith Number'].astype(str)
125
- hadith = matn_info[matn_info['bookid_hadithid'].isin(df['bookid_hadithid'])]
126
- taraf_hadith_split = [i.split('_') for i in hadith['bookid_hadithid'].to_list()]
127
- hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split))
128
- isnad_hadith = isnad_info[hadith_cleaned][['Source', 'Destination']]
129
- narrators = isnad_hadith.applymap(lambda x: narrator_bios[narrator_bios['Rawi ID'] == int(x)]['Famous Name'].to_list()).rename(columns={"Source": "Teacher", "Destination": "Student"})
130
- isnad_hadith["Student"] = narrators['Student']
131
- isnad_hadith["Teacher"] = narrators['Teacher']
132
- filtered = isnad_hadith[(isnad_hadith['Teacher'].apply(lambda x: len(x)) == 1) & (isnad_hadith['Student'].apply(lambda x: len(x)) == 1)]
133
- filtered['Student'] = filtered['Student'].apply(lambda x: x[0])
134
- filtered['Teacher'] = filtered['Teacher'].apply(lambda x: x[0])
135
- net = Network(directed =True)
136
- for _, row in filtered.iterrows():
137
- source = row['Teacher']
138
- target = row['Student']
139
- teacher_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Source'])]
140
- student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
141
- isnad = isnad_info[(isnad_info['Source'] == row['Source']) & (isnad_info['Destination'] == row['Destination'])]
142
- teacher_narrations = teacher_info['Number of Narrations'].to_list()[0]
143
- student_narrations = student_info['Number of Narrations'].to_list()[0]
144
- if row['Source'] == '99999':
145
- net.add_node(source, font = {'size':50, 'color': 'Black'}, color = '#000000')
146
- else:
147
- net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{source} \n {teacher_info["Narrator Rank"].to_list()[0]}')
148
- net.add_node(target, font = {'size': 30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{target} \n{student_info["Narrator Rank"].to_list()[0]}')
149
- net.add_edge(source, target, color = value_to_hex(int(isnad[f'{yaxis} Count'].to_list()[0])), label = f"{isnad[f'{yaxis} Count'].to_list()[0]}")
150
- net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
151
- html = net.generate_html()
152
- html = html.replace("'", "\"")
153
- return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
154
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
155
  allow-scripts allow-same-origin allow-popups
156
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""
 
120
  taraf = matn_info[matn_info['taraf_ID'] == taraf_num]
121
  return taraf[['matn', 'Book ID', 'Hadith Number']]
122
 
123
+ def visualize_subTaraf(df):
124
+ df['bookid_hadithid'] = df['Book ID'].astype(str) + '_' + df['Hadith Number'].astype(str)
125
+ hadith = matn_info[matn_info['bookid_hadithid'].isin(df['bookid_hadithid'])]
126
+ taraf_hadith_split = [i.split('_') for i in hadith['bookid_hadithid'].to_list()]
127
+ hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split))
128
+ isnad_hadith = isnad_info[hadith_cleaned][['Source', 'Destination']]
129
+ narrators = isnad_hadith.applymap(lambda x: narrator_bios[narrator_bios['Rawi ID'] == int(x)]['Famous Name'].to_list()).rename(columns={"Source": "Teacher", "Destination": "Student"})
130
+ isnad_hadith["Student"] = narrators['Student']
131
+ isnad_hadith["Teacher"] = narrators['Teacher']
132
+ filtered = isnad_hadith[(isnad_hadith['Teacher'].apply(lambda x: len(x)) == 1) & (isnad_hadith['Student'].apply(lambda x: len(x)) == 1)]
133
+ filtered['Student'] = filtered['Student'].apply(lambda x: x[0])
134
+ filtered['Teacher'] = filtered['Teacher'].apply(lambda x: x[0])
135
+ net = Network(directed =True)
136
+ for _, row in filtered.iterrows():
137
+ source = row['Teacher']
138
+ target = row['Student']
139
+ teacher_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Source'])]
140
+ student_info = narrator_bios[narrator_bios['Rawi ID'] == int(row['Destination'])]
141
+ isnad = isnad_info[(isnad_info['Source'] == row['Source']) & (isnad_info['Destination'] == row['Destination'])]
142
+ teacher_narrations = teacher_info['Number of Narrations'].to_list()[0]
143
+ student_narrations = student_info['Number of Narrations'].to_list()[0]
144
+ if row['Source'] == '99999':
145
+ net.add_node(source, font = {'size':50, 'color': 'Black'}, color = '#000000')
146
+ else:
147
+ net.add_node(source, font = {'size':30, 'color': 'red'}, color = value_to_hex(teacher_narrations), label = f'{source} \n {teacher_info["Narrator Rank"].to_list()[0]}')
148
+ net.add_node(target, font = {'size': 30, 'color': 'red'}, color = value_to_hex(student_narrations), label = f'{target} \n{student_info["Narrator Rank"].to_list()[0]}')
149
+ net.add_edge(source, target, color = value_to_hex(int(isnad[f'{yaxis} Count'].to_list()[0])), label = f"{isnad[f'{yaxis} Count'].to_list()[0]}")
150
+ net.barnes_hut(gravity=-5000, central_gravity=0.3, spring_length=200)
151
+ html = net.generate_html()
152
+ html = html.replace("'", "\"")
153
+ return f"""<iframe style="width: 100%; height: 600px;margin:0 auto" name="result" allow="midi; geolocation; microphone; camera;
154
  display-capture; encrypted-media;" sandbox="allow-modals allow-forms
155
  allow-scripts allow-same-origin allow-popups
156
  allow-top-navigation-by-user-activation allow-downloads" allowfullscreen=""