Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -32,8 +32,7 @@ for f in os.listdir("."):
|
|
| 32 |
# STEP 2: Copy images to clean "examples" folder with simple names
|
| 33 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 34 |
def prepare_clean_examples(src_folder, prefix, limit=10):
|
| 35 |
-
"""Read images
|
| 36 |
-
dst_folder = "."
|
| 37 |
results = []
|
| 38 |
|
| 39 |
if not os.path.exists(src_folder):
|
|
@@ -46,17 +45,13 @@ def prepare_clean_examples(src_folder, prefix, limit=10):
|
|
| 46 |
if not fname.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp', '.webp')):
|
| 47 |
continue
|
| 48 |
src_path = os.path.join(root, fname)
|
| 49 |
-
dst_name = f"{prefix}_{count}.jpg"
|
| 50 |
-
dst_path = os.path.join(dst_folder, dst_name)
|
| 51 |
try:
|
| 52 |
-
#
|
| 53 |
-
img = Image.open(src_path)
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
img.save(dst_path, "JPEG", quality=90)
|
| 57 |
-
results.append([dst_path])
|
| 58 |
count += 1
|
| 59 |
-
print(f"[EXAMPLES]
|
| 60 |
if count >= limit:
|
| 61 |
break
|
| 62 |
except Exception as e:
|
|
@@ -64,7 +59,7 @@ def prepare_clean_examples(src_folder, prefix, limit=10):
|
|
| 64 |
if count >= limit:
|
| 65 |
break
|
| 66 |
|
| 67 |
-
print(f"[EXAMPLES] {prefix}: {count} images prepared from '{src_folder}'")
|
| 68 |
return results
|
| 69 |
|
| 70 |
# List all folders before preparing
|
|
|
|
| 32 |
# STEP 2: Copy images to clean "examples" folder with simple names
|
| 33 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 34 |
def prepare_clean_examples(src_folder, prefix, limit=10):
|
| 35 |
+
"""Read images and pass PIL objects directly to bypass Gradio path issues."""
|
|
|
|
| 36 |
results = []
|
| 37 |
|
| 38 |
if not os.path.exists(src_folder):
|
|
|
|
| 45 |
if not fname.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp', '.webp')):
|
| 46 |
continue
|
| 47 |
src_path = os.path.join(root, fname)
|
|
|
|
|
|
|
| 48 |
try:
|
| 49 |
+
# Open image and convert to RGB
|
| 50 |
+
img = Image.open(src_path).convert('RGB')
|
| 51 |
+
# Append the actual PIL image object!
|
| 52 |
+
results.append([img])
|
|
|
|
|
|
|
| 53 |
count += 1
|
| 54 |
+
print(f"[EXAMPLES] Loaded PIL Image: {src_path}")
|
| 55 |
if count >= limit:
|
| 56 |
break
|
| 57 |
except Exception as e:
|
|
|
|
| 59 |
if count >= limit:
|
| 60 |
break
|
| 61 |
|
| 62 |
+
print(f"[EXAMPLES] {prefix}: {count} PIL images prepared from '{src_folder}'")
|
| 63 |
return results
|
| 64 |
|
| 65 |
# List all folders before preparing
|