Spaces:
Sleeping
Sleeping
Commit Β·
1988036
1
Parent(s): 1e41f1f
Fix temp file leak, remove duplicate code, align Python version
Browse files- Fix unreachable temp cleanup in tab5 (save temp_dir before clearing dict)
- Add shutil.rmtree cleanup to tabs 1, 2, 3, 7, 8 via try/finally
- Remove duplicate extract_zip_to_temp definition in helper.py (line 959)
- Remove wasted brand_counters first pass in helper.py
- Import extension sets from helper.py in tab2/3/7/8 instead of redefining
- Align Python version to 3.12 in runtime.txt and devcontainer.json
- Update README to list all 8 tabs (was missing Re-run Matrix and Place on Canvas)
- Remove committed __pycache__ from git tracking
Closes #2, closes #3, closes #4
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- .devcontainer/devcontainer.json +1 -1
- README.md +8 -3
- __pycache__/helper.cpython-312.pyc +0 -0
- __pycache__/helper.cpython-313.pyc +0 -0
- __pycache__/tab1.cpython-312.pyc +0 -0
- __pycache__/tab1.cpython-313.pyc +0 -0
- __pycache__/tab2.cpython-312.pyc +0 -0
- __pycache__/tab2.cpython-313.pyc +0 -0
- __pycache__/tab3.cpython-312.pyc +0 -0
- __pycache__/tab3.cpython-313.pyc +0 -0
- __pycache__/tab4.cpython-312.pyc +0 -0
- __pycache__/tab4.cpython-313.pyc +0 -0
- __pycache__/tab5.cpython-312.pyc +0 -0
- __pycache__/tab5.cpython-313.pyc +0 -0
- __pycache__/tab6.cpython-312.pyc +0 -0
- __pycache__/tab6.cpython-313.pyc +0 -0
- __pycache__/tab7.cpython-312.pyc +0 -0
- __pycache__/tab7.cpython-313.pyc +0 -0
- __pycache__/tab8.cpython-313.pyc +0 -0
- helper.py +6 -14
- runtime.txt +1 -1
- tab1.py +95 -91
- tab2.py +14 -7
- tab3.py +8 -8
- tab5.py +4 -3
- tab7.py +7 -8
- tab8.py +7 -8
.devcontainer/devcontainer.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"name": "Python 3",
|
| 3 |
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
| 4 |
-
"image": "mcr.microsoft.com/devcontainers/python:1-3.
|
| 5 |
"customizations": {
|
| 6 |
"codespaces": {
|
| 7 |
"openFiles": [
|
|
|
|
| 1 |
{
|
| 2 |
"name": "Python 3",
|
| 3 |
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
| 4 |
+
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bullseye",
|
| 5 |
"customizations": {
|
| 6 |
"codespaces": {
|
| 7 |
"openFiles": [
|
README.md
CHANGED
|
@@ -17,15 +17,16 @@ A comprehensive suite of tools for managing and processing brand assets, built w
|
|
| 17 |
|
| 18 |
## Features
|
| 19 |
|
| 20 |
-
This application provides
|
| 21 |
|
| 22 |
1. **Extract Images from Excel** - Extract embedded images from Excel worksheets (.xlsx files)
|
| 23 |
2. **Name Assets by Brand** - Rename files based on brand naming conventions
|
| 24 |
3. **Canvas White to Transparent** - Convert white backgrounds to transparent in images
|
| 25 |
4. **Asset Overview** - Generate PDF overview of your assets
|
| 26 |
5. **Name Stims by Block** - Organize and rename stimulus files by block with output file creation
|
| 27 |
-
6. **
|
| 28 |
-
7. **
|
|
|
|
| 29 |
|
| 30 |
## Usage
|
| 31 |
|
|
@@ -51,6 +52,10 @@ Simply select the tool you need from the tabs at the top of the application and
|
|
| 51 |
- Organize stimulus files by experimental blocks
|
| 52 |
- Create structured output files
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
### Resize
|
| 55 |
- Resize images to specific dimensions
|
| 56 |
- Maintain transparent backgrounds
|
|
|
|
| 17 |
|
| 18 |
## Features
|
| 19 |
|
| 20 |
+
This application provides 8 tools for brand asset management:
|
| 21 |
|
| 22 |
1. **Extract Images from Excel** - Extract embedded images from Excel worksheets (.xlsx files)
|
| 23 |
2. **Name Assets by Brand** - Rename files based on brand naming conventions
|
| 24 |
3. **Canvas White to Transparent** - Convert white backgrounds to transparent in images
|
| 25 |
4. **Asset Overview** - Generate PDF overview of your assets
|
| 26 |
5. **Name Stims by Block** - Organize and rename stimulus files by block with output file creation
|
| 27 |
+
6. **Re-run Matrix** - Re-process updated zip files and regenerate reports
|
| 28 |
+
7. **Resize** - Resize images while maintaining aspect ratio on transparent canvas
|
| 29 |
+
8. **Place on Canvas** - Center images on a custom canvas size
|
| 30 |
|
| 31 |
## Usage
|
| 32 |
|
|
|
|
| 52 |
- Organize stimulus files by experimental blocks
|
| 53 |
- Create structured output files
|
| 54 |
|
| 55 |
+
### Re-run Matrix
|
| 56 |
+
- Upload a modified zip from "Name Stims by Block"
|
| 57 |
+
- Re-analyze files and regenerate PDF/Excel reports
|
| 58 |
+
|
| 59 |
### Resize
|
| 60 |
- Resize images to specific dimensions
|
| 61 |
- Maintain transparent backgrounds
|
__pycache__/helper.cpython-312.pyc
DELETED
|
Binary file (52.8 kB)
|
|
|
__pycache__/helper.cpython-313.pyc
DELETED
|
Binary file (58.8 kB)
|
|
|
__pycache__/tab1.cpython-312.pyc
DELETED
|
Binary file (8.03 kB)
|
|
|
__pycache__/tab1.cpython-313.pyc
DELETED
|
Binary file (8.18 kB)
|
|
|
__pycache__/tab2.cpython-312.pyc
DELETED
|
Binary file (6.96 kB)
|
|
|
__pycache__/tab2.cpython-313.pyc
DELETED
|
Binary file (7.05 kB)
|
|
|
__pycache__/tab3.cpython-312.pyc
DELETED
|
Binary file (9.64 kB)
|
|
|
__pycache__/tab3.cpython-313.pyc
DELETED
|
Binary file (9.76 kB)
|
|
|
__pycache__/tab4.cpython-312.pyc
DELETED
|
Binary file (7.58 kB)
|
|
|
__pycache__/tab4.cpython-313.pyc
DELETED
|
Binary file (7.69 kB)
|
|
|
__pycache__/tab5.cpython-312.pyc
DELETED
|
Binary file (12.6 kB)
|
|
|
__pycache__/tab5.cpython-313.pyc
DELETED
|
Binary file (14.6 kB)
|
|
|
__pycache__/tab6.cpython-312.pyc
DELETED
|
Binary file (9.8 kB)
|
|
|
__pycache__/tab6.cpython-313.pyc
DELETED
|
Binary file (9.88 kB)
|
|
|
__pycache__/tab7.cpython-312.pyc
DELETED
|
Binary file (8.95 kB)
|
|
|
__pycache__/tab7.cpython-313.pyc
DELETED
|
Binary file (9.03 kB)
|
|
|
__pycache__/tab8.cpython-313.pyc
DELETED
|
Binary file (28.8 kB)
|
|
|
helper.py
CHANGED
|
@@ -114,29 +114,26 @@ def process_files(input_folder, marken_index, output_root):
|
|
| 114 |
continue
|
| 115 |
blocknummer = re.sub(r'\D', '', subfolder.name)[:2].zfill(2)
|
| 116 |
|
| 117 |
-
brand_counters = defaultdict(int)
|
| 118 |
-
|
| 119 |
files_to_process = []
|
| 120 |
for file in sorted(subfolder.iterdir()):
|
| 121 |
# Skip if not a file
|
| 122 |
if not file.is_file():
|
| 123 |
continue
|
| 124 |
-
|
| 125 |
# Skip files without allowed extensions
|
| 126 |
if file.suffix.lower() not in ALL_ALLOWED_EXTENSIONS and file.suffix != '':
|
| 127 |
continue
|
| 128 |
-
|
| 129 |
# Accept files with no extension as well
|
| 130 |
marke = extract_brand(file.stem)
|
| 131 |
-
|
| 132 |
# CRITICAL FIX: Skip files where brand extraction failed or brand not in index
|
| 133 |
if not marke or marke == "unknown" or marke not in marken_index:
|
| 134 |
print(f"Warning: Skipping file {file.name} - brand '{marke}' not found in marken_index")
|
| 135 |
continue
|
| 136 |
-
|
| 137 |
-
brand_counters[marke] += 1
|
| 138 |
files_to_process.append((file, marke))
|
| 139 |
-
|
| 140 |
brand_counters = defaultdict(int)
|
| 141 |
|
| 142 |
for file, marke in files_to_process:
|
|
@@ -953,15 +950,10 @@ def generate_pdf_report(input_folder, erste_marke=None):
|
|
| 953 |
try:
|
| 954 |
doc.build(alle_elements)
|
| 955 |
pdf_buffer.seek(0)
|
|
|
|
| 956 |
return pdf_buffer, None
|
| 957 |
except Exception as e:
|
| 958 |
return None, f"Error generating PDF: {str(e)}"
|
| 959 |
-
def extract_zip_to_temp(uploaded_file):
|
| 960 |
-
"""Extract uploaded zip file to temporary directory"""
|
| 961 |
-
temp_dir = tempfile.mkdtemp()
|
| 962 |
-
with zipfile.ZipFile(uploaded_file, 'r') as zip_ref:
|
| 963 |
-
zip_ref.extractall(temp_dir)
|
| 964 |
-
return temp_dir
|
| 965 |
|
| 966 |
def clean_letters_only(text):
|
| 967 |
return re.sub(r'[^A-Za-z]', '', text)
|
|
|
|
| 114 |
continue
|
| 115 |
blocknummer = re.sub(r'\D', '', subfolder.name)[:2].zfill(2)
|
| 116 |
|
|
|
|
|
|
|
| 117 |
files_to_process = []
|
| 118 |
for file in sorted(subfolder.iterdir()):
|
| 119 |
# Skip if not a file
|
| 120 |
if not file.is_file():
|
| 121 |
continue
|
| 122 |
+
|
| 123 |
# Skip files without allowed extensions
|
| 124 |
if file.suffix.lower() not in ALL_ALLOWED_EXTENSIONS and file.suffix != '':
|
| 125 |
continue
|
| 126 |
+
|
| 127 |
# Accept files with no extension as well
|
| 128 |
marke = extract_brand(file.stem)
|
| 129 |
+
|
| 130 |
# CRITICAL FIX: Skip files where brand extraction failed or brand not in index
|
| 131 |
if not marke or marke == "unknown" or marke not in marken_index:
|
| 132 |
print(f"Warning: Skipping file {file.name} - brand '{marke}' not found in marken_index")
|
| 133 |
continue
|
| 134 |
+
|
|
|
|
| 135 |
files_to_process.append((file, marke))
|
| 136 |
+
|
| 137 |
brand_counters = defaultdict(int)
|
| 138 |
|
| 139 |
for file, marke in files_to_process:
|
|
|
|
| 950 |
try:
|
| 951 |
doc.build(alle_elements)
|
| 952 |
pdf_buffer.seek(0)
|
| 953 |
+
pdf_buffer.seek(0)
|
| 954 |
return pdf_buffer, None
|
| 955 |
except Exception as e:
|
| 956 |
return None, f"Error generating PDF: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 957 |
|
| 958 |
def clean_letters_only(text):
|
| 959 |
return re.sub(r'[^A-Za-z]', '', text)
|
runtime.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
python-3.
|
|
|
|
| 1 |
+
python-3.12
|
tab1.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
|
|
|
| 3 |
import tempfile
|
| 4 |
import zipfile
|
| 5 |
from pathlib import Path
|
|
@@ -73,99 +74,102 @@ def excel_extractor_tool():
|
|
| 73 |
|
| 74 |
if st.button("Extract Images", type="primary", key="extract_btn_fixed"):
|
| 75 |
temp_dir = tempfile.mkdtemp()
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
else:
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
else:
|
| 129 |
-
st.info(
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
progress_bar.empty()
|
| 133 |
-
|
| 134 |
-
# Show detailed extraction results
|
| 135 |
-
with st.expander("Detailed Extraction Results"):
|
| 136 |
-
for result in extraction_results:
|
| 137 |
-
st.write(result)
|
| 138 |
-
|
| 139 |
-
if total_images > 0:
|
| 140 |
-
st.success(f"Total: {total_images} images extracted from {len(uploaded_files)} file(s)")
|
| 141 |
-
|
| 142 |
-
# Show extracted files summary
|
| 143 |
-
with st.expander("Extracted Files Summary"):
|
| 144 |
-
for file_path in all_extracted_files[:20]: # Show first 20
|
| 145 |
-
st.write(f"π {os.path.relpath(file_path, temp_dir)}")
|
| 146 |
-
if len(all_extracted_files) > 20:
|
| 147 |
-
st.info(f"Showing first 20 files. Total extracted: {len(all_extracted_files)}")
|
| 148 |
-
|
| 149 |
-
# Create zip file with all extracted images
|
| 150 |
-
zip_buffer = io.BytesIO()
|
| 151 |
-
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 152 |
-
for file_path in all_extracted_files:
|
| 153 |
-
# Get relative path for zip structure
|
| 154 |
-
rel_path = os.path.relpath(file_path, temp_dir)
|
| 155 |
-
zip_file.write(file_path, rel_path)
|
| 156 |
-
|
| 157 |
-
zip_buffer.seek(0)
|
| 158 |
-
|
| 159 |
-
# Download button for all extracted images
|
| 160 |
-
st.download_button(
|
| 161 |
-
label="Download All Extracted Images (ZIP)",
|
| 162 |
-
data=zip_buffer.getvalue(),
|
| 163 |
-
file_name="extracted_images_by_sheet.zip",
|
| 164 |
-
mime="application/zip"
|
| 165 |
-
)
|
| 166 |
-
|
| 167 |
-
else:
|
| 168 |
-
st.info("No images were found in the selected sheets of the uploaded Excel file(s).")
|
| 169 |
|
| 170 |
else:
|
| 171 |
st.info("Please upload Excel file(s) to get started.")
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
+
import shutil
|
| 4 |
import tempfile
|
| 5 |
import zipfile
|
| 6 |
from pathlib import Path
|
|
|
|
| 74 |
|
| 75 |
if st.button("Extract Images", type="primary", key="extract_btn_fixed"):
|
| 76 |
temp_dir = tempfile.mkdtemp()
|
| 77 |
+
try:
|
| 78 |
+
all_extracted_files = []
|
| 79 |
+
total_images = 0
|
| 80 |
+
extraction_results = []
|
| 81 |
+
|
| 82 |
+
progress_bar = st.progress(0)
|
| 83 |
+
status_text = st.empty()
|
| 84 |
+
|
| 85 |
+
for i, uploaded_file in enumerate(uploaded_files):
|
| 86 |
+
file_name = uploaded_file.name
|
| 87 |
+
selected_sheets = sheet_selections.get(file_name, [])
|
| 88 |
+
|
| 89 |
+
if not selected_sheets:
|
| 90 |
+
st.warning(f"No sheets selected for {file_name}, skipping...")
|
| 91 |
+
continue
|
| 92 |
+
|
| 93 |
+
status_text.text(f"Processing {file_name}...")
|
| 94 |
+
progress_bar.progress((i + 1) / len(uploaded_files))
|
| 95 |
+
|
| 96 |
+
# Save uploaded file temporarily
|
| 97 |
+
temp_xlsx_path = os.path.join(temp_dir, file_name)
|
| 98 |
+
with open(temp_xlsx_path, 'wb') as f:
|
| 99 |
+
f.write(uploaded_file.getbuffer())
|
| 100 |
+
|
| 101 |
+
# Create output directory for this file
|
| 102 |
+
output_dir = os.path.join(temp_dir, f"{Path(file_name).stem}_images")
|
| 103 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 104 |
+
|
| 105 |
+
# Extract images for each selected sheet individually
|
| 106 |
+
file_total = 0
|
| 107 |
+
for sheet_name in selected_sheets:
|
| 108 |
+
sheet_output_dir = os.path.join(output_dir, sheet_name.replace('/', '_').replace('\\', '_'))
|
| 109 |
+
os.makedirs(sheet_output_dir, exist_ok=True)
|
| 110 |
+
|
| 111 |
+
count, extracted_files, error, _ = extract_images_from_xlsx_by_sheet(
|
| 112 |
+
temp_xlsx_path,
|
| 113 |
+
sheet_output_dir,
|
| 114 |
+
sheet_name
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
if error:
|
| 118 |
+
st.warning(f"Issue with {file_name} - {sheet_name}: {error}")
|
| 119 |
+
|
| 120 |
+
if count > 0:
|
| 121 |
+
extraction_results.append(f"β
{file_name} - {sheet_name}: {count} images")
|
| 122 |
+
all_extracted_files.extend(extracted_files)
|
| 123 |
+
file_total += count
|
| 124 |
+
else:
|
| 125 |
+
extraction_results.append(f"βͺ {file_name} - {sheet_name}: No images found")
|
| 126 |
+
|
| 127 |
+
total_images += file_total
|
| 128 |
+
if file_total > 0:
|
| 129 |
+
st.success(f"Extracted {file_total} images from {file_name}")
|
| 130 |
else:
|
| 131 |
+
st.info(f"No images found in {file_name}")
|
| 132 |
+
|
| 133 |
+
status_text.empty()
|
| 134 |
+
progress_bar.empty()
|
| 135 |
+
|
| 136 |
+
# Show detailed extraction results
|
| 137 |
+
with st.expander("Detailed Extraction Results"):
|
| 138 |
+
for result in extraction_results:
|
| 139 |
+
st.write(result)
|
| 140 |
+
|
| 141 |
+
if total_images > 0:
|
| 142 |
+
st.success(f"Total: {total_images} images extracted from {len(uploaded_files)} file(s)")
|
| 143 |
+
|
| 144 |
+
# Show extracted files summary
|
| 145 |
+
with st.expander("Extracted Files Summary"):
|
| 146 |
+
for file_path in all_extracted_files[:20]: # Show first 20
|
| 147 |
+
st.write(f"π {os.path.relpath(file_path, temp_dir)}")
|
| 148 |
+
if len(all_extracted_files) > 20:
|
| 149 |
+
st.info(f"Showing first 20 files. Total extracted: {len(all_extracted_files)}")
|
| 150 |
+
|
| 151 |
+
# Create zip file with all extracted images
|
| 152 |
+
zip_buffer = io.BytesIO()
|
| 153 |
+
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 154 |
+
for file_path in all_extracted_files:
|
| 155 |
+
# Get relative path for zip structure
|
| 156 |
+
rel_path = os.path.relpath(file_path, temp_dir)
|
| 157 |
+
zip_file.write(file_path, rel_path)
|
| 158 |
+
|
| 159 |
+
zip_buffer.seek(0)
|
| 160 |
+
|
| 161 |
+
# Download button for all extracted images
|
| 162 |
+
st.download_button(
|
| 163 |
+
label="Download All Extracted Images (ZIP)",
|
| 164 |
+
data=zip_buffer.getvalue(),
|
| 165 |
+
file_name="extracted_images_by_sheet.zip",
|
| 166 |
+
mime="application/zip"
|
| 167 |
+
)
|
| 168 |
+
|
| 169 |
else:
|
| 170 |
+
st.info("No images were found in the selected sheets of the uploaded Excel file(s).")
|
| 171 |
+
finally:
|
| 172 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
else:
|
| 175 |
st.info("Please upload Excel file(s) to get started.")
|
tab2.py
CHANGED
|
@@ -1,17 +1,20 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
import shutil
|
|
|
|
| 4 |
import zipfile
|
| 5 |
from pathlib import Path
|
| 6 |
import pandas as pd
|
| 7 |
import streamlit as st
|
| 8 |
-
from helper import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv'}
|
| 12 |
-
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv'}
|
| 13 |
-
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma'}
|
| 14 |
-
ALL_ALLOWED_EXTENSIONS = ALLOWED_IMAGE_EXTENSIONS.union(ALLOWED_TEXT_EXTENSIONS).union(ALLOWED_VIDEO_EXTENSIONS).union(ALLOWED_AUDIO_EXTENSIONS)
|
| 15 |
|
| 16 |
def file_renamer_tool():
|
| 17 |
st.header("Brand File Renamer")
|
|
@@ -26,6 +29,7 @@ def file_renamer_tool():
|
|
| 26 |
)
|
| 27 |
|
| 28 |
if uploaded_file is not None:
|
|
|
|
| 29 |
try:
|
| 30 |
# Extract zip file
|
| 31 |
with st.spinner("Extracting zip file..."):
|
|
@@ -108,7 +112,10 @@ def file_renamer_tool():
|
|
| 108 |
|
| 109 |
except Exception as e:
|
| 110 |
st.error(f"An error occurred: {str(e)}")
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
else:
|
| 113 |
st.info("π Please upload a zip file to get started.")
|
| 114 |
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
import shutil
|
| 4 |
+
import tempfile
|
| 5 |
import zipfile
|
| 6 |
from pathlib import Path
|
| 7 |
import pandas as pd
|
| 8 |
import streamlit as st
|
| 9 |
+
from helper import (
|
| 10 |
+
extract_zip_to_temp,
|
| 11 |
+
ALLOWED_IMAGE_EXTENSIONS,
|
| 12 |
+
ALLOWED_TEXT_EXTENSIONS,
|
| 13 |
+
ALLOWED_VIDEO_EXTENSIONS,
|
| 14 |
+
ALLOWED_AUDIO_EXTENSIONS,
|
| 15 |
+
)
|
| 16 |
|
| 17 |
+
ALL_ALLOWED_EXTENSIONS = ALLOWED_IMAGE_EXTENSIONS | ALLOWED_TEXT_EXTENSIONS | ALLOWED_VIDEO_EXTENSIONS | ALLOWED_AUDIO_EXTENSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def file_renamer_tool():
|
| 20 |
st.header("Brand File Renamer")
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
if uploaded_file is not None:
|
| 32 |
+
temp_dir = None
|
| 33 |
try:
|
| 34 |
# Extract zip file
|
| 35 |
with st.spinner("Extracting zip file..."):
|
|
|
|
| 112 |
|
| 113 |
except Exception as e:
|
| 114 |
st.error(f"An error occurred: {str(e)}")
|
| 115 |
+
finally:
|
| 116 |
+
if temp_dir:
|
| 117 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 118 |
+
|
| 119 |
else:
|
| 120 |
st.info("π Please upload a zip file to get started.")
|
| 121 |
|
tab3.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
|
|
|
| 3 |
import tempfile
|
| 4 |
import zipfile
|
| 5 |
import cv2
|
|
@@ -9,11 +10,7 @@ from PIL import Image as PILImage
|
|
| 9 |
from reportlab.lib.pagesizes import A4
|
| 10 |
from reportlab.lib.styles import getSampleStyleSheet
|
| 11 |
|
| 12 |
-
|
| 13 |
-
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv'}
|
| 14 |
-
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv'}
|
| 15 |
-
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma'}
|
| 16 |
-
ALL_ALLOWED_EXTENSIONS = ALLOWED_IMAGE_EXTENSIONS.union(ALLOWED_TEXT_EXTENSIONS).union(ALLOWED_VIDEO_EXTENSIONS).union(ALLOWED_AUDIO_EXTENSIONS)
|
| 17 |
|
| 18 |
def white_to_transparent_tool():
|
| 19 |
st.header("White Background to Transparent")
|
|
@@ -38,8 +35,9 @@ def white_to_transparent_tool():
|
|
| 38 |
if uploaded_files:
|
| 39 |
if st.button("Process Images", type="primary"):
|
| 40 |
temp_dir = tempfile.mkdtemp()
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
# Save uploaded files to temp dir
|
| 45 |
for uploaded_file in uploaded_files:
|
|
@@ -139,7 +137,9 @@ def white_to_transparent_tool():
|
|
| 139 |
|
| 140 |
if failed_files:
|
| 141 |
st.warning(f"β οΈ Failed to process {len(failed_files)} files: {', '.join(failed_files)}")
|
| 142 |
-
|
|
|
|
|
|
|
| 143 |
else:
|
| 144 |
st.info("π Please upload image files to get started.")
|
| 145 |
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
+
import shutil
|
| 4 |
import tempfile
|
| 5 |
import zipfile
|
| 6 |
import cv2
|
|
|
|
| 10 |
from reportlab.lib.pagesizes import A4
|
| 11 |
from reportlab.lib.styles import getSampleStyleSheet
|
| 12 |
|
| 13 |
+
from helper import ALLOWED_IMAGE_EXTENSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def white_to_transparent_tool():
|
| 16 |
st.header("White Background to Transparent")
|
|
|
|
| 35 |
if uploaded_files:
|
| 36 |
if st.button("Process Images", type="primary"):
|
| 37 |
temp_dir = tempfile.mkdtemp()
|
| 38 |
+
try:
|
| 39 |
+
processed_files = []
|
| 40 |
+
failed_files = []
|
| 41 |
|
| 42 |
# Save uploaded files to temp dir
|
| 43 |
for uploaded_file in uploaded_files:
|
|
|
|
| 137 |
|
| 138 |
if failed_files:
|
| 139 |
st.warning(f"β οΈ Failed to process {len(failed_files)} files: {', '.join(failed_files)}")
|
| 140 |
+
finally:
|
| 141 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 142 |
+
|
| 143 |
else:
|
| 144 |
st.info("π Please upload image files to get started.")
|
| 145 |
|
tab5.py
CHANGED
|
@@ -206,12 +206,13 @@ def brand_renamer_tool():
|
|
| 206 |
|
| 207 |
# Option to start over
|
| 208 |
if st.button("π Process New File", help="Clear results and upload a new file"):
|
|
|
|
| 209 |
st.session_state.processing_complete = False
|
| 210 |
st.session_state.processed_data = {}
|
| 211 |
-
if
|
| 212 |
try:
|
| 213 |
-
shutil.rmtree(
|
| 214 |
-
except:
|
| 215 |
pass
|
| 216 |
st.rerun()
|
| 217 |
|
|
|
|
| 206 |
|
| 207 |
# Option to start over
|
| 208 |
if st.button("π Process New File", help="Clear results and upload a new file"):
|
| 209 |
+
temp_dir = st.session_state.processed_data.get('temp_dir')
|
| 210 |
st.session_state.processing_complete = False
|
| 211 |
st.session_state.processed_data = {}
|
| 212 |
+
if temp_dir:
|
| 213 |
try:
|
| 214 |
+
shutil.rmtree(temp_dir)
|
| 215 |
+
except Exception:
|
| 216 |
pass
|
| 217 |
st.rerun()
|
| 218 |
|
tab7.py
CHANGED
|
@@ -1,16 +1,11 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
|
|
|
| 3 |
import zipfile
|
| 4 |
import streamlit as st
|
| 5 |
from PIL import Image as PILImage
|
| 6 |
|
| 7 |
-
from helper import extract_zip_to_temp
|
| 8 |
-
|
| 9 |
-
ALLOWED_IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp'}
|
| 10 |
-
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv'}
|
| 11 |
-
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv'}
|
| 12 |
-
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma'}
|
| 13 |
-
ALL_ALLOWED_EXTENSIONS = ALLOWED_IMAGE_EXTENSIONS.union(ALLOWED_TEXT_EXTENSIONS).union(ALLOWED_VIDEO_EXTENSIONS).union(ALLOWED_AUDIO_EXTENSIONS)
|
| 14 |
|
| 15 |
|
| 16 |
def center_on_canvas_tool():
|
|
@@ -38,6 +33,7 @@ def center_on_canvas_tool():
|
|
| 38 |
|
| 39 |
# Add unique key to the button
|
| 40 |
if st.button("Process Images", type="primary", key="process_canvas_images"):
|
|
|
|
| 41 |
try:
|
| 42 |
# Extract zip file
|
| 43 |
with st.spinner("Extracting zip file..."):
|
|
@@ -138,7 +134,10 @@ def center_on_canvas_tool():
|
|
| 138 |
|
| 139 |
except Exception as e:
|
| 140 |
st.error(f"An error occurred: {str(e)}")
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 142 |
else:
|
| 143 |
st.info("π Please upload a zip file with images to process.")
|
| 144 |
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
+
import shutil
|
| 4 |
import zipfile
|
| 5 |
import streamlit as st
|
| 6 |
from PIL import Image as PILImage
|
| 7 |
|
| 8 |
+
from helper import extract_zip_to_temp, ALLOWED_IMAGE_EXTENSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def center_on_canvas_tool():
|
|
|
|
| 33 |
|
| 34 |
# Add unique key to the button
|
| 35 |
if st.button("Process Images", type="primary", key="process_canvas_images"):
|
| 36 |
+
temp_dir = None
|
| 37 |
try:
|
| 38 |
# Extract zip file
|
| 39 |
with st.spinner("Extracting zip file..."):
|
|
|
|
| 134 |
|
| 135 |
except Exception as e:
|
| 136 |
st.error(f"An error occurred: {str(e)}")
|
| 137 |
+
finally:
|
| 138 |
+
if temp_dir:
|
| 139 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 140 |
+
|
| 141 |
else:
|
| 142 |
st.info("π Please upload a zip file with images to process.")
|
| 143 |
|
tab8.py
CHANGED
|
@@ -1,16 +1,11 @@
|
|
| 1 |
import io
|
| 2 |
import os
|
|
|
|
| 3 |
import zipfile
|
| 4 |
import streamlit as st
|
| 5 |
from PIL import Image as PILImage
|
| 6 |
|
| 7 |
-
from helper import extract_zip_to_temp
|
| 8 |
-
|
| 9 |
-
ALLOWED_IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp'}
|
| 10 |
-
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv'}
|
| 11 |
-
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv'}
|
| 12 |
-
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma'}
|
| 13 |
-
ALL_ALLOWED_EXTENSIONS = ALLOWED_IMAGE_EXTENSIONS.union(ALLOWED_TEXT_EXTENSIONS).union(ALLOWED_VIDEO_EXTENSIONS).union(ALLOWED_AUDIO_EXTENSIONS)
|
| 14 |
|
| 15 |
|
| 16 |
def resize_with_transparent_canvas_tool():
|
|
@@ -31,6 +26,7 @@ def resize_with_transparent_canvas_tool():
|
|
| 31 |
|
| 32 |
# Process button with unique key
|
| 33 |
if st.button("Process Images", type="primary", key="process_resize_transparent_images"):
|
|
|
|
| 34 |
try:
|
| 35 |
# Extract zip file
|
| 36 |
with st.spinner("Extracting zip file..."):
|
|
@@ -152,7 +148,10 @@ def resize_with_transparent_canvas_tool():
|
|
| 152 |
|
| 153 |
except Exception as e:
|
| 154 |
st.error(f"An error occurred during processing: {str(e)}")
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
| 156 |
else:
|
| 157 |
st.info("π Please upload a zip file with images to resize.")
|
| 158 |
|
|
|
|
| 1 |
import io
|
| 2 |
import os
|
| 3 |
+
import shutil
|
| 4 |
import zipfile
|
| 5 |
import streamlit as st
|
| 6 |
from PIL import Image as PILImage
|
| 7 |
|
| 8 |
+
from helper import extract_zip_to_temp, ALLOWED_IMAGE_EXTENSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
def resize_with_transparent_canvas_tool():
|
|
|
|
| 26 |
|
| 27 |
# Process button with unique key
|
| 28 |
if st.button("Process Images", type="primary", key="process_resize_transparent_images"):
|
| 29 |
+
temp_dir = None
|
| 30 |
try:
|
| 31 |
# Extract zip file
|
| 32 |
with st.spinner("Extracting zip file..."):
|
|
|
|
| 148 |
|
| 149 |
except Exception as e:
|
| 150 |
st.error(f"An error occurred during processing: {str(e)}")
|
| 151 |
+
finally:
|
| 152 |
+
if temp_dir:
|
| 153 |
+
shutil.rmtree(temp_dir, ignore_errors=True)
|
| 154 |
+
|
| 155 |
else:
|
| 156 |
st.info("π Please upload a zip file with images to resize.")
|
| 157 |
|