Update app.py
Browse files
app.py
CHANGED
|
@@ -12,6 +12,7 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 12 |
|
| 13 |
Args:
|
| 14 |
camera_zips (list): A list of uploaded ZIP files (each representing one camera folder).
|
|
|
|
| 15 |
regex_pattern (str): A regex pattern with one capturing group that extracts the numeric frame value.
|
| 16 |
start_frame (str): The start frame number (as string, will be converted to int).
|
| 17 |
end_frame (str): The end frame number (as string, will be converted to int).
|
|
@@ -47,13 +48,15 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 47 |
camera_folders = []
|
| 48 |
|
| 49 |
for uploaded_zip in camera_zips:
|
|
|
|
|
|
|
| 50 |
# Save the uploaded ZIP to a temporary file
|
| 51 |
-
temp_zip_path = os.path.join(tempfile.gettempdir(),
|
| 52 |
with open(temp_zip_path, "wb") as f:
|
| 53 |
-
f.write(uploaded_zip
|
| 54 |
|
| 55 |
# Create a temporary directory to extract the ZIP contents
|
| 56 |
-
extract_dir = os.path.join(tempfile.gettempdir(),
|
| 57 |
os.makedirs(extract_dir, exist_ok=True)
|
| 58 |
with zipfile.ZipFile(temp_zip_path, "r") as zip_ref:
|
| 59 |
zip_ref.extractall(extract_dir)
|
|
@@ -64,7 +67,7 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 64 |
camera_folder = subdirs[0] if len(subdirs) == 1 else extract_dir
|
| 65 |
|
| 66 |
# Use the ZIP filename (without extension) as the camera name
|
| 67 |
-
camera_name = os.path.splitext(
|
| 68 |
camera_folders.append((camera_name, camera_folder))
|
| 69 |
|
| 70 |
# Build a mapping for each camera: { frame_index: file_full_path }
|
|
@@ -111,11 +114,11 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 111 |
|
| 112 |
return output_zip_path
|
| 113 |
|
| 114 |
-
# Create the Gradio interface
|
| 115 |
iface = gr.Interface(
|
| 116 |
fn=process_zips,
|
| 117 |
inputs=[
|
| 118 |
-
gr.File(label="Camera Folder ZIPs", file_count="multiple", type="
|
| 119 |
gr.Textbox(label="Regex Pattern (with one capturing group)"),
|
| 120 |
gr.Textbox(label="Start Frame Number"),
|
| 121 |
gr.Textbox(label="End Frame Number")
|
|
|
|
| 12 |
|
| 13 |
Args:
|
| 14 |
camera_zips (list): A list of uploaded ZIP files (each representing one camera folder).
|
| 15 |
+
Each file is a dictionary with keys "name" and "data".
|
| 16 |
regex_pattern (str): A regex pattern with one capturing group that extracts the numeric frame value.
|
| 17 |
start_frame (str): The start frame number (as string, will be converted to int).
|
| 18 |
end_frame (str): The end frame number (as string, will be converted to int).
|
|
|
|
| 48 |
camera_folders = []
|
| 49 |
|
| 50 |
for uploaded_zip in camera_zips:
|
| 51 |
+
# uploaded_zip is now a dict with keys "name" and "data"
|
| 52 |
+
zip_name = uploaded_zip["name"]
|
| 53 |
# Save the uploaded ZIP to a temporary file
|
| 54 |
+
temp_zip_path = os.path.join(tempfile.gettempdir(), zip_name)
|
| 55 |
with open(temp_zip_path, "wb") as f:
|
| 56 |
+
f.write(uploaded_zip["data"])
|
| 57 |
|
| 58 |
# Create a temporary directory to extract the ZIP contents
|
| 59 |
+
extract_dir = os.path.join(tempfile.gettempdir(), zip_name + "_extracted")
|
| 60 |
os.makedirs(extract_dir, exist_ok=True)
|
| 61 |
with zipfile.ZipFile(temp_zip_path, "r") as zip_ref:
|
| 62 |
zip_ref.extractall(extract_dir)
|
|
|
|
| 67 |
camera_folder = subdirs[0] if len(subdirs) == 1 else extract_dir
|
| 68 |
|
| 69 |
# Use the ZIP filename (without extension) as the camera name
|
| 70 |
+
camera_name = os.path.splitext(zip_name)[0]
|
| 71 |
camera_folders.append((camera_name, camera_folder))
|
| 72 |
|
| 73 |
# Build a mapping for each camera: { frame_index: file_full_path }
|
|
|
|
| 114 |
|
| 115 |
return output_zip_path
|
| 116 |
|
| 117 |
+
# Create the Gradio interface with type "binary" for file uploads
|
| 118 |
iface = gr.Interface(
|
| 119 |
fn=process_zips,
|
| 120 |
inputs=[
|
| 121 |
+
gr.File(label="Camera Folder ZIPs", file_count="multiple", type="binary"),
|
| 122 |
gr.Textbox(label="Regex Pattern (with one capturing group)"),
|
| 123 |
gr.Textbox(label="Start Frame Number"),
|
| 124 |
gr.Textbox(label="End Frame Number")
|