Spaces:
Sleeping
Sleeping
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, year): | |
edges = taraf_info[(taraf_info['Year'] == year) & (taraf_info['City'].isin(city))] | |
return edges | |
def subset_year(year = 50): | |
edges = taraf_info[(taraf_info['Year'] == year)] | |
return edges | |
def get_narrators( city , year): | |
try: | |
df = subset_city_year(city, year) | |
narrators = edge_info[edge_info['Edge_ID'].isin(df['ID'])] | |
return narrators['Edge_Name'].reset_index().drop('index', axis = 1).rename(columns = {'Edge_Name': 'Teacher To Student'}) | |
except Exception as e: | |
return str(e) | |
with gr.Blocks() as demo: | |
Places = gr.Dropdown(choices = cities, value = ['المدينه', 'بغداد', 'كوفة', 'بصرة'], multiselect=True, label = 'Location') | |
Last_Year = gr.Slider(min_year, max_year, value = 50, label = 'End', info = 'Choose the year to display Narrators') | |
btn = gr.Button('Submit') | |
btn.click(fn = get_narrators, inputs = [Places, Last_Year], outputs = gr.DataFrame()) | |
demo.launch() |