import subprocess import sys subprocess.check_call([sys.executable, "-m", "pip", "install", 'openpyxl']) import os import pandas as pd import gradio as gr type_list = ['اسپرت', 'راحتی', 'پوتون', 'طبی', 'گوندارا', 'کالج', 'مجلسی', 'دمپایی', 'پاشنه دار', 'تابستانه', 'جورابی'] color_list = ['مشکی', 'سفید', 'قهوه ای', 'کرمی', 'خاکستری', 'طوسی', 'سبز', 'آبی', 'رنگارنگ'] shoelace_list = ['کشی', 'چسب دار', 'بند دار', 'بدون بند', 'زیپ دار'] sex_list = ['بزرگسال', 'بزرگسال زنانه', 'بزرگسال مردانه', 'بچگانه', 'بچگانه دختر', 'بچگانه پسر'] sizes = [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] IMAGE_DIR = '/Img' root = os.path.dirname(__file__) shoes_data = pd.read_excel(os.path.join(root, 'Book1.xlsx')) # Read the shoe data from the Excel file def show_shoes(sizes, types, colors, shoelaces, genders): shoes_arr = [] selection = [list(map(int, sizes)), genders, colors, types, shoelaces] print(55555555555555555555555, selection) for i in range(len(shoes_data['code'].values)): Flag = True shoe_code,shoe_name,shoe_company,shoe_sizes,shoe_colors,shoe_shoelaces,shoe_sexes,shoe_types = shoes_data.iloc[i].values shoes = [shoe_sizes.split('-'), shoe_sexes.split('-'), shoe_colors.split('-'), shoe_types.split('-'), shoe_shoelaces.split('-')] for select_details, shoe_details in zip(selection, shoes): if not select_details: continue for shoe_d in shoe_details: if shoe_d not in select_details: Flag = False break if not Flag: break if Flag: # shoes_arr.append({'name': shoe_name, 'code': str(shoe_code), 'sizes': shoe_sizes, 'image_url': os.path.join(root,IMAGE_DIR,str(shoe_code)+'.jpg')}) print(shoe_sizes.split('-'), shoe_sexes.split('-'), shoe_colors.split('-'), shoe_types.split('-'), shoe_shoelaces.split('-'), os.path.join(root,IMAGE_DIR,str(shoe_code)+'.jpg')) shoes_arr.append(os.path.join(root,IMAGE_DIR,str(shoe_code)+'.jpg')) else: shoes.append({'name': '', 'code': '', 'sizes': [], 'image_url': './static/Images/Empty.jpg'}) return shoes_arr demo = gr.Interface( fn=show_shoes, inputs=[ gr.Dropdown(sizes, value=[42, 44], multiselect=True, label="sizes", info="Lor vel nisl."), gr.CheckboxGroup(type_list, label="types", info="Where are they from?"), gr.CheckboxGroup(color_list, label="colors", info="Where are they from?"), gr.CheckboxGroup(shoelace_list, label="shoelaces", info="Where are they from?"), gr.CheckboxGroup(sex_list, label="genders", info="Where are they from?"), ], outputs=gr.Gallery(label="Generated Images", columns=[2]), # examples=[ # [42, "cat", ["Japan", "Pakistan"], "park", ["ate", "swam"], True], # [4, "dog", ["Japan"], "zoo", ["ate", "swam"], False], # [10, "bird", ["USA", "Pakistan"], "road", ["ran"], False], # [8, "cat", ["Pakistan"], "zoo", ["ate"], True], # ] ) demo.launch()