Update app.py
Browse files
app.py
CHANGED
@@ -5,22 +5,22 @@ import os
|
|
5 |
def unzip_file(file):
|
6 |
extract_path = "extracted_files" # Define a path to extract files
|
7 |
os.makedirs(extract_path, exist_ok=True) # Create the directory if it doesn't exist
|
8 |
-
|
9 |
with zipfile.ZipFile(file, "r") as zip_ref:
|
10 |
zip_ref.extractall(extract_path) # Extract files into the specified directory
|
11 |
-
# Walk through the directory structure and
|
12 |
for root, dirs, files in os.walk(extract_path):
|
13 |
for file in files:
|
14 |
-
if
|
15 |
-
# Construct the file's full path
|
16 |
full_path = os.path.join(root, file)
|
17 |
-
|
18 |
-
relative_path = os.path.relpath(full_path, extract_path)
|
19 |
-
file_names.append(relative_path)
|
20 |
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
|
|
|
24 |
interface.launch()
|
25 |
|
26 |
|
|
|
5 |
def unzip_file(file):
|
6 |
extract_path = "extracted_files" # Define a path to extract files
|
7 |
os.makedirs(extract_path, exist_ok=True) # Create the directory if it doesn't exist
|
8 |
+
jpg_files = [] # List to store paths of JPG files
|
9 |
with zipfile.ZipFile(file, "r") as zip_ref:
|
10 |
zip_ref.extractall(extract_path) # Extract files into the specified directory
|
11 |
+
# Walk through the directory structure and look for JPG files
|
12 |
for root, dirs, files in os.walk(extract_path):
|
13 |
for file in files:
|
14 |
+
if file.lower().endswith('.jpg'): # Check if the file is a JPG
|
|
|
15 |
full_path = os.path.join(root, file)
|
16 |
+
jpg_files.append(full_path)
|
|
|
|
|
17 |
|
18 |
+
if not jpg_files:
|
19 |
+
return ["No JPG files found in the zip."] # Return a message if no JPGs are found
|
20 |
+
return jpg_files # Return the list of JPG file paths
|
21 |
|
22 |
+
# Define the Gradio interface, specifying image display for multiple images
|
23 |
+
interface = gr.Interface(fn=unzip_file, inputs="file", outputs=gr.Gallery())
|
24 |
interface.launch()
|
25 |
|
26 |
|