Spaces:
Sleeping
Sleeping
| import numpy as np | |
| import gradio as gr | |
| import os | |
| import pandas as pd | |
| from datasets import load_dataset | |
| from datasets import load_dataset | |
| from datasets import Features | |
| from datasets import Value | |
| from datasets import Dataset | |
| Secret_token = os.getenv('token') | |
| dataset = load_dataset('FDSRashid/hadith_info',data_files = 'Basic_Edge_Information.csv', token = Secret_token, split = 'train') | |
| dataset2 = load_dataset('FDSRashid/hadith_info',data_files = 'Taraf_Info.csv', token = Secret_token, split = 'train') | |
| edge_info = dataset.to_pandas() | |
| taraf_info = dataset2.to_pandas() | |
| cities = taraf_info['City'].unique().tolist() | |
| min_year = int(taraf_info['Year'].min()) | |
| max_year = int(taraf_info['Year'].max()) | |
| features = Features({'Rawi ID': Value('int32'), 'Famous Name': Value('string'), 'Narrator Rank': Value('string'), 'Number of Narrations': 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'] = narrator_bios['Number of Narrations'].sum() | |
| def subset_city_year(city, year1, year2): | |
| if 'All' in city: | |
| edges = taraf_info[(taraf_info['Year'] >= year1) & (taraf_info['Year'] <= year2)] | |
| else: | |
| edges = taraf_info[(taraf_info['Year'] >= year1) & (taraf_info['City'].isin(city)) & (taraf_info['Year'] <= year2)] | |
| return edges | |
| def subset_year(year = 50): | |
| edges = taraf_info[(taraf_info['Year'] == year)] | |
| return edges | |
| 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 get_narrators( city , year1, year2): | |
| try: | |
| df = subset_city_year(city, year1, year2) | |
| narrators = edge_info[edge_info['Edge_ID'].isin(df['ID'])] | |
| fixed = splitIsnad(narrators) | |
| fixed['Teacher Reports'] = fixed['Teacher_ID'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID']== x]['Number of Narrations'].to_list()[0]) | |
| fixed['Student Reports'] = fixed['Student_ID'].apply(lambda x: narrator_bios[narrator_bios['Rawi ID']== x]['Number of Narrations'].to_list()[0]) | |
| return fixed[['Teacher', 'Student', 'Teacher Reports', 'Student Reports', 'Isnads', 'Hadiths', 'Tarafs', 'Books']] | |
| except Exception as e: | |
| return str(e) | |
| with gr.Blocks() as demo: | |
| Places = gr.Dropdown(choices = cities + ['All'], value = ['المدينه', 'بغداد', 'كوفة', 'بصرة'], multiselect=True, label = 'Location') | |
| First_Year = gr.Slider(min_year, max_year, value = 10, label = 'Begining', info = 'Choose the first year to display Narrators') | |
| Last_Year = gr.Slider(min_year, max_year, value = 50, label = 'End', info = 'Choose the Last year to display Narrators') | |
| btn = gr.Button('Submit') | |
| btn.click(fn = get_narrators, inputs = [Places, First_Year, Last_Year], outputs = gr.DataFrame()) | |
| demo.launch() |