kivilaid commited on
Commit
88f516c
·
1 Parent(s): 30d0187

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -21
app.py CHANGED
@@ -1,29 +1,31 @@
1
  import gradio as gr
2
  import zipfile
3
  import os
 
4
 
5
- def extract_zip_file(zip_file):
6
- # Save the uploaded ZIP file to a temporary path
7
- zip_file_path = 'uploaded_zip.zip'
8
- with open(zip_file_path, 'wb') as f:
9
- f.write(zip_file.read())
 
 
 
 
 
 
 
 
10
 
11
- # Specify the directory to extract files
12
- extract_dir = 'extracted_files'
13
- os.makedirs(extract_dir, exist_ok=True)
14
-
15
- # Extract files
16
- with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
17
- zip_ref.extractall(extract_dir)
18
-
19
- return f"All files from {zip_file_path} have been extracted to {extract_dir}."
20
-
21
- # Create a gradio interface
22
  iface = gr.Interface(
23
- fn=extract_zip_file,
24
- inputs=gr.File(label="Upload ZIP File"),
25
- outputs="text"
 
 
26
  )
27
 
28
- # Launch the interface
29
- iface.launch()
 
 
1
  import gradio as gr
2
  import zipfile
3
  import os
4
+ from tempfile import TemporaryDirectory
5
 
6
+ def extract_zip(file_obj):
7
+ with TemporaryDirectory() as tmpdirname:
8
+ # Save the uploaded zip file to the temporary directory
9
+ zip_path = os.path.join(tmpdirname, 'uploaded.zip')
10
+ with open(zip_path, 'wb') as f:
11
+ f.write(file_obj.read())
12
+
13
+ # Extract the zip file
14
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
15
+ zip_ref.extractall(tmpdirname)
16
+
17
+ # Return the path to the extracted files
18
+ return f"Extracted to {tmpdirname}"
19
 
20
+ # Create the Gradio interface
 
 
 
 
 
 
 
 
 
 
21
  iface = gr.Interface(
22
+ fn=extract_zip,
23
+ inputs=gr.inputs.File(type="file", label="Upload ZIP File"),
24
+ outputs="text",
25
+ title="ZIP File Extractor",
26
+ description="Upload a ZIP file and it will be extracted."
27
  )
28
 
29
+ if __name__ == "__main__":
30
+ iface.launch()
31
+