Spaces:
Sleeping
Sleeping
update2
Browse files- image_processor.py +6 -7
image_processor.py
CHANGED
|
@@ -20,7 +20,7 @@ def process_zip_and_generate_images(
|
|
| 20 |
):
|
| 21 |
num_images = 1 if demo_mode else num_images
|
| 22 |
|
| 23 |
-
num_images =
|
| 24 |
|
| 25 |
try:
|
| 26 |
if zip_path.endswith('.zip'):
|
|
@@ -145,21 +145,20 @@ def process_single_image(file_name, file_path, category, size, quality, user_pro
|
|
| 145 |
def generate_images_from_prompts(file_path, size, quality, category, sentiment, user_prompt, platform, num_images, blur):
|
| 146 |
image_urls = []
|
| 147 |
|
| 148 |
-
def worker(
|
| 149 |
try:
|
| 150 |
-
image_bytes = generate_image(file_path, size, quality, category, sentiment, user_prompt, platform, blur)
|
| 151 |
|
| 152 |
if not image_bytes:
|
| 153 |
-
|
| 154 |
return None
|
| 155 |
|
| 156 |
logger.info("Successfully generated image bytes.")
|
| 157 |
|
| 158 |
-
logger.info("Injecting EXIF metadata into image.")
|
| 159 |
try:
|
| 160 |
image_with_metadata = meta_data_helper_function(image_bytes)
|
| 161 |
except Exception as e:
|
| 162 |
-
|
| 163 |
return None
|
| 164 |
|
| 165 |
s3_url = upload_image_to_r2(image_with_metadata)
|
|
@@ -167,7 +166,7 @@ def generate_images_from_prompts(file_path, size, quality, category, sentiment,
|
|
| 167 |
return s3_url
|
| 168 |
|
| 169 |
except Exception as e:
|
| 170 |
-
|
| 171 |
return None
|
| 172 |
|
| 173 |
with ThreadPoolExecutor(max_workers=min(10, num_images)) as executor:
|
|
|
|
| 20 |
):
|
| 21 |
num_images = 1 if demo_mode else num_images
|
| 22 |
|
| 23 |
+
num_images = 3 if not demo_mode and platform == "Google Display Network" else num_images
|
| 24 |
|
| 25 |
try:
|
| 26 |
if zip_path.endswith('.zip'):
|
|
|
|
| 145 |
def generate_images_from_prompts(file_path, size, quality, category, sentiment, user_prompt, platform, num_images, blur):
|
| 146 |
image_urls = []
|
| 147 |
|
| 148 |
+
def worker(i):
|
| 149 |
try:
|
| 150 |
+
image_bytes = generate_image(file_path, size, quality, category, sentiment, user_prompt, platform, blur, i)
|
| 151 |
|
| 152 |
if not image_bytes:
|
| 153 |
+
logger.error("Image generation returned empty bytes.")
|
| 154 |
return None
|
| 155 |
|
| 156 |
logger.info("Successfully generated image bytes.")
|
| 157 |
|
|
|
|
| 158 |
try:
|
| 159 |
image_with_metadata = meta_data_helper_function(image_bytes)
|
| 160 |
except Exception as e:
|
| 161 |
+
logger.error(f"Metadata generation failed: {e}")
|
| 162 |
return None
|
| 163 |
|
| 164 |
s3_url = upload_image_to_r2(image_with_metadata)
|
|
|
|
| 166 |
return s3_url
|
| 167 |
|
| 168 |
except Exception as e:
|
| 169 |
+
logger.error(f"Image generation failed: {e}")
|
| 170 |
return None
|
| 171 |
|
| 172 |
with ThreadPoolExecutor(max_workers=min(10, num_images)) as executor:
|