Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,24 @@
|
|
| 1 |
import zipfile
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
def unzip_file(file):
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
interface = gr.Interface(fn=unzip_file, inputs="file", outputs="text")
|
| 9 |
interface.launch()
|
|
|
|
| 1 |
import zipfile
|
| 2 |
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
|
| 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()
|