awacke1 commited on
Commit
9425f06
·
1 Parent(s): d73965a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import zipfile
3
+ import os
4
+ import base64
5
+
6
+ # Function to extract files from a zip file
7
+ def extract_files(file):
8
+ output_dir = "/path/to/extract/to" # replace with the path where you want to extract the files
9
+ with zipfile.ZipFile(file.name, 'r') as zip_ref:
10
+ zip_ref.extractall(output_dir)
11
+ extracted_files = zip_ref.namelist()
12
+
13
+ # Generate a downloadable link for each extracted file
14
+ links = []
15
+ for filename in extracted_files:
16
+ file_path = os.path.join(output_dir, filename)
17
+ with open(file_path, "rb") as file:
18
+ bytes = file.read()
19
+ b64 = base64.b64encode(bytes).decode()
20
+ href = f'<a href="data:file/octet-stream;base64,{b64}" download="{filename}">Download {filename}</a>'
21
+ links.append(href)
22
+
23
+ return "<br>".join(links)
24
+
25
+ iface = gr.Interface(fn=extract_files, inputs="file", outputs="html", title="Zip File Extractor")
26
+ iface.launch()