import zipfile import gradio as gr import os def unzip_file(file): extract_path = "extracted_files" # Define a path to extract files os.makedirs(extract_path, exist_ok=True) # Create the directory if it doesn't exist jpg_files = [] # List to store paths of JPG files with zipfile.ZipFile(file, "r") as zip_ref: zip_ref.extractall(extract_path) # Extract files into the specified directory # Walk through the directory structure and look for JPG files, ignoring __MACOSX directory for root, dirs, files in os.walk(extract_path): if '__MACOSX' in root: # Skip the __MACOSX directory continue for file in files: if file.lower().endswith('.jpg'): # Check if the file is a JPG full_path = os.path.join(root, file) jpg_files.append(full_path) if not jpg_files: return ["No JPG files found in the zip."] # Return a message if no JPGs are found return jpg_files # Return the list of JPG file paths # Define the Gradio interface, specifying image display for multiple images interface = gr.Interface(fn=unzip_file, inputs="file", outputs=gr.Gallery()) interface.launch() # def greet(name): # return "Hello " + name + "!!" #iface = gr.Interface(fn=greet, inputs="text", outputs="text") #iface.launch()