Spaces:
Runtime error
Runtime error
Commit
·
2b3dc42
1
Parent(s):
08ad16b
Create utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import os
|
3 |
+
import cv2
|
4 |
+
import shutil
|
5 |
+
import sys
|
6 |
+
from subprocess import call
|
7 |
+
|
8 |
+
def run_cmd(command):
|
9 |
+
try:
|
10 |
+
call(command, shell=True)
|
11 |
+
except KeyboardInterrupt:
|
12 |
+
print("Process interrupted")
|
13 |
+
sys.exit(1)
|
14 |
+
|
15 |
+
def Restoration(image):
|
16 |
+
os.makedirs("Temp")
|
17 |
+
os.makedirs("Temp/input")
|
18 |
+
print(type(image))
|
19 |
+
cv2.imwrite("Temp/input/input_img.png", image)
|
20 |
+
|
21 |
+
command = ("python run.py --input_folder "
|
22 |
+
+ "Temp/input"
|
23 |
+
+ " --output_folder "
|
24 |
+
+ "Temp"
|
25 |
+
+ " --GPU "
|
26 |
+
+ "-1"
|
27 |
+
+ " --with_scratch")
|
28 |
+
run_cmd(command)
|
29 |
+
|
30 |
+
result = cv2.imread("Temp/final_output/input_img.png")
|
31 |
+
shutil.rmtree("Temp")
|
32 |
+
return result
|