File size: 3,314 Bytes
bbf2a31
d5089aa
 
 
bbf2a31
 
d5089aa
bbf2a31
 
 
 
f05d877
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dc6fb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f05d877
 
 
 
bbf2a31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
title: Image Editor
emoji: 🐠
colorFrom: green
colorTo: indigo
sdk: gradio
sdk_version: 5.37.0
app_file: app.py
pinned: false
---

# ImageResizer

Batch download, resize, and export product images via a Gradio web UI. Designed for e-commerce catalog workflows where image URLs live in Excel workbooks.

## Run locally

```bash
pip install -r requirements.txt
python app.py
```

Or install as a package:

```bash
pip install -e .
python app.py
```

## Project layout

```
ImageResizer/
β”œβ”€β”€ app.py                  # Hugging Face Spaces entry point
β”œβ”€β”€ Template.xlsm           # Workbook template (download from UI in workbook mode)
β”œβ”€β”€ image_resizer/
β”‚   β”œβ”€β”€ config.py           # Constants and settings
β”‚   β”œβ”€β”€ models.py           # Shared types (ImageItem, ProcessResult)
β”‚   β”œβ”€β”€ failure_log.py      # Failed download logging
β”‚   β”œβ”€β”€ downloader.py       # HTTP / cloudscraper / Selenium downloads
β”‚   β”œβ”€β”€ image_ops.py        # Resize, format conversion, save
β”‚   β”œβ”€β”€ pipeline.py         # Download + process + ZIP orchestration
β”‚   β”œβ”€β”€ workbook.py         # Excel workbook parsing
β”‚   β”œβ”€β”€ processor.py        # High-level processing (no UI)
β”‚   └── ui/
β”‚       β”œβ”€β”€ theme.py        # CSS and HTML assets
β”‚       β”œβ”€β”€ handlers.py     # Gradio event handlers
β”‚       └── demo.py         # build_demo() β€” Gradio Blocks assembly
β”œβ”€β”€ requirements.txt
└── pyproject.toml
```

## Input modes

- **Upload Workbook** β€” Parse `.xlsx`/`.xlsm` files with an `ItemCode` column and URL/image/link columns. Use **Download Template** beside the upload field to get `Template.xlsm` from the project root.
- **Upload Images** β€” Process local image files or a single pasted URL

## Workbook template

Place `Template.xlsm` at the repository root. The app serves it via the **Download Template** button in workbook mode. Commit this file to git so Hugging Face Spaces can serve it.

### Clear Data button (Cleared Data sheet)

`ClearClearedData.bas` provides **Clear Data** for the Cleared Data worksheet (clears B2 onward; keeps row 1 and column A).

1. Import `ClearClearedData.bas`.
2. Run macro `CreateClearDataButton` once, **or** add a Form Control button on Cleared Data assigned to `ClearClearedDataSheet`.
3. Clicking the button asks for confirmation, then clears data contents only (no row/column/format deletion).

### Amazon URL auto-cleaner (Excel VBA)

`AmazonUrlCleaner.bas` strips Amazon image size modifiers (e.g. `._AC_SL1500_`) automatically when URLs are typed or pasted.

**Scope:** Manual and WriteBuffer sheets only, cells from B2 onward (never row 1 or column A).

**Install into `Template.xlsm`:**

1. Open the workbook β†’ Alt+F11.
2. File β†’ Import File β†’ select `AmazonUrlCleaner.bas` only.
3. Open **ThisWorkbook** (do not import the txt file). Paste the `Workbook_SheetChange` procedure from `AmazonUrlCleaner_ThisWorkbook.txt`.
4. Debug β†’ Compile VBAProject, then save as `.xlsm`.

## Hugging Face Spaces

This repo is configured for [Hugging Face Spaces](https://huggingface.co/docs/hub/spaces-config-reference). The Space uses root `app.py` as the entry point.

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference