Spaces:
Sleeping
Sleeping
Gnanashri Kota Venkatesh commited on
Update tab5.py
Browse files
tab5.py
CHANGED
|
@@ -79,17 +79,33 @@ def brand_renamer_tool():
|
|
| 79 |
output_folder
|
| 80 |
)
|
| 81 |
|
| 82 |
-
#
|
| 83 |
for file_path in output_folder.iterdir():
|
| 84 |
-
if file_path.is_file()
|
| 85 |
-
#
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
# Generate PDF with extensions -
|
| 93 |
pdf_buffer, error = generate_filename_based_pdf_report_with_extensions(
|
| 94 |
input_folder,
|
| 95 |
erste_marke,
|
|
@@ -104,7 +120,8 @@ def brand_renamer_tool():
|
|
| 104 |
zip_buffer = io.BytesIO()
|
| 105 |
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 106 |
for file in output_folder.iterdir():
|
| 107 |
-
|
|
|
|
| 108 |
zip_buffer.seek(0)
|
| 109 |
|
| 110 |
# Create combined download with all files
|
|
@@ -112,7 +129,8 @@ def brand_renamer_tool():
|
|
| 112 |
with zipfile.ZipFile(combined_zip_buffer, 'w', zipfile.ZIP_DEFLATED) as combined_zip:
|
| 113 |
# Add processed files
|
| 114 |
for file in output_folder.iterdir():
|
| 115 |
-
|
|
|
|
| 116 |
|
| 117 |
# Add PDF report if available
|
| 118 |
if pdf_buffer:
|
|
@@ -142,10 +160,10 @@ def brand_renamer_tool():
|
|
| 142 |
if st.session_state.processing_complete:
|
| 143 |
st.success("Processing complete!")
|
| 144 |
|
| 145 |
-
# Display a preview of processed names with extensions
|
| 146 |
with st.expander("Preview Processed Names"):
|
| 147 |
if 'renamed_files' in st.session_state.processed_data:
|
| 148 |
-
st.write("Sample processed filenames (with
|
| 149 |
# Handle the case where renamed_files might be a defaultdict
|
| 150 |
renamed_files_data = st.session_state.processed_data['renamed_files']
|
| 151 |
|
|
@@ -157,7 +175,9 @@ def brand_renamer_tool():
|
|
| 157 |
for brand_name, files in list(brand_data.items())[:2]: # First 2 brands per folder
|
| 158 |
for file_path, new_name in files[:2]: # First 2 files per brand
|
| 159 |
if isinstance(new_name, str):
|
| 160 |
-
|
|
|
|
|
|
|
| 161 |
sample_files.append((Path(file_path).name, pdf_name))
|
| 162 |
if len(sample_files) >= 10:
|
| 163 |
break
|
|
@@ -253,8 +273,15 @@ def brand_renamer_tool():
|
|
| 253 |
Upload a ZIP file containing brand asset folders. The tool will:
|
| 254 |
1. Detect all brands automatically
|
| 255 |
2. Let you choose which brand gets number 01
|
| 256 |
-
3. Process and rename all files with proper numbering
|
| 257 |
-
4. Generate a PDF report showing all assets with filenames
|
| 258 |
-
5. Create an Excel overview of the processed files
|
| 259 |
6. Package everything for easy download
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
""")
|
|
|
|
| 79 |
output_folder
|
| 80 |
)
|
| 81 |
|
| 82 |
+
# Rename files to preserve original extensions instead of forcing .png
|
| 83 |
for file_path in output_folder.iterdir():
|
| 84 |
+
if file_path.is_file():
|
| 85 |
+
# Get original extension (if it exists)
|
| 86 |
+
original_ext = file_path.suffix.lower()
|
| 87 |
+
|
| 88 |
+
# If file has no extension, try to detect from content or keep as is
|
| 89 |
+
if not original_ext:
|
| 90 |
+
# Try to find original extension from renamed_files mapping
|
| 91 |
+
original_name = None
|
| 92 |
+
for folder_data in renamed_files.values():
|
| 93 |
+
for brand_data in folder_data.values():
|
| 94 |
+
for orig_path, new_name in brand_data:
|
| 95 |
+
if Path(new_name).name == file_path.name:
|
| 96 |
+
original_name = Path(orig_path).name
|
| 97 |
+
break
|
| 98 |
+
|
| 99 |
+
if original_name:
|
| 100 |
+
orig_ext = Path(original_name).suffix.lower()
|
| 101 |
+
if orig_ext:
|
| 102 |
+
new_file_path = file_path.with_suffix(orig_ext)
|
| 103 |
+
try:
|
| 104 |
+
file_path.rename(new_file_path)
|
| 105 |
+
except Exception as e:
|
| 106 |
+
print(f"Could not rename {file_path}: {e}")
|
| 107 |
|
| 108 |
+
# Generate PDF with extensions - supports all file types
|
| 109 |
pdf_buffer, error = generate_filename_based_pdf_report_with_extensions(
|
| 110 |
input_folder,
|
| 111 |
erste_marke,
|
|
|
|
| 120 |
zip_buffer = io.BytesIO()
|
| 121 |
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 122 |
for file in output_folder.iterdir():
|
| 123 |
+
if file.is_file():
|
| 124 |
+
zip_file.write(file, file.name)
|
| 125 |
zip_buffer.seek(0)
|
| 126 |
|
| 127 |
# Create combined download with all files
|
|
|
|
| 129 |
with zipfile.ZipFile(combined_zip_buffer, 'w', zipfile.ZIP_DEFLATED) as combined_zip:
|
| 130 |
# Add processed files
|
| 131 |
for file in output_folder.iterdir():
|
| 132 |
+
if file.is_file():
|
| 133 |
+
combined_zip.write(file, f"processed_files/{file.name}")
|
| 134 |
|
| 135 |
# Add PDF report if available
|
| 136 |
if pdf_buffer:
|
|
|
|
| 160 |
if st.session_state.processing_complete:
|
| 161 |
st.success("Processing complete!")
|
| 162 |
|
| 163 |
+
# Display a preview of processed names with original extensions
|
| 164 |
with st.expander("Preview Processed Names"):
|
| 165 |
if 'renamed_files' in st.session_state.processed_data:
|
| 166 |
+
st.write("Sample processed filenames (with original extensions preserved):")
|
| 167 |
# Handle the case where renamed_files might be a defaultdict
|
| 168 |
renamed_files_data = st.session_state.processed_data['renamed_files']
|
| 169 |
|
|
|
|
| 175 |
for brand_name, files in list(brand_data.items())[:2]: # First 2 brands per folder
|
| 176 |
for file_path, new_name in files[:2]: # First 2 files per brand
|
| 177 |
if isinstance(new_name, str):
|
| 178 |
+
# Preserve original extension
|
| 179 |
+
original_ext = Path(file_path).suffix
|
| 180 |
+
pdf_name = Path(new_name).stem + original_ext
|
| 181 |
sample_files.append((Path(file_path).name, pdf_name))
|
| 182 |
if len(sample_files) >= 10:
|
| 183 |
break
|
|
|
|
| 273 |
Upload a ZIP file containing brand asset folders. The tool will:
|
| 274 |
1. Detect all brands automatically
|
| 275 |
2. Let you choose which brand gets number 01
|
| 276 |
+
3. Process and rename all files with proper numbering (preserving all file extensions)
|
| 277 |
+
4. Generate a PDF report showing all assets with original filenames and extensions
|
| 278 |
+
5. Create an Excel overview of the processed files (all file types)
|
| 279 |
6. Package everything for easy download
|
| 280 |
+
|
| 281 |
+
**Supported file types:** All extensions are supported including:
|
| 282 |
+
- Images: .png, .jpg, .jpeg, .gif, .bmp, .svg, .webp
|
| 283 |
+
- Videos: .mp4, .avi, .mov, .mkv, .webm
|
| 284 |
+
- Audio: .mp3, .wav, .ogg, .flac, .m4a
|
| 285 |
+
- Documents: .pdf, .doc, .docx, .txt, .xlsx
|
| 286 |
+
- And any other file type!
|
| 287 |
""")
|