Spaces:
Running
Running
Update generator_function/image_processor.py
Browse files
generator_function/image_processor.py
CHANGED
|
@@ -14,9 +14,7 @@ logger = logging.getLogger(__name__)
|
|
| 14 |
COL = get_collection()
|
| 15 |
|
| 16 |
def _resolve_user_id() -> str:
|
| 17 |
-
return current_uid() or os.getenv("DEFAULT_USER_ID")
|
| 18 |
-
|
| 19 |
-
uid = _resolve_user_id()
|
| 20 |
|
| 21 |
def process_zip_and_generate_images(
|
| 22 |
zip_path: str,
|
|
@@ -30,6 +28,7 @@ def process_zip_and_generate_images(
|
|
| 30 |
demo_mode: bool,
|
| 31 |
existing_images: Optional[List[str]],
|
| 32 |
blur: bool,
|
|
|
|
| 33 |
) -> List[str]:
|
| 34 |
num_images = 1 if demo_mode else num_images
|
| 35 |
try:
|
|
@@ -40,7 +39,7 @@ def process_zip_and_generate_images(
|
|
| 40 |
image_files = [(os.path.basename(zip_path), zip_path)]
|
| 41 |
|
| 42 |
results = process_image_files(
|
| 43 |
-
image_files, category, size, quality, user_prompt, sentiment, platform, num_images, blur
|
| 44 |
)
|
| 45 |
all_urls = [url for entry in results for url in entry["urls"]]
|
| 46 |
seen, deduped = set(), []
|
|
@@ -72,7 +71,7 @@ def get_valid_image_files(temp_dir: tempfile.TemporaryDirectory) -> List[Tuple[s
|
|
| 72 |
return valid_files
|
| 73 |
|
| 74 |
def process_image_files(image_files: List[Tuple[str, str]],category: str,size: str,
|
| 75 |
-
quality: str,user_prompt: str,sentiment: str,platform: str,num_images: int,blur: bool,
|
| 76 |
) -> List[dict]:
|
| 77 |
final_results: List[dict] = []
|
| 78 |
with ThreadPoolExecutor(max_workers=5) as executor:
|
|
|
|
| 14 |
COL = get_collection()
|
| 15 |
|
| 16 |
def _resolve_user_id() -> str:
|
| 17 |
+
return current_uid() or os.getenv("DEFAULT_USER_ID", "anonymous")
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def process_zip_and_generate_images(
|
| 20 |
zip_path: str,
|
|
|
|
| 28 |
demo_mode: bool,
|
| 29 |
existing_images: Optional[List[str]],
|
| 30 |
blur: bool,
|
| 31 |
+
uid: str,
|
| 32 |
) -> List[str]:
|
| 33 |
num_images = 1 if demo_mode else num_images
|
| 34 |
try:
|
|
|
|
| 39 |
image_files = [(os.path.basename(zip_path), zip_path)]
|
| 40 |
|
| 41 |
results = process_image_files(
|
| 42 |
+
image_files, category, size, quality, user_prompt, sentiment, platform, num_images, blur, uid
|
| 43 |
)
|
| 44 |
all_urls = [url for entry in results for url in entry["urls"]]
|
| 45 |
seen, deduped = set(), []
|
|
|
|
| 71 |
return valid_files
|
| 72 |
|
| 73 |
def process_image_files(image_files: List[Tuple[str, str]],category: str,size: str,
|
| 74 |
+
quality: str,user_prompt: str,sentiment: str,platform: str,num_images: int,blur: bool,uid: str,
|
| 75 |
) -> List[dict]:
|
| 76 |
final_results: List[dict] = []
|
| 77 |
with ThreadPoolExecutor(max_workers=5) as executor:
|