mkaramb commited on
Commit
7b79b85
·
verified ·
1 Parent(s): 4391bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -1,9 +1,24 @@
1
  import zipfile
2
  import gradio as gr
 
3
 
4
  def unzip_file(file):
5
- with zipfile.ZipFile(file, "r") as zip_ref:
6
- zip_ref.extractall()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()