FDSRashid commited on
Commit
69e22b7
·
verified ·
1 Parent(s): cffe818

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -38,12 +38,18 @@ matn_info['taraf_ID'] = matn_info['taraf_ID'].replace('KeyAbsent', -1)
38
 
39
 
40
  matn_info['taraf_ID'] = matn_info['taraf_ID'].astype(int)
 
 
 
 
 
 
41
 
42
 
43
  isnad_info = load_dataset('FDSRashid/hadith_info',token = Secret_token, data_files = 'isnad_info.csv', split = 'train').to_pandas()
44
  isnad_info['Hadiths Cleaned'] = isnad_info['Hadiths'].apply(lambda x: [re.findall(pattern, string)[0].split("_") for string in x[1:-1].split(',')])
45
 
46
- tarafs = np.max(matn_info['taraf_ID'].unique())
47
 
48
  cmap = plt.colormaps['cool']
49
  def value_to_hex(value):
@@ -53,7 +59,7 @@ def value_to_hex(value):
53
  #edge_info, matn_info, narrator_bios, isnad_info
54
 
55
  def visualize_isnad(taraf_num, yaxis):
56
- taraf_hadith = matn_info[matn_info['taraf_ID'] == taraf_num]['bookid_hadithid'].to_list()
57
  taraf_hadith_split = [i.split('_') for i in taraf_hadith]
58
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split) )
59
  isnad_hadith = isnad_info[hadith_cleaned][['Source', 'Destination']]
@@ -92,7 +98,7 @@ def visualize_isnad(taraf_num, yaxis):
92
 
93
  with gr.Blocks() as demo:
94
  Yaxis = gr.Dropdown(choices = ['Tarafs', 'Hadiths', 'Isnads', 'Books'], value = 'Tarafs', label = 'Variable to Display', info = 'Choose the variable to visualize.')
95
- taraf_number = gr.Slider(1,tarafs , value=10000, label="Taraf", info="Choose the Taraf to Input", step = 1)
96
  btn = gr.Button('Submit')
97
  btn.click(fn = visualize_isnad, inputs = [taraf_number, Yaxis], outputs = gr.HTML())
98
  demo.launch()
 
38
 
39
 
40
  matn_info['taraf_ID'] = matn_info['taraf_ID'].astype(int)
41
+ matn_info = matn_info.sort_values('taraf_ID')
42
+ tarafs = matn_info['taraf_ID'].unique()
43
+ for i, taraf in enumerate(tarafs):
44
+ matn_info.loc[matn_info['taraf_ID'] == taraf, 'taraf_ID_New'] = i + 1 # Replace 'a' with 'e' in column 'C' where the condition is met
45
+ matn_info['taraf_ID_New'] = matn_info['taraf_ID_New'].astype(int)
46
+
47
 
48
 
49
  isnad_info = load_dataset('FDSRashid/hadith_info',token = Secret_token, data_files = 'isnad_info.csv', split = 'train').to_pandas()
50
  isnad_info['Hadiths Cleaned'] = isnad_info['Hadiths'].apply(lambda x: [re.findall(pattern, string)[0].split("_") for string in x[1:-1].split(',')])
51
 
52
+ taraf_max = np.max(matn_info['taraf_ID_New'].unique())
53
 
54
  cmap = plt.colormaps['cool']
55
  def value_to_hex(value):
 
59
  #edge_info, matn_info, narrator_bios, isnad_info
60
 
61
  def visualize_isnad(taraf_num, yaxis):
62
+ taraf_hadith = matn_info[matn_info['taraf_ID_New'] == taraf_num]['bookid_hadithid'].to_list()
63
  taraf_hadith_split = [i.split('_') for i in taraf_hadith]
64
  hadith_cleaned = isnad_info['Hadiths Cleaned'].apply(lambda x: any(i in x for i in taraf_hadith_split) )
65
  isnad_hadith = isnad_info[hadith_cleaned][['Source', 'Destination']]
 
98
 
99
  with gr.Blocks() as demo:
100
  Yaxis = gr.Dropdown(choices = ['Tarafs', 'Hadiths', 'Isnads', 'Books'], value = 'Tarafs', label = 'Variable to Display', info = 'Choose the variable to visualize.')
101
+ taraf_number = gr.Slider(1,taraf_max , value=10000, label="Taraf", info="Choose the Taraf to Input", step = 1)
102
  btn = gr.Button('Submit')
103
  btn.click(fn = visualize_isnad, inputs = [taraf_number, Yaxis], outputs = gr.HTML())
104
  demo.launch()