File size: 3,440 Bytes
d0e2dd3 571f610 d0e2dd3 e857199 d0e2dd3 87bc78a 9e2e2cc d0e2dd3 4842f46 d0e2dd3 87bc78a 2f8e2f5 f21664b 87bc78a d0e2dd3 5c2a2d9 d0e2dd3 87bc78a 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 |
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
Secret_token = os.getenv('HF_Token')
dataset = load_dataset('FDSRashid/hadith_info',data_files = 'Basic_Edge_Information.csv', token = Secret_token, split = 'train')
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)
edge_info = dataset.to_pandas()
def splitIsnad(dataframe):
teacher_student =dataframe['Edge_Name'].str.split(' TO ')
dataframe['Teacher'] = teacher_student.apply(lambda x: x[0])
dataframe['Student'] = teacher_student.apply(lambda x: x[1])
return dataframe
def network_narrator(narrator_id):
edge_narrator = edge_info[(edge_info['Teacher_ID'] == narrator_id) | (edge_info['Student_ID'] == narrator_id)]
edge_full = splitIsnad(edge_narrator[['Tarafs', 'Hadiths', 'Isnads', 'Edge_Name', 'Books']]).drop(['Edge_Name'], axis=1)
return edge_full
def narrator_retriever(name):
if '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('|')))]
with gr.Blocks() 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()
|