mkaramb commited on
Commit
c8197d8
·
verified ·
1 Parent(s): 7b79b85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
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
- file_names = []
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 add files to the list
12
  for root, dirs, files in os.walk(extract_path):
13
  for file in files:
14
- if not file.startswith('.'):
15
- # Construct the file's full path
16
  full_path = os.path.join(root, file)
17
- # Subtract the base extraction path to show a relative path
18
- relative_path = os.path.relpath(full_path, extract_path)
19
- file_names.append(relative_path)
20
 
21
- return '\n'.join(file_names) # Join the list into a single string separated by newlines
 
 
22
 
23
- interface = gr.Interface(fn=unzip_file, inputs="file", outputs="text")
 
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