Spaces:
Sleeping
Sleeping
import gradio as gr | |
import json | |
def regions_list(): | |
with open('regions.json', 'r') as f: | |
regions = json.load(f) | |
reg_name = [(i['name_uz'], i['id']) for i in regions] | |
reg_tuple = [tuple(reg_name[k]) for k in range(len(reg_name))] | |
return reg_tuple | |
def district_list(): | |
with open('districts.json', 'r') as f: | |
districts = json.load(f) | |
dis_name = [(i['name_uz'], i['region_id']) for i in districts] | |
dis_tuple = [tuple(dis_name[k]) for k in range(len(dis_name))] | |
return dis_tuple | |
def get_district(reg_ch): | |
newDList = [i for i in district_list() if i[1]==reg_ch] | |
return dict(newDList) | |
with gr.Blocks() as iface: | |
gr.Markdown("""# Region lists""") | |
with gr.Row(): | |
inp=gr.Dropdown(choices=regions_list(), label="Region") | |
out=gr.Label(label='Tanlovlar') | |
theme='gradio/seafoam' | |
inp.change(fn=get_district, inputs=inp, outputs=out) | |
if __name__=="__main__": | |
iface.launch(debug=True) | |