| --- |
| title: Database Image Alt-Text Generator |
| emoji: 🖼️ |
| colorFrom: blue |
| colorTo: purple |
| sdk: gradio |
| app_file: app.py |
| pinned: false |
| --- |
| |
| # Database Image Alt-Text Generator |
|
|
| This Gradio Space accepts a CSV, TSV, XLSX, or XLSM table with one encoded image per row, generates alt text with a Hugging Face vision-language model, and returns the original table with added result columns. |
|
|
| ## Supported image-cell representations |
|
|
| - `TFLiveData` header followed by original image bytes |
| - Base64 |
| - Hexadecimal |
| - Escaped byte strings such as `\\x89PNG...` |
| - Latin-1-preserved binary strings |
| - Python byte literals such as `b'...'` |
|
|
| The supplied example has this form: |
|
|
| ```text |
| <TFLiveData extension=".ico" name="FileCabinet.ico" mime="image/x-icon" stamp="...">[ICO bytes] |
| ``` |
|
|
| The app removes the metadata header, opens the remaining bytes with Pillow, and converts the result to PNG before inference. |
|
|
| ## Deploy on Hugging Face Spaces |
|
|
| 1. Create a new **Gradio** Space. |
| 2. Upload `app.py`, `requirements.txt`, and this `README.md` to the Space repository. |
| 3. Create a Hugging Face access token with **Inference Providers** permission. |
| 4. In the Space settings, add a private repository secret named `HF_TOKEN`. |
| 5. Keep the default model or set the optional `VISION_MODEL` repository variable. |
| 6. For confidential database images, make the Space private and confirm that the selected inference provider is approved by your organization. |
|
|
| ## Recommended database export format |
|
|
| Base64 is the safest representation for CSV and Excel because arbitrary binary bytes, NUL characters, tabs, and line breaks can corrupt delimited files. If possible, export each image field as base64 while retaining a record ID and MIME-type column. |
|
|
| Suggested input: |
|
|
| | image_id | image_data | mime_type | |
| |---|---|---| |
| | 1001 | `AAABAAE...` | `image/x-icon` | |
| |
| ## Output columns |
| |
| - `record_id` |
| - `alt_text` |
| - `status` |
| - `error` |
| - `source_name` |
| - `source_mime` |
| - `processed_dimensions` |
|
|
| Rows that fail decoding or inference remain in the output and receive `status = error` with a diagnostic message. |
|
|
|
|