Spaces:
Sleeping
Sleeping
File size: 1,960 Bytes
5046606 3fcd866 5046606 a7b34d0 dcda834 ced084d dcda834 1891607 ffaaf4c 3fcd866 d885298 0d7cef9 3fcd866 7f9027d 3fcd866 83e1bac 50a580c 83e1bac 0d7cef9 e185680 83e1bac a4a0168 0d7cef9 e185680 dcda834 54dac96 ffaaf4c d885298 ffaaf4c d885298 0d7cef9 |
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 |
import numpy as np
import gradio as gr
import os
import pandas as pd
from datasets import load_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())
def subset_city_year(city, year1, year2):
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 , year):
try:
df = subset_city_year(city, year)
narrators = edge_info[edge_info['Edge_ID'].isin(df['ID'])]
fixed = narrators['Edge_Name'].reset_index()
return splitIsnad(fixed)[['Teacher', 'Student']]
except Exception as e:
return str(e)
with gr.Blocks() as demo:
Places = gr.Dropdown(choices = cities, 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() |