Spaces:
Sleeping
feat: multi-target brand numbering, configurable canvas/resize sizes, stim-number fix (#27)
Browse filesTab 5 (Name Stims by Block): replace the single "which brand = 01"
dropdown with a multiselect where selection order assigns 01/02/03...;
remaining brands are numbered alphabetically afterwards. Picking one
brand behaves exactly as before.
helper.py (bug fix): get_cleaned_filename_without_brand now preserves
digits (drops only separators/punctuation) instead of stripping all
non-letters. Previously "brand_txt1" and "brand_txt2" both collapsed to
"txt", losing stim identity and colliding in report IDs. Removes the
now-unused clean_letters_only helper. Also benefits Tab 6.
Tab 8 (Resize): replace the hard-coded 400px largest-side with a size
picker (400 / 1500 / custom), default 400; aspect ratio unchanged.
Tab 7 (Place on Canvas): replace the canvas-size field with a size
picker (500 / 1500 / custom), default 500. Oversized-skip behavior
unchanged.
- docs/architecture/active-surface.md +1 -2
- helper.py +11 -7
- tab5.py +23 -8
- tab7.py +16 -7
- tab8.py +34 -16
|
@@ -28,7 +28,6 @@ Splitting `helper.py` into focused modules is **out of scope** for the AI-standa
|
|
| 28 |
| `add_brand_pages(...)` | function | 836 |
|
| 29 |
| `analyze_files_by_filename(input_folder)` | function | 874 |
|
| 30 |
| `generate_pdf_report(input_folder, erste_marke=None)` | function | 914 |
|
| 31 |
-
| `clean_letters_only(text)` | function | 958 |
|
| 32 |
| `get_cleaned_filename_without_brand(filename, brand)` | function | 961 |
|
| 33 |
| `generate_filename_based_pdf_report(...)` | function | 970 |
|
| 34 |
| `add_brand_pages_with_final_labels(...)` | function | 1078 |
|
|
@@ -60,7 +59,7 @@ If a future architecture-hardening slice splits `helper.py`, these are the natur
|
|
| 60 |
|
| 61 |
1. **constants** — the five `ALLOWED_*` / `NON_IMAGE_*` extension sets.
|
| 62 |
2. **zip + io** — `extract_zip_to_temp`, `is_valid_file`.
|
| 63 |
-
3. **brand index** — `extract_brand`, `erkenne_marken_aus_ordnern`, `get_files_by_marke`, `
|
| 64 |
4. **Excel image extraction** — `extract_images_from_xlsx_zip_method`, `extract_images_from_xlsx_by_sheet`, `extract_images_from_xlsx`, `get_excel_worksheets_simple`.
|
| 65 |
5. **Excel report** — `generate_excel_report`.
|
| 66 |
6. **PDF report** — `generate_pdf_report`, `generate_filename_based_pdf_report`, `generate_filename_based_pdf_report_with_extensions`, `generate_two_section_pdf_report`, `add_brand_pages`, `add_brand_pages_with_png_extensions`, `add_brand_pages_with_final_labels`, `build_marken_einzelseiten`, `get_asset_cell`.
|
|
|
|
| 28 |
| `add_brand_pages(...)` | function | 836 |
|
| 29 |
| `analyze_files_by_filename(input_folder)` | function | 874 |
|
| 30 |
| `generate_pdf_report(input_folder, erste_marke=None)` | function | 914 |
|
|
|
|
| 31 |
| `get_cleaned_filename_without_brand(filename, brand)` | function | 961 |
|
| 32 |
| `generate_filename_based_pdf_report(...)` | function | 970 |
|
| 33 |
| `add_brand_pages_with_final_labels(...)` | function | 1078 |
|
|
|
|
| 59 |
|
| 60 |
1. **constants** — the five `ALLOWED_*` / `NON_IMAGE_*` extension sets.
|
| 61 |
2. **zip + io** — `extract_zip_to_temp`, `is_valid_file`.
|
| 62 |
+
3. **brand index** — `extract_brand`, `erkenne_marken_aus_ordnern`, `get_files_by_marke`, `get_cleaned_filename_without_brand`, `analyze_files_by_filename`, `process_files`.
|
| 63 |
4. **Excel image extraction** — `extract_images_from_xlsx_zip_method`, `extract_images_from_xlsx_by_sheet`, `extract_images_from_xlsx`, `get_excel_worksheets_simple`.
|
| 64 |
5. **Excel report** — `generate_excel_report`.
|
| 65 |
6. **PDF report** — `generate_pdf_report`, `generate_filename_based_pdf_report`, `generate_filename_based_pdf_report_with_extensions`, `generate_two_section_pdf_report`, `add_brand_pages`, `add_brand_pages_with_png_extensions`, `add_brand_pages_with_final_labels`, `build_marken_einzelseiten`, `get_asset_cell`.
|
|
@@ -974,16 +974,20 @@ def generate_pdf_report(input_folder, erste_marke=None):
|
|
| 974 |
except Exception as e:
|
| 975 |
return None, f"Error generating PDF: {str(e)}"
|
| 976 |
|
| 977 |
-
def clean_letters_only(text):
|
| 978 |
-
return re.sub(r'[^A-Za-z]', '', text)
|
| 979 |
-
|
| 980 |
def get_cleaned_filename_without_brand(filename, brand):
|
| 981 |
-
"""Get cleaned filename without brand name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 982 |
# Remove the extension first if present
|
| 983 |
stem = Path(filename).stem
|
| 984 |
-
|
| 985 |
-
|
| 986 |
-
|
|
|
|
| 987 |
return cleaned
|
| 988 |
|
| 989 |
def generate_filename_based_pdf_report(input_folder, erste_marke=None, processed_files_mapping=None):
|
|
|
|
| 974 |
except Exception as e:
|
| 975 |
return None, f"Error generating PDF: {str(e)}"
|
| 976 |
|
|
|
|
|
|
|
|
|
|
| 977 |
def get_cleaned_filename_without_brand(filename, brand):
|
| 978 |
+
"""Get cleaned filename without brand name.
|
| 979 |
+
|
| 980 |
+
Keeps letters AND digits, dropping only separators/punctuation
|
| 981 |
+
(spaces, underscores, hyphens, …). Digits carry stim identity, so
|
| 982 |
+
'brand_txt1' and 'brand_txt2' must stay distinct ('txt1' vs 'txt2')
|
| 983 |
+
instead of collapsing to the same 'txt'.
|
| 984 |
+
"""
|
| 985 |
# Remove the extension first if present
|
| 986 |
stem = Path(filename).stem
|
| 987 |
+
# Keep alphanumerics only — preserve digits, strip separators/punctuation.
|
| 988 |
+
full = re.sub(r'[^A-Za-z0-9]', '', stem.lower())
|
| 989 |
+
# Remove the brand from the beginning (brand may itself contain digits).
|
| 990 |
+
cleaned = full.replace(brand, '', 1)
|
| 991 |
return cleaned
|
| 992 |
|
| 993 |
def generate_filename_based_pdf_report(input_folder, erste_marke=None, processed_files_mapping=None):
|
|
@@ -69,18 +69,33 @@ def brand_renamer_tool():
|
|
| 69 |
|
| 70 |
# Brand numbering selection
|
| 71 |
st.subheader("Brand Numbering")
|
| 72 |
-
|
| 73 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
options=sorted(marken_set),
|
| 75 |
-
|
| 76 |
)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
for marke in sorted(marken_set):
|
| 81 |
-
if marke
|
| 82 |
marken_index[marke] = f"{aktuelle_nummer:02d}"
|
| 83 |
aktuelle_nummer += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
if st.button("Process Files and Generate Reports", type="primary"):
|
| 86 |
with st.spinner("Processing files..."):
|
|
@@ -285,7 +300,7 @@ def brand_renamer_tool():
|
|
| 285 |
st.markdown("""
|
| 286 |
Upload a ZIP file containing brand asset folders. The tool will:
|
| 287 |
1. Detect all brands automatically
|
| 288 |
-
2. Let you choose
|
| 289 |
3. Process and rename all files with proper numbering (preserving all file extensions)
|
| 290 |
4. Generate a PDF report showing all assets with original filenames and extensions
|
| 291 |
5. Create an Excel overview of the processed files (all file types)
|
|
|
|
| 69 |
|
| 70 |
# Brand numbering selection
|
| 71 |
st.subheader("Brand Numbering")
|
| 72 |
+
st.markdown(
|
| 73 |
+
"Select your **target brand(s) in order** — the first you pick becomes "
|
| 74 |
+
"`01`, the second `02`, and so on. Any brands you don't pick are numbered "
|
| 75 |
+
"afterwards in alphabetical order."
|
| 76 |
+
)
|
| 77 |
+
target_marken = st.multiselect(
|
| 78 |
+
"Target brand(s) — selection order sets the numbering",
|
| 79 |
options=sorted(marken_set),
|
| 80 |
+
default=[sorted(marken_set)[0]],
|
| 81 |
)
|
| 82 |
+
|
| 83 |
+
# Target brands first, in the exact order the user selected them.
|
| 84 |
+
marken_index = {}
|
| 85 |
+
aktuelle_nummer = 1
|
| 86 |
+
for marke in target_marken:
|
| 87 |
+
marken_index[marke] = f"{aktuelle_nummer:02d}"
|
| 88 |
+
aktuelle_nummer += 1
|
| 89 |
+
|
| 90 |
+
# Remaining (non-target) brands fill in afterwards, alphabetically.
|
| 91 |
for marke in sorted(marken_set):
|
| 92 |
+
if marke not in marken_index:
|
| 93 |
marken_index[marke] = f"{aktuelle_nummer:02d}"
|
| 94 |
aktuelle_nummer += 1
|
| 95 |
+
|
| 96 |
+
# erste_marke is only a fallback inside the PDF report (ignored when
|
| 97 |
+
# marken_index is passed); keep it pointing at brand 01 for safety.
|
| 98 |
+
erste_marke = target_marken[0] if target_marken else None
|
| 99 |
|
| 100 |
if st.button("Process Files and Generate Reports", type="primary"):
|
| 101 |
with st.spinner("Processing files..."):
|
|
|
|
| 300 |
st.markdown("""
|
| 301 |
Upload a ZIP file containing brand asset folders. The tool will:
|
| 302 |
1. Detect all brands automatically
|
| 303 |
+
2. Let you choose the target brand(s) and their order (first picked = 01, then 02, 03…; the rest follow alphabetically)
|
| 304 |
3. Process and rename all files with proper numbering (preserving all file extensions)
|
| 305 |
4. Generate a PDF report showing all assets with original filenames and extensions
|
| 306 |
5. Create an Excel overview of the processed files (all file types)
|
|
@@ -21,15 +21,24 @@ def center_on_canvas_tool():
|
|
| 21 |
)
|
| 22 |
|
| 23 |
if uploaded_file:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
"Canvas size (pixels):",
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
step=10,
|
| 31 |
-
key="canvas_size_input" # Added unique key
|
| 32 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Add unique key to the button
|
| 35 |
if st.button("Process Images", type="primary", key="process_canvas_images"):
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
if uploaded_file:
|
| 24 |
+
# Size picker: standard 500, high-res 1500, or a custom value.
|
| 25 |
+
size_choice = st.selectbox(
|
| 26 |
"Canvas size (pixels):",
|
| 27 |
+
options=["500", "1500", "Custom…"],
|
| 28 |
+
index=0,
|
| 29 |
+
key="canvas_size_choice",
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
+
if size_choice == "Custom…":
|
| 32 |
+
canvas_size = int(st.number_input(
|
| 33 |
+
"Custom canvas size (pixels):",
|
| 34 |
+
min_value=100,
|
| 35 |
+
max_value=10000,
|
| 36 |
+
value=500,
|
| 37 |
+
step=10,
|
| 38 |
+
key="canvas_size_input",
|
| 39 |
+
))
|
| 40 |
+
else:
|
| 41 |
+
canvas_size = int(size_choice)
|
| 42 |
|
| 43 |
# Add unique key to the button
|
| 44 |
if st.button("Process Images", type="primary", key="process_canvas_images"):
|
|
@@ -21,9 +21,27 @@ def resize_with_transparent_canvas_tool():
|
|
| 21 |
)
|
| 22 |
|
| 23 |
if uploaded_file:
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# Process button with unique key
|
| 28 |
if st.button("Process Images", type="primary", key="process_resize_transparent_images"):
|
| 29 |
temp_dir = None
|
|
@@ -67,9 +85,8 @@ def resize_with_transparent_canvas_tool():
|
|
| 67 |
with PILImage.open(file_path) as img:
|
| 68 |
img = img.convert("RGBA")
|
| 69 |
orig_w, orig_h = img.size
|
| 70 |
-
|
| 71 |
# Calculate scaling factor based on largest side
|
| 72 |
-
max_dimension = 400
|
| 73 |
if orig_w >= orig_h:
|
| 74 |
# Width is larger or equal
|
| 75 |
scale_factor = max_dimension / orig_w
|
|
@@ -104,7 +121,7 @@ def resize_with_transparent_canvas_tool():
|
|
| 104 |
Processing complete!
|
| 105 |
- ✅ Processed: {processed_count} images
|
| 106 |
- ❌ Errors: {error_count} images
|
| 107 |
-
- All images resized to
|
| 108 |
""")
|
| 109 |
|
| 110 |
if processed_count > 0:
|
|
@@ -123,7 +140,7 @@ def resize_with_transparent_canvas_tool():
|
|
| 123 |
st.download_button(
|
| 124 |
label="📥 Download Resized Images (ZIP)",
|
| 125 |
data=zip_buffer.getvalue(),
|
| 126 |
-
file_name="
|
| 127 |
mime="application/zip",
|
| 128 |
key="download_resized_transparent"
|
| 129 |
)
|
|
@@ -161,19 +178,20 @@ def resize_with_transparent_canvas_tool():
|
|
| 161 |
**How to use this tool:**
|
| 162 |
|
| 163 |
1. Upload a zip file containing images
|
| 164 |
-
2.
|
| 165 |
-
3.
|
| 166 |
-
4.
|
| 167 |
-
5.
|
| 168 |
-
|
| 169 |
-
|
|
|
|
| 170 |
- 1000x800 image → 400x320 image (width was larger)
|
| 171 |
-
- 600x1200 image → 200x400 image (height was larger)
|
| 172 |
- 400x400 image → 400x400 image (already correct size)
|
| 173 |
-
|
| 174 |
**Features:**
|
| 175 |
- Maintains original aspect ratio
|
| 176 |
- Outputs PNG files to preserve transparency
|
| 177 |
- Preserves folder structure
|
| 178 |
-
-
|
| 179 |
""")
|
|
|
|
| 21 |
)
|
| 22 |
|
| 23 |
if uploaded_file:
|
| 24 |
+
# Size picker: standard 400, high-res 1500, or a custom value.
|
| 25 |
+
size_choice = st.selectbox(
|
| 26 |
+
"Target size — longest side (pixels):",
|
| 27 |
+
options=["400", "1500", "Custom…"],
|
| 28 |
+
index=0,
|
| 29 |
+
key="resize_size_choice",
|
| 30 |
+
)
|
| 31 |
+
if size_choice == "Custom…":
|
| 32 |
+
max_dimension = int(st.number_input(
|
| 33 |
+
"Custom size (longest side, pixels):",
|
| 34 |
+
min_value=10,
|
| 35 |
+
max_value=10000,
|
| 36 |
+
value=400,
|
| 37 |
+
step=10,
|
| 38 |
+
key="resize_custom_size",
|
| 39 |
+
))
|
| 40 |
+
else:
|
| 41 |
+
max_dimension = int(size_choice)
|
| 42 |
+
|
| 43 |
+
st.info(f"Images will be resized to {max_dimension}px on the largest side (width or height), maintaining aspect ratio.")
|
| 44 |
+
|
| 45 |
# Process button with unique key
|
| 46 |
if st.button("Process Images", type="primary", key="process_resize_transparent_images"):
|
| 47 |
temp_dir = None
|
|
|
|
| 85 |
with PILImage.open(file_path) as img:
|
| 86 |
img = img.convert("RGBA")
|
| 87 |
orig_w, orig_h = img.size
|
| 88 |
+
|
| 89 |
# Calculate scaling factor based on largest side
|
|
|
|
| 90 |
if orig_w >= orig_h:
|
| 91 |
# Width is larger or equal
|
| 92 |
scale_factor = max_dimension / orig_w
|
|
|
|
| 121 |
Processing complete!
|
| 122 |
- ✅ Processed: {processed_count} images
|
| 123 |
- ❌ Errors: {error_count} images
|
| 124 |
+
- All images resized to {max_dimension}px on largest side
|
| 125 |
""")
|
| 126 |
|
| 127 |
if processed_count > 0:
|
|
|
|
| 140 |
st.download_button(
|
| 141 |
label="📥 Download Resized Images (ZIP)",
|
| 142 |
data=zip_buffer.getvalue(),
|
| 143 |
+
file_name=f"resized_{max_dimension}px_images.zip",
|
| 144 |
mime="application/zip",
|
| 145 |
key="download_resized_transparent"
|
| 146 |
)
|
|
|
|
| 178 |
**How to use this tool:**
|
| 179 |
|
| 180 |
1. Upload a zip file containing images
|
| 181 |
+
2. Choose the target size for the largest side — 400, 1500, or a custom value
|
| 182 |
+
3. All images will be resized to that many pixels on their largest side (width or height)
|
| 183 |
+
4. Aspect ratio is maintained - smaller dimension will be scaled proportionally
|
| 184 |
+
5. Click "Process Images"
|
| 185 |
+
6. Download the resized images with transparent backgrounds
|
| 186 |
+
|
| 187 |
+
**Examples (with a 400px target):**
|
| 188 |
- 1000x800 image → 400x320 image (width was larger)
|
| 189 |
+
- 600x1200 image → 200x400 image (height was larger)
|
| 190 |
- 400x400 image → 400x400 image (already correct size)
|
| 191 |
+
|
| 192 |
**Features:**
|
| 193 |
- Maintains original aspect ratio
|
| 194 |
- Outputs PNG files to preserve transparency
|
| 195 |
- Preserves folder structure
|
| 196 |
+
- Choose 400, 1500, or a custom maximum on the largest dimension
|
| 197 |
""")
|