SIUBIU commited on
Commit
164398f
1 Parent(s): 281597f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +171 -171
app.py CHANGED
@@ -1,171 +1,171 @@
1
- import gradio as gr
2
- from suggestion import generate_outfit_advice
3
- from clothGen import cloth_gen
4
- from user_dress import user_cloths
5
- import requests
6
- import os
7
- from io import BytesIO
8
- from PIL import Image
9
- from cal_compatibility import cal_compatibility
10
-
11
-
12
- gen_pic_num = 6
13
-
14
-
15
- def get_select_index(evt: gr.SelectData, gallery):
16
- print(gallery[evt.index][0])
17
- # response = requests.get(gallery[evt.index][0])
18
- # img = Image.open(BytesIO(response.content))
19
- return gallery[evt.index][0]
20
-
21
-
22
- def update_choices(dropout1, dropout2,):
23
- if dropout1 == "男":
24
- option = ['倒三角形', '矩形', '苹果形', '沙漏型', '胖型']
25
- else:
26
- option = ["梨形", "草莓形", "沙漏形", "标准", "苹果形"]
27
- dropout2 = gr.Dropdown(choices=option)
28
- return dropout2
29
-
30
-
31
- with gr.Blocks(css="styles.css", theme=gr.themes.Base()) as demo:
32
- with gr.Row():
33
- # 左侧模块
34
- with gr.Column(scale=1):
35
- with gr.Row():
36
- gr.Markdown(""
37
- "# 用户信息"
38
- "")
39
- with gr.Row():
40
- text_input1 = gr.Textbox(label="用户姓名", min_width=100)
41
- text_input2 = gr.Textbox(label="身高/cm", min_width=100)
42
- text_input3 = gr.Textbox(label="体重/kg", min_width=100)
43
- text_input4 = gr.Textbox(label="腰围/cm", min_width=100)
44
- text_input5 = gr.Textbox(label="胸围/cm", min_width=100)
45
- text_input6 = gr.Textbox(label="臀围/cm", min_width=100)
46
- text_input7 = gr.Textbox(label="肩宽/cm", min_width=100)
47
- text_input8 = gr.Textbox(label="腿长/cm", min_width=100)
48
- text_input9 = gr.Textbox(label="臂长/cm", min_width=100)
49
- dropdown_options1 = ["男", "女"]
50
- dropdown_input1 = gr.Dropdown(choices=dropdown_options1, label="性别", min_width=100)
51
- dropdown_input2 = gr.Dropdown(choices=[], label="体型分类", min_width=100)
52
- dropdown_input1.change(fn=update_choices, inputs=[dropdown_input1, dropdown_input2], outputs=dropdown_input2)
53
- dropdown_options3 = ["浅色", "中等偏黄色", "中等偏褐色", "深色"]
54
- dropdown_input3 = gr.Dropdown(choices=dropdown_options3, label="肤色", min_width=100)
55
- text_input10 = gr.Textbox(label="穿衣风格偏好", min_width=1000)
56
- text_input11 = gr.Textbox(label="生话方式和场景需求", min_width=1000)
57
- text_input12 = gr.Textbox(label="其他特殊需求", min_width=1000)
58
- with gr.Row():
59
- user_pic = gr.Image(label="用户照片", value="model.jpg", height=550, width=300)
60
-
61
- # 右侧模块
62
- with gr.Column(scale=2):
63
- with gr.Row():
64
- gr.Markdown(""
65
- "# 穿搭建议"
66
- "")
67
- with gr.Row():
68
- text_output1 = gr.Textbox(label="穿搭建议", lines=12, max_lines=12, interactive=False, show_label=False,
69
- min_width=1000)
70
- submit_button_1 = gr.Button("AI智能分析,生成穿搭建议", min_width=1000)
71
- image_output_1 = gr.Image(label="显示图像", value="image 209.png")
72
-
73
- gallery_1 = gr.Gallery(
74
- label="服装", elem_id="gallery",
75
- value=[
76
- # os.path.join(example_path, '上衣/_WEB_2016_09_26__2016092617451357e8ee2957aa1_TD.jpg'),
77
- # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717211057ea3a069c749_TD.jpg'),
78
- # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717391657ea3e446ce3f_TD.jpg'),
79
- # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717573057ea428a305bc_TD.jpg'),
80
- # os.path.join(example_path, '上衣/_WEB_2016_09_28__2016092810150157eb27a56a631_TD.jpg'),
81
- # os.path.join(example_path, '上衣/_WEB_2016_09_28__2016092810464557eb2f15e1df3_TD.jpg'),
82
- ],
83
- columns=[4], rows=[2], object_fit="contain", height=250, min_width=450)
84
-
85
- gallery_3 = gr.Gallery(
86
- label="配饰", elem_id="gallery",
87
- value=[
88
- 'downloads/access_1.jpg',
89
- 'downloads/access_2.jpg',
90
- 'downloads/access_3.jpg',
91
- 'downloads/access_4.jpg',
92
- 'downloads/access_5.jpg',
93
- 'downloads/access_6.jpg',
94
- ],
95
- columns=[4], rows=[2], object_fit="contain", height=250, min_width=450)
96
- submit_button_2 = gr.Button("AI智能分析,生成民族服饰")
97
-
98
- with gr.Column(scale=2):
99
- with gr.Row():
100
- gr.Markdown(""
101
- "# 搭配生成"
102
- "")
103
- with gr.Row():
104
- gallery_4 = gr.Gallery(
105
- label="套装", elem_id="gallery",
106
- value=[],
107
- columns=[3], rows=[1], object_fit="contain", height=180, min_width=450)
108
- with gr.Row():
109
- submit_button_3 = gr.Button("服饰及搭配兼容性排序")
110
- with gr.Row():
111
- image_output_5 = gr.Image(label="显示图像", show_label=False, min_width=200, height=350)
112
- intro = gr.Textbox(label="服饰介绍", lines=14, max_lines=14)
113
- with gr.Row():
114
- submit_button_4 = gr.Button("虚拟试穿")
115
- with gr.Row():
116
- with gr.Column(scale=1):
117
- gallery_user = gr.Gallery(
118
- label="试穿结果",
119
- elem_id="gallery",
120
- value=[],
121
- columns=[3], rows=[2],
122
- object_fit="contain",
123
- min_width=200,
124
- height=350,
125
- )
126
- with gr.Column(scale=1):
127
- feedback = gr.Textbox(label="反馈", placeholder="可以从款式、颜色、图案、风格倾向、文化偏好角度进行反馈", lines=1,
128
- max_lines=1, elem_id="feedback")
129
- submit_button_5 = gr.Button("反馈")
130
- with gr.Row():
131
- gr.Markdown("""
132
- 女性体型备注:
133
- 1. **梨形身材**:臀围比胸围**至少大5.08厘米**
134
- 2. **草莓形身材**:臀围比胸围**至少小5.08厘米**
135
- 3. **沙漏形身材**:胸围比腰围**至少大3.81厘米**且腰部线条明显
136
- 4. **标准身材**:胸围比腰围**至少大3.81厘米**且腰部线条不明显
137
- 5. **苹果形身材**:胸围比腰围**至少小3.81厘米**
138
-
139
- 男性体型备注:
140
- 1. **倒三角形身材**:肩宽比腰围**至少大10厘米**
141
- 2. **矩形身材**:肩宽与腰围的差异**小于5厘米**
142
- 3. **苹果形身材**:腰围比肩宽**至少大7.5厘米**
143
- 4. **沙漏型身材**:腰围比肩宽或臀围**至少小10厘米**,且肩宽和臀围的差异**小于5厘米**
144
- 5. **胖型身材**:腰围比胸围或肩宽**至少大10厘米**
145
- """)
146
-
147
- submit_button_1.click(fn=generate_outfit_advice,
148
- inputs=[text_input1, text_input2, text_input3, text_input4, text_input5,
149
- text_input6, text_input7, text_input8, text_input9, dropdown_input1,
150
- dropdown_input2, dropdown_input3, text_input10, text_input11, text_input12,
151
- feedback, user_pic],
152
- outputs=text_output1)
153
- submit_button_2.click(fn=cloth_gen,
154
- inputs=[text_output1, dropdown_input1],
155
- outputs=[gallery_1, image_output_5, intro])
156
-
157
- gallery_1.select(get_select_index, gallery_1, image_output_5)
158
- submit_button_3.click(fn=cal_compatibility,
159
- inputs=[],
160
- outputs=[gallery_4])
161
- submit_button_4.click(fn=user_cloths,
162
- inputs=[user_pic, image_output_5],
163
- outputs=gallery_user)
164
- submit_button_5.click(fn=generate_outfit_advice,
165
- inputs=[text_input1, text_input2, text_input3, text_input4, text_input5,
166
- text_input6, text_input7, text_input8, text_input9, dropdown_input1,
167
- dropdown_input2, dropdown_input3, text_input10, text_input11, text_input12,
168
- feedback, user_pic],
169
- outputs=text_output1)
170
-
171
- demo.launch(server_port=7860, share=True)
 
1
+ import gradio as gr
2
+ from suggestion import generate_outfit_advice
3
+ from clothGen import cloth_gen
4
+ from user_dress import user_cloths
5
+ import requests
6
+ import os
7
+ from io import BytesIO
8
+ from PIL import Image
9
+ from cal_compatibility import cal_compatibility
10
+
11
+
12
+ gen_pic_num = 6
13
+
14
+
15
+ def get_select_index(evt: gr.SelectData, gallery):
16
+ print(gallery[evt.index][0])
17
+ # response = requests.get(gallery[evt.index][0])
18
+ # img = Image.open(BytesIO(response.content))
19
+ return gallery[evt.index][0]
20
+
21
+
22
+ def update_choices(dropout1, dropout2,):
23
+ if dropout1 == "男":
24
+ option = ['倒三角形', '矩形', '苹果形', '沙漏型', '胖型']
25
+ else:
26
+ option = ["梨形", "草莓形", "沙漏形", "标准", "苹果形"]
27
+ dropout2 = gr.Dropdown(choices=option)
28
+ return dropout2
29
+
30
+
31
+ with gr.Blocks(css="styles.css", theme=gr.themes.Base()) as demo:
32
+ with gr.Row():
33
+ # 左侧模块
34
+ with gr.Column(scale=1):
35
+ with gr.Row():
36
+ gr.Markdown(""
37
+ "# 用户信息"
38
+ "")
39
+ with gr.Row():
40
+ text_input1 = gr.Textbox(label="用户姓名", min_width=100)
41
+ text_input2 = gr.Textbox(label="身高/cm", min_width=100)
42
+ text_input3 = gr.Textbox(label="体重/kg", min_width=100)
43
+ text_input4 = gr.Textbox(label="腰围/cm", min_width=100)
44
+ text_input5 = gr.Textbox(label="胸围/cm", min_width=100)
45
+ text_input6 = gr.Textbox(label="臀围/cm", min_width=100)
46
+ text_input7 = gr.Textbox(label="肩宽/cm", min_width=100)
47
+ text_input8 = gr.Textbox(label="腿长/cm", min_width=100)
48
+ text_input9 = gr.Textbox(label="臂长/cm", min_width=100)
49
+ dropdown_options1 = ["男", "女"]
50
+ dropdown_input1 = gr.Dropdown(choices=dropdown_options1, label="性别", min_width=100)
51
+ dropdown_input2 = gr.Dropdown(choices=['倒三角形', '矩形', '苹果形', '沙漏型', '胖型'], label="体型分类", min_width=100)
52
+ dropdown_input1.change(fn=update_choices, inputs=[dropdown_input1, dropdown_input2], outputs=dropdown_input2)
53
+ dropdown_options3 = ["浅色", "中等偏黄色", "中等偏褐色", "深色"]
54
+ dropdown_input3 = gr.Dropdown(choices=dropdown_options3, label="肤色", min_width=100)
55
+ text_input10 = gr.Textbox(label="穿衣风格偏好", min_width=1000)
56
+ text_input11 = gr.Textbox(label="生话方式和场景需求", min_width=1000)
57
+ text_input12 = gr.Textbox(label="其他特殊需求", min_width=1000)
58
+ with gr.Row():
59
+ user_pic = gr.Image(label="用户照片", value="model.jpg", height=550, width=300)
60
+
61
+ # 右侧模块
62
+ with gr.Column(scale=2):
63
+ with gr.Row():
64
+ gr.Markdown(""
65
+ "# 穿搭建议"
66
+ "")
67
+ with gr.Row():
68
+ text_output1 = gr.Textbox(label="穿搭建议", lines=12, max_lines=12, interactive=False, show_label=False,
69
+ min_width=1000)
70
+ submit_button_1 = gr.Button("AI智能分析,生成穿搭建议", min_width=1000)
71
+ image_output_1 = gr.Image(label="显示图像", value="image 209.png")
72
+
73
+ gallery_1 = gr.Gallery(
74
+ label="服装", elem_id="gallery",
75
+ value=[
76
+ # os.path.join(example_path, '上衣/_WEB_2016_09_26__2016092617451357e8ee2957aa1_TD.jpg'),
77
+ # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717211057ea3a069c749_TD.jpg'),
78
+ # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717391657ea3e446ce3f_TD.jpg'),
79
+ # os.path.join(example_path, '上衣/_WEB_2016_09_27__2016092717573057ea428a305bc_TD.jpg'),
80
+ # os.path.join(example_path, '上衣/_WEB_2016_09_28__2016092810150157eb27a56a631_TD.jpg'),
81
+ # os.path.join(example_path, '上衣/_WEB_2016_09_28__2016092810464557eb2f15e1df3_TD.jpg'),
82
+ ],
83
+ columns=[4], rows=[2], object_fit="contain", height=250, min_width=450)
84
+
85
+ gallery_3 = gr.Gallery(
86
+ label="配饰", elem_id="gallery",
87
+ value=[
88
+ 'downloads/access_1.jpg',
89
+ 'downloads/access_2.jpg',
90
+ 'downloads/access_3.jpg',
91
+ 'downloads/access_4.jpg',
92
+ 'downloads/access_5.jpg',
93
+ 'downloads/access_6.jpg',
94
+ ],
95
+ columns=[4], rows=[2], object_fit="contain", height=250, min_width=450)
96
+ submit_button_2 = gr.Button("AI智能分析,生成民族服饰")
97
+
98
+ with gr.Column(scale=2):
99
+ with gr.Row():
100
+ gr.Markdown(""
101
+ "# 搭配生成"
102
+ "")
103
+ with gr.Row():
104
+ gallery_4 = gr.Gallery(
105
+ label="套装", elem_id="gallery",
106
+ value=[],
107
+ columns=[3], rows=[1], object_fit="contain", height=180, min_width=450)
108
+ with gr.Row():
109
+ submit_button_3 = gr.Button("服饰及搭配兼容性排序")
110
+ with gr.Row():
111
+ image_output_5 = gr.Image(label="显示图像", show_label=False, min_width=200, height=350)
112
+ intro = gr.Textbox(label="服饰介绍", lines=14, max_lines=14)
113
+ with gr.Row():
114
+ submit_button_4 = gr.Button("虚拟试穿")
115
+ with gr.Row():
116
+ with gr.Column(scale=1):
117
+ gallery_user = gr.Gallery(
118
+ label="试穿结果",
119
+ elem_id="gallery",
120
+ value=[],
121
+ columns=[3], rows=[2],
122
+ object_fit="contain",
123
+ min_width=200,
124
+ height=350,
125
+ )
126
+ with gr.Column(scale=1):
127
+ feedback = gr.Textbox(label="反馈", placeholder="可以从款式、颜色、图案、风格倾向、文化偏好角度进行反馈", lines=1,
128
+ max_lines=1, elem_id="feedback")
129
+ submit_button_5 = gr.Button("反馈")
130
+ with gr.Row():
131
+ gr.Markdown("""
132
+ 女性体型备注:
133
+ 1. **梨形身材**:臀围比胸围**至少大5.08厘米**
134
+ 2. **草莓形身材**:臀围比胸围**至少小5.08厘米**
135
+ 3. **沙漏形身材**:胸围比腰围**至少大3.81厘米**且腰部线条明显
136
+ 4. **标准身材**:胸围比腰围**至少大3.81厘米**且腰部线条不明显
137
+ 5. **苹果形身材**:胸围比腰围**至少小3.81厘米**
138
+
139
+ 男性体型备注:
140
+ 1. **倒三角形身材**:肩宽比腰围**至少大10厘米**
141
+ 2. **矩形身材**:肩宽与腰围的差异**小于5厘米**
142
+ 3. **苹果形身材**:腰围比肩宽**至少大7.5厘米**
143
+ 4. **沙漏型身材**:腰围比肩宽或臀围**至少小10厘米**,且肩宽和臀围的差异**小于5厘米**
144
+ 5. **胖型身材**:腰围比胸围或肩宽**至少大10厘米**
145
+ """)
146
+
147
+ submit_button_1.click(fn=generate_outfit_advice,
148
+ inputs=[text_input1, text_input2, text_input3, text_input4, text_input5,
149
+ text_input6, text_input7, text_input8, text_input9, dropdown_input1,
150
+ dropdown_input2, dropdown_input3, text_input10, text_input11, text_input12,
151
+ feedback, user_pic],
152
+ outputs=text_output1)
153
+ submit_button_2.click(fn=cloth_gen,
154
+ inputs=[text_output1, dropdown_input1],
155
+ outputs=[gallery_1, image_output_5, intro])
156
+
157
+ gallery_1.select(get_select_index, gallery_1, image_output_5)
158
+ submit_button_3.click(fn=cal_compatibility,
159
+ inputs=[],
160
+ outputs=[gallery_4])
161
+ submit_button_4.click(fn=user_cloths,
162
+ inputs=[user_pic, image_output_5],
163
+ outputs=gallery_user)
164
+ submit_button_5.click(fn=generate_outfit_advice,
165
+ inputs=[text_input1, text_input2, text_input3, text_input4, text_input5,
166
+ text_input6, text_input7, text_input8, text_input9, dropdown_input1,
167
+ dropdown_input2, dropdown_input3, text_input10, text_input11, text_input12,
168
+ feedback, user_pic],
169
+ outputs=text_output1)
170
+
171
+ demo.launch(server_port=7860, share=True)