Filepath config
Browse files
app.py
CHANGED
|
@@ -11,8 +11,7 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 11 |
Processes uploaded ZIP files containing frame images from one or more cameras.
|
| 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).
|
|
@@ -47,22 +46,16 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 47 |
# List to hold (camera_name, folder) tuples
|
| 48 |
camera_folders = []
|
| 49 |
|
| 50 |
-
for
|
| 51 |
-
|
| 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(
|
| 62 |
zip_ref.extractall(extract_dir)
|
| 63 |
|
| 64 |
# If the ZIP extracts to a single subdirectory, use that folder
|
| 65 |
-
subdirs = [os.path.join(extract_dir, d) for d in os.listdir(extract_dir)
|
| 66 |
if os.path.isdir(os.path.join(extract_dir, d))]
|
| 67 |
camera_folder = subdirs[0] if len(subdirs) == 1 else extract_dir
|
| 68 |
|
|
@@ -114,11 +107,11 @@ def process_zips(camera_zips, regex_pattern, start_frame, end_frame):
|
|
| 114 |
|
| 115 |
return output_zip_path
|
| 116 |
|
| 117 |
-
# Create the Gradio interface
|
| 118 |
iface = gr.Interface(
|
| 119 |
fn=process_zips,
|
| 120 |
inputs=[
|
| 121 |
-
gr.File(label="Camera Folder ZIPs", file_count="multiple", type="
|
| 122 |
gr.Textbox(label="Regex Pattern (with one capturing group)"),
|
| 123 |
gr.Textbox(label="Start Frame Number"),
|
| 124 |
gr.Textbox(label="End Frame Number")
|
|
|
|
| 11 |
Processes uploaded ZIP files containing frame images from one or more cameras.
|
| 12 |
|
| 13 |
Args:
|
| 14 |
+
camera_zips (list): A list of file paths for the 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).
|
|
|
|
| 46 |
# List to hold (camera_name, folder) tuples
|
| 47 |
camera_folders = []
|
| 48 |
|
| 49 |
+
for file_path in camera_zips:
|
| 50 |
+
zip_name = os.path.basename(file_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Create a temporary directory to extract the ZIP contents
|
| 52 |
extract_dir = os.path.join(tempfile.gettempdir(), zip_name + "_extracted")
|
| 53 |
os.makedirs(extract_dir, exist_ok=True)
|
| 54 |
+
with zipfile.ZipFile(file_path, "r") as zip_ref:
|
| 55 |
zip_ref.extractall(extract_dir)
|
| 56 |
|
| 57 |
# If the ZIP extracts to a single subdirectory, use that folder
|
| 58 |
+
subdirs = [os.path.join(extract_dir, d) for d in os.listdir(extract_dir)
|
| 59 |
if os.path.isdir(os.path.join(extract_dir, d))]
|
| 60 |
camera_folder = subdirs[0] if len(subdirs) == 1 else extract_dir
|
| 61 |
|
|
|
|
| 107 |
|
| 108 |
return output_zip_path
|
| 109 |
|
| 110 |
+
# Create the Gradio interface using type "filepath"
|
| 111 |
iface = gr.Interface(
|
| 112 |
fn=process_zips,
|
| 113 |
inputs=[
|
| 114 |
+
gr.File(label="Camera Folder ZIPs", file_count="multiple", type="filepath"),
|
| 115 |
gr.Textbox(label="Regex Pattern (with one capturing group)"),
|
| 116 |
gr.Textbox(label="Start Frame Number"),
|
| 117 |
gr.Textbox(label="End Frame Number")
|