File size: 938 Bytes
9425f06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import zipfile
import os
import base64

# Function to extract files from a zip file
def extract_files(file):
    output_dir = "/path/to/extract/to"  # replace with the path where you want to extract the files
    with zipfile.ZipFile(file.name, 'r') as zip_ref:
        zip_ref.extractall(output_dir)
        extracted_files = zip_ref.namelist()

    # Generate a downloadable link for each extracted file
    links = []
    for filename in extracted_files:
        file_path = os.path.join(output_dir, filename)
        with open(file_path, "rb") as file:
            bytes = file.read()
        b64 = base64.b64encode(bytes).decode()
        href = f'<a href="data:file/octet-stream;base64,{b64}" download="{filename}">Download {filename}</a>'
        links.append(href)

    return "<br>".join(links)

iface = gr.Interface(fn=extract_files, inputs="file", outputs="html", title="Zip File Extractor")
iface.launch()