Spaces:
Runtime error
Runtime error
Commit
·
989f4bb
1
Parent(s):
48e8a4e
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import cv2
|
| 4 |
+
import shutil
|
| 5 |
+
import sys
|
| 6 |
+
from subprocess import call
|
| 7 |
+
|
| 8 |
+
os.system('bash setup.sh')
|
| 9 |
+
|
| 10 |
+
def run_cmd(command):
|
| 11 |
+
try:
|
| 12 |
+
call(command, shell=True)
|
| 13 |
+
except KeyboardInterrupt:
|
| 14 |
+
print("Process interrupted")
|
| 15 |
+
sys.exit(1)
|
| 16 |
+
|
| 17 |
+
def run(image):
|
| 18 |
+
os.makedirs("Temp")
|
| 19 |
+
os.makedirs("Temp/input")
|
| 20 |
+
print(type(image))
|
| 21 |
+
cv2.imwrite("Temp/input/input_img.png", image)
|
| 22 |
+
|
| 23 |
+
command = ("python run.py --input_folder "
|
| 24 |
+
+ "Temp/input"
|
| 25 |
+
+ " --output_folder "
|
| 26 |
+
+ "Temp"
|
| 27 |
+
+ " --GPU "
|
| 28 |
+
+ "-1"
|
| 29 |
+
+ " --with_scratch")
|
| 30 |
+
run_cmd(command)
|
| 31 |
+
|
| 32 |
+
result = cv2.imread("Temp/final_output/input_img.png")
|
| 33 |
+
shutil.rmtree("Temp")
|
| 34 |
+
|
| 35 |
+
return result
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(fn=run, inputs="image", outputs="image").launch(debug=True)
|