johny12353q commited on
Commit
3ee9006
·
1 Parent(s): 7e9a2b9

feat: Add ability to upload more poses and combine them with faces + error counting

Browse files
Files changed (1) hide show
  1. app.py +79 -35
app.py CHANGED
@@ -15,7 +15,7 @@ AWS_ACCESS_SECRET = os.getenv('AWS_ACCESS_SECRET')
15
 
16
  def process_images(
17
  person_images,
18
- pose_image,
19
  prompt,
20
  negative_prompt,
21
  num_steps,
@@ -35,7 +35,7 @@ def process_images(
35
  gr.Warning('No person images set')
36
  return
37
 
38
- if pose_image == None:
39
  gr.Warning('No pose image set')
40
  return
41
 
@@ -43,50 +43,94 @@ def process_images(
43
  gr.Warning('No prompt set')
44
  return
45
 
46
- person_images_paths = [image for image in person_images]
47
- pose_image_path = pose_image
48
- image_paths = person_images_paths + [pose_image_path]
49
 
50
  yield [], "Uploading images"
51
 
52
- uploaded_person_image_urls, uploaded_pose_image_urls = upload_images_concurrently(person_images_paths, [pose_image_path])
53
- uploaded_pose_image_url = uploaded_pose_image_urls[0] if uploaded_pose_image_urls else None
 
 
54
 
55
- requests_data = []
56
- for i in range(0, generations_repeat_count):
57
- for person_image_url in uploaded_person_image_urls:
58
- requests_data.append(
59
- {
60
- "faceImageUrl": person_image_url,
61
- "poseImageUrl": uploaded_pose_image_url,
62
- "prompt": prompt,
63
- "n_prompt": negative_prompt,
64
- "num_steps": num_steps,
65
- "identity_strength_ration": identity_strength_ration,
66
- "adapter_strength_ration": adapter_strength_ration,
67
- "pose_strength_ration": pose_strength_ration,
68
- "canny_strength_ration": canny_strength_ration,
69
- "depth_strength_ration": depth_strength_ration,
70
- "controlnet_selection": controlnet_selection,
71
- "guidance_strength_ration": guidance_strength_ration,
72
- "scheduler": scheduler,
73
- "enable_lcm": enable_lcm,
74
- "enhance_face_region": enhance_face_region
75
- }
76
- )
77
 
78
  yield [], f"Generating images 0/{len(requests_data)}"
79
 
80
  gallery_items = []
 
81
  with concurrent.futures.ThreadPoolExecutor() as executor:
82
  futures = {executor.submit(execute_instantid_request, req_data.copy()): req_data for req_data in requests_data}
83
  for future in concurrent.futures.as_completed(futures):
84
  response = future.result()
85
  if response is not None:
86
  gallery_items.append((response, "Caption"))
87
- yield gallery_items, f"Generating images {len(gallery_items)}/{len(requests_data)}"
88
-
89
- def upload_images_concurrently(person_images_paths, pose_images_paths, progress_callback):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  """
91
  Uploads person and pose images concurrently and keeps them organized.
92
  Returns a tuple of lists: (list of person image URLs, list of pose image URLs).
@@ -167,9 +211,9 @@ with gr.Blocks() as demo:
167
  file_types=["jpg", "jpeg", "png", "webp"],
168
  )
169
 
170
- pose_image = gr.File(
171
  label="Pose",
172
- file_count="single",
173
  file_types=["jpg", "jpeg", "png", "webp"],
174
  )
175
 
@@ -296,7 +340,7 @@ with gr.Blocks() as demo:
296
  fn=process_images,
297
  inputs=[
298
  person_images,
299
- pose_image,
300
  prompt,
301
  negative_prompt,
302
  num_steps,
 
15
 
16
  def process_images(
17
  person_images,
18
+ pose_images,
19
  prompt,
20
  negative_prompt,
21
  num_steps,
 
35
  gr.Warning('No person images set')
36
  return
37
 
38
+ if pose_images == None:
39
  gr.Warning('No pose image set')
40
  return
41
 
 
43
  gr.Warning('No prompt set')
44
  return
45
 
46
+ person_images_paths = person_images
47
+ pose_images_paths = pose_images
 
48
 
49
  yield [], "Uploading images"
50
 
51
+ uploaded_person_image_urls, uploaded_pose_image_urls = upload_images_concurrently(
52
+ person_images_paths=person_images_paths,
53
+ pose_images_paths=pose_images_paths,
54
+ )
55
 
56
+ requests_data = generate_requests_data(
57
+ generations_repeat_count=generations_repeat_count,
58
+ uploaded_person_image_urls=uploaded_person_image_urls,
59
+ uploaded_pose_image_urls=uploaded_pose_image_urls,
60
+ prompt=prompt,
61
+ negative_prompt=negative_prompt,
62
+ num_steps=num_steps,
63
+ identity_strength_ration=identity_strength_ration,
64
+ adapter_strength_ration=adapter_strength_ration,
65
+ pose_strength_ration=pose_strength_ration,
66
+ canny_strength_ration=canny_strength_ration,
67
+ depth_strength_ration=depth_strength_ration,
68
+ controlnet_selection=controlnet_selection,
69
+ guidance_strength_ration=guidance_strength_ration,
70
+ scheduler=scheduler,
71
+ enable_lcm=enable_lcm,
72
+ enhance_face_region=enhance_face_region,
73
+ )
 
 
 
 
74
 
75
  yield [], f"Generating images 0/{len(requests_data)}"
76
 
77
  gallery_items = []
78
+ error_count = 0
79
  with concurrent.futures.ThreadPoolExecutor() as executor:
80
  futures = {executor.submit(execute_instantid_request, req_data.copy()): req_data for req_data in requests_data}
81
  for future in concurrent.futures.as_completed(futures):
82
  response = future.result()
83
  if response is not None:
84
  gallery_items.append((response, "Caption"))
85
+ else:
86
+ error_count += 1
87
+
88
+ yield gallery_items, f"Generating images {len(gallery_items)}/{len(requests_data)} (Failed: {error_count})"
89
+
90
+ def generate_requests_data(
91
+ generations_repeat_count,
92
+ uploaded_person_image_urls,
93
+ uploaded_pose_image_urls,
94
+ prompt,
95
+ negative_prompt,
96
+ num_steps,
97
+ identity_strength_ration,
98
+ adapter_strength_ration,
99
+ pose_strength_ration,
100
+ canny_strength_ration,
101
+ depth_strength_ration,
102
+ controlnet_selection,
103
+ guidance_strength_ration,
104
+ scheduler,
105
+ enable_lcm,
106
+ enhance_face_region,
107
+ ):
108
+ requests_data = []
109
+ for i in range(0, generations_repeat_count):
110
+ for person_image_url in uploaded_person_image_urls:
111
+ for pose_image_url in uploaded_pose_image_urls:
112
+ requests_data.append(
113
+ {
114
+ "faceImageUrl": person_image_url,
115
+ "poseImageUrl": pose_image_url,
116
+ "prompt": prompt,
117
+ "n_prompt": negative_prompt,
118
+ "num_steps": num_steps,
119
+ "identity_strength_ration": identity_strength_ration,
120
+ "adapter_strength_ration": adapter_strength_ration,
121
+ "pose_strength_ration": pose_strength_ration,
122
+ "canny_strength_ration": canny_strength_ration,
123
+ "depth_strength_ration": depth_strength_ration,
124
+ "controlnet_selection": controlnet_selection,
125
+ "guidance_strength_ration": guidance_strength_ration,
126
+ "scheduler": scheduler,
127
+ "enable_lcm": enable_lcm,
128
+ "enhance_face_region": enhance_face_region
129
+ }
130
+ )
131
+ return requests_data
132
+
133
+ def upload_images_concurrently(person_images_paths, pose_images_paths):
134
  """
135
  Uploads person and pose images concurrently and keeps them organized.
136
  Returns a tuple of lists: (list of person image URLs, list of pose image URLs).
 
211
  file_types=["jpg", "jpeg", "png", "webp"],
212
  )
213
 
214
+ pose_images = gr.File(
215
  label="Pose",
216
+ file_count="multiple",
217
  file_types=["jpg", "jpeg", "png", "webp"],
218
  )
219
 
 
340
  fn=process_images,
341
  inputs=[
342
  person_images,
343
+ pose_images,
344
  prompt,
345
  negative_prompt,
346
  num_steps,