Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,27 @@ import numpy as np
|
|
| 5 |
import pandas as pd
|
| 6 |
import os
|
| 7 |
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
|
| 10 |
Secret_token = os.getenv('token')
|
| 11 |
|
| 12 |
dataset = load_dataset('FDSRashid/hadith_info',data_files = 'Basic_Edge_Information.csv', token = Secret_token, split = 'train')
|
| 13 |
dataset2 = load_dataset('FDSRashid/hadith_info',data_files = 'Taraf_Info.csv', token = Secret_token, split = 'train')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
edge_info = dataset.to_pandas()
|
| 15 |
taraf_info = dataset2.to_pandas()
|
| 16 |
cities = taraf_info['City'].unique().tolist()
|
|
@@ -33,14 +48,14 @@ def splitIsnad(dataframe):
|
|
| 33 |
|
| 34 |
|
| 35 |
def network_visualizer(yaxis, city, fstyear,lastyr, num_nodes):
|
| 36 |
-
edges =
|
|
|
|
| 37 |
#.groupby(['Teacher', 'Student']).sum()
|
| 38 |
-
if
|
| 39 |
-
edge_15 =
|
| 40 |
else:
|
| 41 |
-
edge_15 =
|
| 42 |
-
|
| 43 |
-
student_hadiths = edge_15[['Student', yaxis]].groupby('Student').sum().reset_index()
|
| 44 |
net = Network()
|
| 45 |
|
| 46 |
|
|
@@ -50,11 +65,12 @@ def network_visualizer(yaxis, city, fstyear,lastyr, num_nodes):
|
|
| 50 |
target = row['Student']
|
| 51 |
attribute_value = row[yaxis]
|
| 52 |
edge_color = value_to_hex(np.log10(attribute_value))
|
| 53 |
-
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
-
net.add_node(source, color=value_to_hex(
|
| 57 |
-
net.add_node(target, color=value_to_hex(
|
| 58 |
net.add_edge(source, target, color=edge_color, value=attribute_value, label = f"{source} to {target}\n{yaxis}: {attribute_value}")
|
| 59 |
|
| 60 |
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
import os
|
| 7 |
from datasets import load_dataset
|
| 8 |
+
from datasets import Features
|
| 9 |
+
from datasets import Value
|
| 10 |
+
from datasets import Dataset
|
| 11 |
import matplotlib.pyplot as plt
|
| 12 |
|
| 13 |
Secret_token = os.getenv('token')
|
| 14 |
|
| 15 |
dataset = load_dataset('FDSRashid/hadith_info',data_files = 'Basic_Edge_Information.csv', token = Secret_token, split = 'train')
|
| 16 |
dataset2 = load_dataset('FDSRashid/hadith_info',data_files = 'Taraf_Info.csv', token = Secret_token, split = 'train')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
features = Features({'Rawi ID': Value('int32'), 'Famous Name': Value('string'), 'Narrator Rank': Value('string'), 'Number of Narrations': Value('string')})
|
| 21 |
+
narrator_bios = load_dataset("FDSRashid/hadith_info", data_files = 'Teacher_Bios.csv', token = Secret_token,features=features )
|
| 22 |
+
narrator_bios = narrator_bios['train'].to_pandas()
|
| 23 |
+
narrator_bios.loc[49845, 'Narrator Rank'] = 'رسول الله'
|
| 24 |
+
narrator_bios.loc[49845, 'Number of Narrations'] = 0
|
| 25 |
+
narrator_bios['Number of Narrations'] = narrator_bios['Number of Narrations'].astype(int)
|
| 26 |
+
narrator_bios.loc[49845, 'Number of Narrations'] = narrator_bios['Number of Narrations'].sum()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
edge_info = dataset.to_pandas()
|
| 30 |
taraf_info = dataset2.to_pandas()
|
| 31 |
cities = taraf_info['City'].unique().tolist()
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def network_visualizer(yaxis, city, fstyear,lastyr, num_nodes):
|
| 51 |
+
edges = subsetEdges(city, fstyear, lastyr)
|
| 52 |
+
edges_split = splitIsnad(edges).reset_index()
|
| 53 |
#.groupby(['Teacher', 'Student']).sum()
|
| 54 |
+
if edges_split.shape[0] > num_nodes:
|
| 55 |
+
edge_15 = edges_split.sort_values(by=yaxis, ascending=False).head(num_nodes)
|
| 56 |
else:
|
| 57 |
+
edge_15 = edges_split.copy()
|
| 58 |
+
|
|
|
|
| 59 |
net = Network()
|
| 60 |
|
| 61 |
|
|
|
|
| 65 |
target = row['Student']
|
| 66 |
attribute_value = row[yaxis]
|
| 67 |
edge_color = value_to_hex(np.log10(attribute_value))
|
| 68 |
+
teacher_info = narrator_bios[narrator_bios['Rawi ID'] == row['Teacher_ID']]
|
| 69 |
+
student_info = narrator_bios[narrator_bios['Rawi ID'] == row['Student_ID']]
|
| 70 |
+
|
| 71 |
|
| 72 |
+
net.add_node(source, color=value_to_hex(teacher_info.loc[0, 'Number of Narrations']), font = {'size':30, 'color': 'orange'})#, label = f"{source}\n{yaxis}: {hadith_count}")
|
| 73 |
+
net.add_node(target, color=value_to_hex(student_info.loc[0, 'Number of Narrations']) , font = {'size': 20, 'color': 'red'})#, label = f"{target}\n{yaxis}: {student_count}")
|
| 74 |
net.add_edge(source, target, color=edge_color, value=attribute_value, label = f"{source} to {target}\n{yaxis}: {attribute_value}")
|
| 75 |
|
| 76 |
|