File size: 3,284 Bytes
e240077
 
 
 
 
03f956d
c6f07c7
d855c8d
 
 
 
 
 
 
 
00c8a32
 
 
 
d855c8d
85d23e8
0e3442e
d855c8d
d038571
 
db87b9c
00c8a32
d038571
 
 
 
 
 
 
 
 
 
 
d855c8d
d038571
 
 
 
c6f07c7
00c8a32
d038571
 
 
 
d855c8d
 
d038571
 
d855c8d
 
 
 
 
 
d038571
d855c8d
 
 
 
 
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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

print(root, os.path.exists(os.path.join(root, 'Book1.xlsx')))
print(shoes_data)

def show_shoes(sizes, types, colors, shoelaces, genders):
    shoes_arr = []
    selection = [list(map(int, sizes)), genders, colors, types, shoelaces]
    print(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(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()