felipekitamura commited on
Commit
033e507
1 Parent(s): 4f88635

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from face_deid_ct import drown_volume
2
+
3
+ import gradio as gr
4
+ import gradio as gr
5
+ import os
6
+ import zipfile
7
+ import shutil
8
+
9
+
10
+ def process_file(input_file):
11
+ cache_dir = "cache"
12
+ cache_out_dir = "_d"
13
+ output_zip_file = "output.zip"
14
+
15
+ # Check if input file is a zip file
16
+ if zipfile.is_zipfile(input_file.name):
17
+ with zipfile.ZipFile(input_file.name, 'r') as zip_ref:
18
+ # Unzip the file in 'cache' directory
19
+ zip_ref.extractall(cache_dir)
20
+
21
+ # Run deid function
22
+ drown_volume(cache_dir, cache_out_dir, replacer='face')
23
+
24
+ # Create a Zip file for 'cache_out' directory
25
+ with zipfile.ZipFile(output_zip_file, 'w') as zipf:
26
+ for root, dirs, files in os.walk(cache_dir+cache_out_dir):
27
+ for file in files:
28
+ zipf.write(os.path.join(root, file),
29
+ os.path.relpath(os.path.join(root, file),
30
+ os.path.join(cache_out_dir, '..')))
31
+
32
+ # Cleanup cache directories
33
+ shutil.rmtree(cache_dir)
34
+ shutil.rmtree(cache_dir+cache_out_dir)
35
+
36
+ return output_zip_file
37
+
38
+ else:
39
+ raise ValueError("The provided file is not a zip file.")
40
+
41
+
42
+ inputs = gr.components.File(label="Input File")
43
+ outputs = gr.components.File(label="Output File")
44
+ demo = gr.Interface(fn=process_file, inputs=inputs, outputs=outputs)
45
+ demo.launch()