承弱 commited on
Commit
4ffefef
1 Parent(s): a48de31

update t2v

Browse files
.gitattributes CHANGED
@@ -36,4 +36,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
36
  *.ggml filter=lfs diff=lfs merge=lfs -text
37
  *.llamafile* filter=lfs diff=lfs merge=lfs -text
38
  test_imgs/* filter=lfs diff=lfs merge=lfs -text
39
- demo/gallery/* filter=lfs diff=lfs merge=lfs -text
 
 
 
36
  *.ggml filter=lfs diff=lfs merge=lfs -text
37
  *.llamafile* filter=lfs diff=lfs merge=lfs -text
38
  test_imgs/* filter=lfs diff=lfs merge=lfs -text
39
+ demo/gallery/* filter=lfs diff=lfs merge=lfs -text
40
+ resource/* filter=lfs diff=lfs merge=lfs -text
41
+ demo/style_img/* filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,13 +1,88 @@
1
  import cv2, os
2
  import gradio as gr
3
  import numpy as np
4
- from demo.generation import call_generation
5
- from demo.instructions import INSTRUCTIONS_VECTORIZE_SIMPLIFY
6
 
7
  VERSION = 'v0.1'
8
 
9
  GALLERY_LIST = [os.path.join('demo/gallery',path) for path in os.listdir('demo/gallery')]
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def resize_image(image, size):
13
  # find the minimal size of the image, resize it to size
@@ -55,6 +130,31 @@ def process_vector(input_image, upsample_method, svg_simplify, svg_optimize, tra
55
  return file_list
56
 
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
 
@@ -85,6 +185,61 @@ with block:
85
  # with gr.Row():
86
  # gr.Gallery(label='图像生成结果', value=GALLERY_LIST,show_label=False, elem_id="Gallery", columns=5, height=1000)
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  tab_3 = gr.Tab(label="IMG to SVG")
90
  with tab_3:
 
1
  import cv2, os
2
  import gradio as gr
3
  import numpy as np
4
+ from demo.generation import call_generation, call_generation_t2v
5
+ from demo.instructions import INSTRUCTIONS_VECTORIZE_SIMPLIFY, INSTRUCTIONS_T2V
6
 
7
  VERSION = 'v0.1'
8
 
9
  GALLERY_LIST = [os.path.join('demo/gallery',path) for path in os.listdir('demo/gallery')]
10
 
11
+ PROMPT_EXAMPLE=[['a cute dog'],
12
+ ['a cute cat'],
13
+ ['a beautiful woman'],
14
+ ['a bus'],]
15
+
16
+ STYLE_MAPPING = {"0": "商业扁平插画",
17
+ "1": "矢量风扁平插画",
18
+ "2": "高级时尚系列插画",
19
+ "3": "s矢量插画",
20
+ "4": "彩色插画",
21
+ "5": "扁平海报插画",
22
+ "6": "扁平职人风插画",
23
+ "7": "矢量风插画",
24
+ "8": "轮廓插画",
25
+ "9": "F矢量插画",
26
+ "10": "Material图标",
27
+ "11": "图标元素",
28
+ "12": "矢量风插画0",
29
+ "13": "Logo风格图标",
30
+ "14": "sticker风图标",
31
+ "15": "纹理插画",
32
+ "16": "矢量风插画2",
33
+ "17": "矢量风插画M"}
34
+
35
+ STYLE_MAPPING_EN = {
36
+ "0": "Commercial flat illustration",
37
+ "1": "Vector-style flat illustration",
38
+ "2": "High-end fashion series illustration",
39
+ "3": "s vector illustration",
40
+ "4": "Color illustration",
41
+ "5": "Flat poster illustration",
42
+ "6": "Flat artisan-style illustration",
43
+ "7": "Vector-style illustration",
44
+ "8": "Outline illustration",
45
+ "9": "F vector illustration",
46
+ "10": "Material icon",
47
+ "11": "Icon elements",
48
+ "12": "Vector-style illustration 0",
49
+ "13": "Logo-style icon",
50
+ "14": "Sticker-style icon",
51
+ "15": "Texture illustration",
52
+ "16": "Vector-style illustration 2",
53
+ "17": "Vector-style illustration M"
54
+ }
55
+
56
+
57
+ STYLE_MAPPING_REVERT = {v: k for k, v in STYLE_MAPPING_EN.items()}
58
+
59
+
60
+ STYLE_IMG_DICT = {"demo/style_img/商业扁平插画.webp": "0",
61
+ "demo/style_img/矢量风扁平插画.webp":"1",
62
+ "demo/style_img/高级时尚系列插画.webp":"2",
63
+ "demo/style_img/s矢量插画.webp": "3",
64
+ "demo/style_img/彩色插画.webp": "4",
65
+ "demo/style_img/扁平海报插画.webp": "5",
66
+ "demo/style_img/扁平职人.webp": "6",
67
+ "demo/style_img/vectorart.webp": "7",
68
+ "demo/style_img/outline.webp": "8",
69
+ "demo/style_img/fllust.webp": "9",
70
+ "demo/style_img/icon.webp": "11",
71
+ "demo/style_img/icon_material.webp": "10",
72
+ "demo/style_img/last.webp": "12",
73
+ "demo/style_img/logo.webp": "13",
74
+ "demo/style_img/sdmai.webp": "14",
75
+ "demo/style_img/texture.webp": "15",
76
+ "demo/style_img/vector_illustration.webp":"16",
77
+ "demo/style_img/vectorizeM.webp": "17",
78
+ }
79
+
80
+ STYLE_IMG_DICT_REVERT = {v: k for k, v in STYLE_IMG_DICT.items()}
81
+
82
+ details_slider_dict = {"Minimal 简约":"minimal",
83
+ "Medium 中等":"medium",
84
+ "Rich 丰富": "rich"
85
+ }
86
 
87
  def resize_image(image, size):
88
  # find the minimal size of the image, resize it to size
 
130
  return file_list
131
 
132
 
133
+ def process_t2v(prompt, num_imgs, image_resolution_h, image_resolution_w, details_slider, style_slider, vectorize, upsample_method, svg_simplify, svg_optimize, trace_mode, subsample_ratio, speckle_removal,sorting_method, sorting_order, use_gpu):
134
+ print("Processing t2v:",upsample_method, svg_simplify, svg_optimize, trace_mode)
135
+ if prompt is not None:
136
+ ## save input_image to a temp file
137
+ details = details_slider_dict[details_slider]
138
+ style = STYLE_MAPPING_REVERT[style_slider]
139
+ ## process the image
140
+ file_list = call_generation_t2v(prompt,
141
+ num_imgs,
142
+ image_resolution_h,
143
+ image_resolution_w,
144
+ details,
145
+ style,
146
+ vectorize,
147
+ preprocess=upsample_method,
148
+ simplify=svg_simplify,
149
+ optimize=svg_optimize,
150
+ mode=trace_mode,
151
+ subsample_ratio=subsample_ratio,
152
+ speckle_removal=speckle_removal,
153
+ sorting_method=sorting_method,
154
+ sorting_order=sorting_order,
155
+ use_gpu=use_gpu)
156
+
157
+ return file_list
158
 
159
 
160
 
 
185
  # with gr.Row():
186
  # gr.Gallery(label='图像生成结果', value=GALLERY_LIST,show_label=False, elem_id="Gallery", columns=5, height=1000)
187
 
188
+ tab_1 = gr.Tab(label="TEXT to Vector (文生矢量图)")
189
+
190
+ with tab_1:
191
+ with gr.Accordion('🕹Usage (操作说明)', open=True,):
192
+ with gr.Tabs():
193
+ gr.HTML(INSTRUCTIONS_T2V)
194
+ with gr.Row():
195
+ with gr.Column():
196
+ with gr.Row():
197
+ lora_radio_t2v = gr.Radio(choices=STYLE_MAPPING_REVERT.keys(), type="value", value='Commercial flat illustration', label="Style Selection (风格选择)")
198
+ style_image_t2v = gr.Image(value=STYLE_IMG_DICT_REVERT["0"],type="numpy", image_mode="RGBA", label="Style Image (风格图片)")
199
+ prompt_t2v = gr.Textbox(label="Prompt (提示词)", value="a cute dog")
200
+ details_slider_t2v = gr.Radio(label="图形细节 Details", choices=["Minimal 简约","Medium 中等","Rich 丰富" ], type="value", value="Medium 中等")
201
+ num_samples_t2v = gr.Slider(label="Images (图像数量)", minimum=1, maximum=2, value=1, step=1, visible=False)
202
+ vectorize = gr.Checkbox(label='generate svg file', value=True, visible=True)
203
+ run_button_t2v = gr.Button(value="Generation Vector (生成矢量)",elem_id="btnSEG")
204
+
205
+ with gr.Accordion("Image options", open=False):
206
+ image_resolution_h = gr.Slider(label="Image height (高)", minimum=256, maximum=1024, value=512, step=64, visible=True)
207
+ image_resolution_w = gr.Slider(label="Image width (宽)", minimum=256, maximum=1024, value=512, step=64, visible=True)
208
+
209
+
210
+ with gr.Accordion("Vector options", open=False):
211
+ upsample_method_t2v = gr.Dropdown(choices=["None", "x4", "x2"], type="value", value="None", label="Upsample Method (超分倍数)[无, 4倍, 2倍], 默认无")
212
+ sorting_method_t2v = gr.Dropdown(choices=["brightness","area"], type="value", value="brightness", label="Sorting Method (排序方法)[亮度,面积], 默认亮度")
213
+ sorting_order_t2v = gr.Dropdown(choices=["ascend","descend"], type="value", value="descend", label="Sorting Order (排序顺序)[递增,递减], 默认递减")
214
+ trace_mode_t2v = gr.Radio(choices=["overlap", "cutout"], type="value", value="overlap", label="Trace Mode (追踪模式)[堆叠,分开]")
215
+ use_gpu_t2v = gr.Checkbox(label='use GPU (是否使用GPU加速[针对复杂图形较为有效]), 默认关闭', value=False, visible=True)
216
+ svg_simplify_t2v = gr.Checkbox(label='Simplify SVG (简化矢量图, 默认关闭)', value=False, visible=True)
217
+ svg_optimize_t2v = gr.Checkbox(label='Optimize SVG (优化矢量图, 默认关闭)', value=False, visible=True)
218
+ speckle_removal_t2v = gr.Checkbox(label='Remove small speckle[是否移除面积过小的图形]', value=False)
219
+ subsample_ratio_t2v = gr.Slider(label="Subsample Ratio", minimum=1, maximum=10000, value=12, step=1, visible=False)
220
+
221
+ with gr.Tab("Prompt Examples"):
222
+ t2v_examples = gr.Examples(
223
+ PROMPT_EXAMPLE,
224
+ [prompt_t2v],
225
+ examples_per_page=5,
226
+ label=''
227
+ )
228
+
229
+ with gr.Column():
230
+ result_gallery_t2v = gr.Gallery(label='图像生成结果 Generation Results', show_label=False, elem_id="Gallery")
231
+
232
+ def update_lora_image(lora_radio: gr.Radio):
233
+ return gr.Image(value=STYLE_IMG_DICT_REVERT[STYLE_MAPPING_REVERT[lora_radio]],)
234
+
235
+ lora_radio_t2v.change(fn=update_lora_image, inputs=[lora_radio_t2v], outputs=[style_image_t2v])
236
+
237
+
238
+
239
+ t2v_ips = [prompt_t2v, num_samples_t2v, image_resolution_h, image_resolution_w, details_slider_t2v, lora_radio_t2v, vectorize, upsample_method_t2v, svg_simplify_t2v, svg_optimize_t2v, trace_mode_t2v, subsample_ratio_t2v, speckle_removal_t2v,sorting_method_t2v, sorting_order_t2v, use_gpu_t2v]
240
+
241
+
242
+ run_button_t2v.click(fn=process_t2v, inputs=t2v_ips, outputs=result_gallery_t2v)
243
 
244
  tab_3 = gr.Tab(label="IMG to SVG")
245
  with tab_3:
demo/generation.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  import requests
7
 
8
  from demo.log import logger
9
- from demo.util import download_svgs, upload_np_2_oss
10
 
11
  API_KEY = os.getenv("API_KEY_GENERATION")
12
 
@@ -84,7 +84,7 @@ def call_generation(input_path,
84
  res = json.loads(res_.content.decode())
85
  request_id = res['request_id']
86
  task_id = res['output']['task_id']
87
- logger.info(f"task_id: {task_id}: Create Poster Imitation request success. Params: {data}")
88
 
89
  # 异步查询
90
  is_running = True
@@ -127,5 +127,146 @@ def call_generation(input_path,
127
  raise gr.Error("Fail to Generation.")
128
  return all_image_data[-1:]
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  if __name__ == "__main__":
131
  call_generation()
 
6
  import requests
7
 
8
  from demo.log import logger
9
+ from demo.util import download_svgs, upload_np_2_oss, download_images
10
 
11
  API_KEY = os.getenv("API_KEY_GENERATION")
12
 
 
84
  res = json.loads(res_.content.decode())
85
  request_id = res['request_id']
86
  task_id = res['output']['task_id']
87
+ logger.info(f"task_id: {task_id}: Create Vectorization I2V request success. Params: {data}")
88
 
89
  # 异步查询
90
  is_running = True
 
127
  raise gr.Error("Fail to Generation.")
128
  return all_image_data[-1:]
129
 
130
+ def call_generation_t2v(prompt,
131
+ num_imgs,
132
+ image_resolution_h,
133
+ image_resolution_w,
134
+ details,
135
+ style,
136
+ vectorize,
137
+ preprocess,
138
+ simplify,
139
+ optimize,
140
+ mode,
141
+ subsample_ratio,
142
+ speckle_removal,
143
+ sorting_method,
144
+ sorting_order,
145
+ use_gpu):
146
+
147
+ ## generate image name based on time stamp
148
+ time_str = time.strftime("%Y%m%d%H%M%S", time.localtime())
149
+ # img_name = f"upload_{time_str}.png"
150
+ svg_name = f"result_{time_str}"
151
+ generate_img_name = f"generate_{time_str}"
152
+ BATCH_SIZE = 1
153
+ count = 1
154
+ start_ind = 0
155
+ if simplify:
156
+ BATCH_SIZE += 1
157
+ count +=1
158
+ start_ind += 1
159
+ if optimize:
160
+ BATCH_SIZE += 1
161
+ start_ind += 1
162
+ count +=1
163
+
164
+ BATCH_SIZE *= num_imgs
165
+ # img_url = upload_np_2_oss(input_path, name=img_name)
166
+ # simplify = convert_bool_to_str(simplify)
167
+ # optimize = convert_bool_to_str(optimize)
168
+ # speckle_removal = convert_bool_to_str(speckle_removal)
169
+ # use_gpu = convert_bool_to_str(use_gpu)
170
+
171
+ headers = {
172
+ "Content-Type": "application/json",
173
+ "Accept": "application/json",
174
+ "Authorization": f"Bearer {API_KEY}",
175
+ "X-DashScope-Async": "enable",
176
+ }
177
+ data = {
178
+ "model": "pre-vectorize_anything_t2v-2352",
179
+ "input": {
180
+ "prompt": prompt
181
+ },
182
+ "parameters":{
183
+ "num_imgs" : num_imgs,
184
+ "image_resolution_h": image_resolution_h,
185
+ "image_resolution_w": image_resolution_w,
186
+ "details" : details,
187
+ "style" : style,
188
+ "vectorize" : vectorize,
189
+ "preprocess": preprocess,
190
+ "mode": mode,
191
+ "simplify": simplify,
192
+ "optimize": optimize,
193
+ "sorting_method": sorting_method,
194
+ "sorting_order": sorting_order,
195
+ "subsample_ratio": subsample_ratio,
196
+ "speckle_removal": speckle_removal,
197
+ "use_GPU": use_gpu
198
+ }
199
+ }
200
+ url_create_task = 'https://poc-dashscope.aliyuncs.com/api/v1/services/aigc/text2image/image-synthesis'
201
+
202
+ all_res_ = []
203
+ REPEAT = 1
204
+ for _ in range(REPEAT):
205
+ try:
206
+ res_ = requests.post(url_create_task, data=json.dumps(data), headers=headers, timeout=120)
207
+ print(json.dumps(data))
208
+ all_res_.append(res_)
209
+ except requests.Timeout:
210
+ # back off and retry
211
+ raise gr.Error("网络波动,请求失败,请再次尝试")
212
+
213
+ all_image_data = []
214
+ for res_ in all_res_:
215
+ respose_code = res_.status_code
216
+ if 200 == respose_code:
217
+ res = json.loads(res_.content.decode())
218
+ request_id = res['request_id']
219
+ task_id = res['output']['task_id']
220
+ logger.info(f"task_id: {task_id}: Create Vectorize T2V request success. Params: {data}")
221
+
222
+ # 异步查询
223
+ is_running = True
224
+ while is_running:
225
+ # url_query = f'https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}'
226
+ url_query = f'https://poc-dashscope.aliyuncs.com/api/v1/tasks/{task_id}'
227
+ try:
228
+ res_ = requests.post(url_query, headers=headers, timeout=120)
229
+ except requests.Timeout:
230
+ # back off and retry
231
+ raise gr.Error("网络波动,请求失败,请再次尝试")
232
+ respose_code = res_.status_code
233
+ if 200 == respose_code:
234
+ res = json.loads(res_.content.decode())
235
+ if "SUCCEEDED" == res['output']['task_status']:
236
+ logger.info(f"task_id: {task_id}: Generation task query success.")
237
+ results = res['output']
238
+ img_urls = results['output_img']
239
+ logger.info(f"task_id: {task_id}: {res}")
240
+ break
241
+ elif "FAILED" != res['output']['task_status']:
242
+ logger.debug(f"task_id: {task_id}: query result...")
243
+ time.sleep(1)
244
+ else:
245
+ raise gr.Error('Fail to get results from Generation task.')
246
+
247
+ else:
248
+ logger.error(f'task_id: {task_id}: Fail to query task result: {res_.content}')
249
+ raise gr.Error("Fail to query task result.")
250
+
251
+ logger.info(f"task_id: {task_id}: download generated images.")
252
+ if vectorize:
253
+ img_data = download_svgs(img_urls, BATCH_SIZE, svg_name)
254
+ else:
255
+ img_data = download_images(img_urls, num_imgs, generate_img_name)
256
+
257
+ logger.info(f"task_id: {task_id}: Generate done.")
258
+ all_image_data += img_data
259
+ else:
260
+ logger.error(f'Fail to create Generation task: {res_.content}')
261
+ raise gr.Error("Fail to create Generation task.")
262
+ if vectorize:
263
+ if len(all_image_data) != REPEAT * BATCH_SIZE:
264
+ raise gr.Error("Fail to Generation.")
265
+ else:
266
+ if len(all_image_data) != REPEAT * num_imgs:
267
+ raise gr.Error("Fail to Generation.")
268
+ return all_image_data[start_ind::BATCH_SIZE//num_imgs]
269
+
270
+
271
  if __name__ == "__main__":
272
  call_generation()
demo/instructions.py CHANGED
@@ -28,4 +28,15 @@ INSTRUCTIONS_VECTORIZE_SIMPLIFY='''
28
  </ul>
29
  <p>Step3: 点击转化矢量图 Press the button to vectorize</p>
30
  </body>
 
 
 
 
 
 
 
 
 
 
 
31
  '''
 
28
  </ul>
29
  <p>Step3: 点击转化矢量图 Press the button to vectorize</p>
30
  </body>
31
+ '''
32
+
33
+ INSTRUCTIONS_T2V='''
34
+
35
+ <p>Step 1: Choose a vector style</p>
36
+ <p>Step 2: Input Prompt
37
+ <p>Step 3: Adjust the details levels of shape</p>
38
+ <p>Step 4: Generate vectors</p>
39
+
40
+ <p> More parameters can be found in Image Options and Vector Options</p>
41
+
42
  '''
demo/style_img/fllust.webp ADDED

Git LFS Details

  • SHA256: 16a4e17e58bfe8a989fca56ddd619406580bb67e97e11f7670c2ed5f09307243
  • Pointer size: 130 Bytes
  • Size of remote file: 10.4 kB
demo/style_img/icon.webp ADDED

Git LFS Details

  • SHA256: 2c4eaff7f1b75ccb13e04473daebc03d6ec1fe09d92b412dc1ee11d73f2e956d
  • Pointer size: 130 Bytes
  • Size of remote file: 10.2 kB
demo/style_img/icon_material.webp ADDED

Git LFS Details

  • SHA256: 51eb8dc18f19a28332b5438ca56c6be0e5e72aa230cea01a8b37c00b3c3b69b9
  • Pointer size: 130 Bytes
  • Size of remote file: 12.3 kB
demo/style_img/last.webp ADDED

Git LFS Details

  • SHA256: 49ea3e3da59a6b6abfa66477923bba701b88ee452ba8f65500f08d5223039f2c
  • Pointer size: 130 Bytes
  • Size of remote file: 18.1 kB
demo/style_img/logo.webp ADDED

Git LFS Details

  • SHA256: 5e06cf3a1447742d8d5c6216a1d67805a6ac19e263b4d8a039c619b153159749
  • Pointer size: 130 Bytes
  • Size of remote file: 17.9 kB
demo/style_img/outline.webp ADDED

Git LFS Details

  • SHA256: eedca602d3b970b2144c04868bb0c863c89e057348bae26562031bc9be77c638
  • Pointer size: 130 Bytes
  • Size of remote file: 48.5 kB
demo/style_img/sdmai.webp ADDED

Git LFS Details

  • SHA256: 26b4c6a6e5573570038b29b404f48e2cbc2d86f584f01e4bc180f7a44066876d
  • Pointer size: 130 Bytes
  • Size of remote file: 15 kB
demo/style_img/s矢量插画.webp ADDED

Git LFS Details

  • SHA256: 615873c3932fe8e390f32a24f4aa2356b32a6bdf9c4762253d33685751181de7
  • Pointer size: 130 Bytes
  • Size of remote file: 25.7 kB
demo/style_img/texture.webp ADDED

Git LFS Details

  • SHA256: cb2bb9f5726a1addaa208b22d1fcd2eace4074bab517a91637a87fad46781b35
  • Pointer size: 130 Bytes
  • Size of remote file: 14 kB
demo/style_img/vector_illustration.webp ADDED

Git LFS Details

  • SHA256: d95f99d47431677c16fcebcffe2580c4cd994ea6b8d182c6ea37795d132ac644
  • Pointer size: 130 Bytes
  • Size of remote file: 16.2 kB
demo/style_img/vectorart.webp ADDED

Git LFS Details

  • SHA256: 0824cf4dd3d8e1e28b6b7b97620e630b0c95d6cfd223a85f24c51cbdd1acc2fe
  • Pointer size: 130 Bytes
  • Size of remote file: 31.9 kB
demo/style_img/vectorizeM.webp ADDED

Git LFS Details

  • SHA256: 7cc448183cb60ffd2fc213277245f6e2bb321622289d022fd4793349f7742860
  • Pointer size: 130 Bytes
  • Size of remote file: 12.5 kB
demo/style_img/商业扁平插画.webp ADDED

Git LFS Details

  • SHA256: 0aeb753a1b8ff0dda70632ad4b52e0f602dfdc04f6412facb4b02622a8f99fff
  • Pointer size: 130 Bytes
  • Size of remote file: 10.8 kB
demo/style_img/彩色插画.webp ADDED

Git LFS Details

  • SHA256: 8ef07e4f6adc8efdc603ae747177ac5e570e68857017058632295a6a22fcf574
  • Pointer size: 130 Bytes
  • Size of remote file: 21.7 kB
demo/style_img/扁平海报插画.webp ADDED

Git LFS Details

  • SHA256: f3360a95b6704eabeba93d14baaef8a26a06eaea8ff201e695768041229562c6
  • Pointer size: 130 Bytes
  • Size of remote file: 54.4 kB
demo/style_img/扁平职人.webp ADDED

Git LFS Details

  • SHA256: eb66ae670895b5929fe046f44e01a3e819cce036bf852c6f4ec7969ed5d1317a
  • Pointer size: 129 Bytes
  • Size of remote file: 9.31 kB
demo/style_img/矢量风扁平插画.webp ADDED

Git LFS Details

  • SHA256: 6fc7890b0a4bbd480da06de8efdff6947270463cb9fe59fc6fd9c2d5e86473a9
  • Pointer size: 130 Bytes
  • Size of remote file: 14.7 kB
demo/style_img/高级时尚系列插画.webp ADDED

Git LFS Details

  • SHA256: 76b64345ecc5bf4880b38e33338aeb3a3465ca58abc5742ede5519cc2bec169e
  • Pointer size: 130 Bytes
  • Size of remote file: 26 kB
demo/util.py CHANGED
@@ -20,23 +20,24 @@ oss_path_img_gallery = "VectorizeAnything"
20
 
21
  bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
22
 
23
- def download_img_pil(index, img_url):
24
  # print(img_url)
25
  r = requests.get(img_url, stream=True)
26
  if r.status_code == 200:
27
  img = Image.open(io.BytesIO(r.content))
 
28
  return (index, img)
29
  else:
30
  logger.error(f"Fail to download: {img_url}")
31
 
32
 
33
- def download_images(img_urls, batch_size):
34
  imgs_pil = [None] * batch_size
35
  # worker_results = []
36
  with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
37
  to_do = []
38
  for i, url in enumerate(img_urls):
39
- future = executor.submit(download_img_pil, i, url)
40
  to_do.append(future)
41
 
42
  for future in concurrent.futures.as_completed(to_do):
 
20
 
21
  bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
22
 
23
+ def download_img_pil(index, img_url, img_name):
24
  # print(img_url)
25
  r = requests.get(img_url, stream=True)
26
  if r.status_code == 200:
27
  img = Image.open(io.BytesIO(r.content))
28
+ upload_svg_2_oss(io.BytesIO(r.content), f"{img_name}_{index}.png")
29
  return (index, img)
30
  else:
31
  logger.error(f"Fail to download: {img_url}")
32
 
33
 
34
+ def download_images(img_urls, batch_size, img_name):
35
  imgs_pil = [None] * batch_size
36
  # worker_results = []
37
  with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
38
  to_do = []
39
  for i, url in enumerate(img_urls):
40
+ future = executor.submit(download_img_pil, i, url, img_name)
41
  to_do.append(future)
42
 
43
  for future in concurrent.futures.as_completed(to_do):