File size: 1,230 Bytes
18cb325 4391bc5 7b79b85 eb822d4 4391bc5 7b79b85 eb822d4 4391bc5 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
file_names = []
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 add files to the list
for root, dirs, files in os.walk(extract_path):
for file in files:
if not file.startswith('.'):
# Construct the file's full path
full_path = os.path.join(root, file)
# Subtract the base extraction path to show a relative path
relative_path = os.path.relpath(full_path, extract_path)
file_names.append(relative_path)
return '\n'.join(file_names) # Join the list into a single string separated by newlines
interface = gr.Interface(fn=unzip_file, inputs="file", outputs="text")
interface.launch()
# def greet(name):
# return "Hello " + name + "!!"
#iface = gr.Interface(fn=greet, inputs="text", outputs="text")
#iface.launch()
|