Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +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 |
-
"""
|
| 36 |
results = []
|
| 37 |
|
| 38 |
if not os.path.exists(src_folder):
|
|
@@ -45,13 +45,16 @@ def prepare_clean_examples(src_folder, prefix, limit=10):
|
|
| 45 |
if not fname.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp', '.webp')):
|
| 46 |
continue
|
| 47 |
src_path = os.path.join(root, fname)
|
|
|
|
| 48 |
try:
|
| 49 |
-
#
|
| 50 |
img = Image.open(src_path).convert('RGB')
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
count += 1
|
| 54 |
-
print(f"[EXAMPLES]
|
| 55 |
if count >= limit:
|
| 56 |
break
|
| 57 |
except Exception as e:
|
|
@@ -59,7 +62,7 @@ def prepare_clean_examples(src_folder, prefix, limit=10):
|
|
| 59 |
if count >= limit:
|
| 60 |
break
|
| 61 |
|
| 62 |
-
print(f"[EXAMPLES] {prefix}: {count}
|
| 63 |
return results
|
| 64 |
|
| 65 |
# List all folders before preparing
|
|
@@ -86,9 +89,9 @@ for folder in ["car Images", "car_Images", "car images"]:
|
|
| 86 |
|
| 87 |
# Fallback
|
| 88 |
if not car_examples and os.path.exists("car.jpeg"):
|
| 89 |
-
car_examples = [
|
| 90 |
if not mirror_examples and os.path.exists("car.jpeg"):
|
| 91 |
-
mirror_examples = [
|
| 92 |
|
| 93 |
print(f"\n[FINAL] Car examples: {len(car_examples)}")
|
| 94 |
print(f"[FINAL] Mirror examples: {len(mirror_examples)}")
|
|
@@ -314,7 +317,7 @@ with gr.Blocks(theme=theme, title="Car vs Mirror Segmentation") as demo:
|
|
| 314 |
if car_examples:
|
| 315 |
gr.Examples(
|
| 316 |
examples=car_examples,
|
| 317 |
-
inputs=
|
| 318 |
examples_per_page=10,
|
| 319 |
cache_examples=False,
|
| 320 |
label="πΈ Click any car image to load it"
|
|
@@ -348,7 +351,7 @@ with gr.Blocks(theme=theme, title="Car vs Mirror Segmentation") as demo:
|
|
| 348 |
if mirror_examples:
|
| 349 |
gr.Examples(
|
| 350 |
examples=mirror_examples,
|
| 351 |
-
inputs=
|
| 352 |
examples_per_page=10,
|
| 353 |
cache_examples=False,
|
| 354 |
label="πΈ Click any mirror image to load it"
|
|
|
|
| 32 |
# STEP 2: Copy images to clean "examples" folder with simple names
|
| 33 |
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 34 |
def prepare_clean_examples(src_folder, prefix, limit=10):
|
| 35 |
+
"""Copy images to root directory and return a FLAT list of filenames."""
|
| 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 |
+
dst_name = f"{prefix}_{count}.jpg"
|
| 49 |
try:
|
| 50 |
+
# Use PIL to verify and save a clean copy to root
|
| 51 |
img = Image.open(src_path).convert('RGB')
|
| 52 |
+
img.save(dst_name, "JPEG", quality=90)
|
| 53 |
+
|
| 54 |
+
# Append flat filename
|
| 55 |
+
results.append(dst_name)
|
| 56 |
count += 1
|
| 57 |
+
print(f"[EXAMPLES] Saved to root: {dst_name}")
|
| 58 |
if count >= limit:
|
| 59 |
break
|
| 60 |
except Exception as e:
|
|
|
|
| 62 |
if count >= limit:
|
| 63 |
break
|
| 64 |
|
| 65 |
+
print(f"[EXAMPLES] {prefix}: {count} flat images prepared from '{src_folder}'")
|
| 66 |
return results
|
| 67 |
|
| 68 |
# List all folders before preparing
|
|
|
|
| 89 |
|
| 90 |
# Fallback
|
| 91 |
if not car_examples and os.path.exists("car.jpeg"):
|
| 92 |
+
car_examples = ["car.jpeg"]
|
| 93 |
if not mirror_examples and os.path.exists("car.jpeg"):
|
| 94 |
+
mirror_examples = ["car.jpeg"]
|
| 95 |
|
| 96 |
print(f"\n[FINAL] Car examples: {len(car_examples)}")
|
| 97 |
print(f"[FINAL] Mirror examples: {len(mirror_examples)}")
|
|
|
|
| 317 |
if car_examples:
|
| 318 |
gr.Examples(
|
| 319 |
examples=car_examples,
|
| 320 |
+
inputs=input_image_car,
|
| 321 |
examples_per_page=10,
|
| 322 |
cache_examples=False,
|
| 323 |
label="πΈ Click any car image to load it"
|
|
|
|
| 351 |
if mirror_examples:
|
| 352 |
gr.Examples(
|
| 353 |
examples=mirror_examples,
|
| 354 |
+
inputs=input_image_mirror,
|
| 355 |
examples_per_page=10,
|
| 356 |
cache_examples=False,
|
| 357 |
label="πΈ Click any mirror image to load it"
|