File size: 4,422 Bytes
d0e2dd3 571f610 d0e2dd3 2614445 16f5643 2614445 d0e2dd3 0d0068a d0e2dd3 e857199 d0e2dd3 87bc78a 9e2e2cc d0e2dd3 d16ee04 0d0068a d16ee04 0d0068a 4842f46 87bc78a cc1f78a 0d0068a 0068ac0 d0e2dd3 2b179f3 5c2a2d9 9ce7800 d0e2dd3 2614445 87bc78a d0e2dd3 65580f0 d0e2dd3 2479bc9 4842f46 8e1ef87 87bc78a d0e2dd3 2479bc9 d0e2dd3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import gradio as gr
import pyarabic.araby as araby
import numpy as np
import pandas as pd
import os
from datasets import load_dataset
from datasets import Features
from datasets import Value
from datasets import Dataset
import matplotlib.pyplot as plt
css = """
.table-wrap {
min-height: 200px;
max-height: 200px;
}
"""
Secret_token = os.getenv('HF_Token')
edge_info = load_dataset('FDSRashid/hadith_info',token = Secret_token, data_files = 'isnad_info.csv', split = 'train').to_pandas()
lst = ['Rawi ID',
'Gender',
'Official Name',
'Famous Name',
'Title Name',
'Kunya',
'Laqab',
'Occupation',
'Wasf',
'Madhhab',
'Nasab',
'Narrator Rank',
'Generation',
'Birth Date',
'Death Date',
'Age',
'Place of Stay',
'Place of Death',
'Mawla Relation',
'Famous Relatives',
'Number of Narrations',
'Avg. Death Date',
'Whole Number Death']
dct = {}
for itrm in lst:
dct[itrm] = Value('string')
dct['Rawi ID'] = Value('int32')
features = Features(dct)
#features = Features({'Rawi ID': Value('int32'), 'Famous Name': Value('string'), 'Narrator Rank': Value('string'), 'Number of Narrations': Value('string'), 'Official Name':Value('string'), 'Title Name':Value('string'), 'Generation': Value('string')} )
narrator_bios = load_dataset("FDSRashid/hadith_info", data_files = 'Teacher_Bios.csv', token = Secret_token,features=features )
narrator_bios = narrator_bios['train'].to_pandas()
narrator_bios.loc[49845, 'Narrator Rank'] = 'ุฑุณูู ุงููู'
narrator_bios.loc[49845, 'Number of Narrations'] = 0
narrator_bios['Number of Narrations'] = narrator_bios['Number of Narrations'].astype(int)
narrator_bios.loc[49845, 'Number of Narrations'] = 22000
narrator_bios['Generation'] = narrator_bios['Generation'].replace([None], [-1])
narrator_bios['Generation'] = narrator_bios['Generation'].astype(int)
def get_node_info(node):
node_info = narrator_bios[narrator_bios['Rawi ID'] == int(node)]
# Extract values with defaults, using `.iloc` if available, otherwise default
student_narrations = node_info['Number of Narrations'].iloc[0] if not node_info.empty else 1
student_gen = node_info['Generation'].iloc[0] if not node_info.empty else -1
student_rank = node_info['Narrator Rank'].iloc[0] if not node_info.empty else 'ููุงู'
node_name = node_info['Famous Name'].iloc[0] if not node_info.empty else 'ููุงู'
return node_info,student_narrations,student_gen, student_rank, node_name
def network_narrator(narrator_id):
edge_narrator = edge_info[(edge_info['Source'] == str(narrator_id)) | (edge_info['Destination'] == str(narrator_id))]
edge_full = edge_narrator[['Taraf Count', 'Hadith Count', 'Isnad Count', 'Source', 'Book Count', 'Destination']]
edge_full['Teacher'] = edge_full['Source'].apply(lambda x: get_node_info(x)[-1] )
edge_full['Student'] = edge_full['Destination'].apply(lambda x: get_node_info(x)[-1] )
return edge_full.rename(columns = {'Taraf Count': 'Tarafs', 'Hadith Count':'Hadiths', 'Isnad Count':'Isnads', 'Book Count':'Books'})
def narrator_retriever(name):
if 'ALL' in name or 'all' in name:
return narrator_bios
else:
full_names = name.replace(', ', '|').replace(',', '|')
return narrator_bios[(narrator_bios['Official Name'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)) | (narrator_bios['Famous Name'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)) | (narrator_bios['Rawi ID'].astype(str).isin(full_names.split('|'))) | (narrator_bios['Kunya'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)) | ((narrator_bios['Laqab'].apply(lambda x: araby.strip_diacritics(x)).str.contains(araby.strip_diacritics(name), regex=True)))]
with gr.Blocks(css=css) as demo:
gr.Markdown("Search Narrators using this tool or Retrieve Transmissions involving Narrator")
with gr.Tab("Search Narrator"):
text_input = gr.Textbox()
text_output = gr.DataFrame()
text_button = gr.Button("Search")
text_button.click(narrator_retriever, inputs=text_input, outputs=text_output)
with gr.Tab("View Network"):
image_input = gr.Number()
image_button = gr.Button("Retrieve!")
image_button.click(network_narrator, inputs=[image_input], outputs=[gr.DataFrame(wrap=True)])
demo.launch()
|