Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
import numpy as np | |
import gradio | |
import os | |
import pandas as pd | |
from datasets import load_dataset | |
import plotly.express as px | |
Secret_token = os.getenv('token') | |
dataset = load_dataset("FDSRashid/taraf_by_year", token = Secret_token,split="train") | |
taraf_s = dataset.to_pandas() | |
taraf_s = taraf_s.sort_values(['City', 'Year'], ascending=True) | |
cities = taraf_s['City'].unique().tolist() | |
min_year = int(taraf_s['Year'].min()) | |
max_year = int(taraf_s['Year'].max()) | |
def plot_timeline(yaxis, citi = ['المدينه', 'بغداد', 'كوفة', 'بصرة'], min_year = 0, max_year = 400): | |
if min_year >= max_year: | |
raise gr.error('Min Year Cannot be Bigger than Max Year!') | |
filtered = taraf_s[taraf_s['City'].isin(citi) & (taraf_s['Year'] >= min_year) & (taraf_s['Year'] <= max_year)] | |
fig = px.line(data_frame = filtered, x = 'Year', y = yaxis, title = "Tarafs per Year", color = 'City' ) | |
fig.update_layout(title_font_color = 'red', title_x = .5) | |
return fig | |
app = gradio.Interface(plot_timeline, | |
[gradio.Dropdown(choices = ['Taraf', 'Hadith', 'Isnad', 'Ranking'], value = 'Taraf', label = 'Y Axis'), gradio.Dropdown(choices = cities, value = ['المدينه', 'بغداد', 'كوفة', 'بصرة'], multiselect=True), | |
gradio.Slider(min_year, max_year, value = 0, label = 'Begining', info = 'Choose the first year to display Tarafs'), | |
gradio.Slider(min_year, max_year, value = 400, label = 'End', info = 'Choose the last year to display Tarafs') | |
], | |
gradio.Plot()).launch() |