File size: 1,242 Bytes
18cb325
4391bc5
7b79b85
eb822d4
4391bc5
7b79b85
 
c8197d8
7b79b85
 
c8197d8
7b79b85
 
c8197d8
7b79b85
c8197d8
7b79b85
c8197d8
 
 
eb822d4
c8197d8
 
a559490
5884368
 
18cb325
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
        for root, dirs, files in os.walk(extract_path):
            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()