jiawi-ren
commited on
Commit
•
5fb2d4c
1
Parent(s):
ca869ab
add image identifier
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from PIL import Image
|
4 |
import subprocess
|
|
|
5 |
|
6 |
os.system('pip install -e ./simple-knn')
|
7 |
os.system('pip install -e ./diff-gaussian-rasterization')
|
@@ -13,36 +14,40 @@ def check_img_input(control_image):
|
|
13 |
|
14 |
def optimize(image_block: Image.Image, preprocess_chk=True, elevation_slider=0):
|
15 |
stage_1_output = optimize_stage_1(image_block, preprocess_chk, elevation_slider)
|
16 |
-
stage_2_output = optimize_stage_2(elevation_slider)
|
17 |
return stage_1_output, stage_2_output
|
18 |
|
|
|
19 |
def optimize_stage_1(image_block: Image.Image, preprocess_chk: bool, elevation_slider: float):
|
20 |
if not os.path.exists('tmp_data'):
|
21 |
os.makedirs('tmp_data')
|
|
|
|
|
22 |
if preprocess_chk:
|
23 |
# save image to a designated path
|
24 |
-
image_block.save('tmp_data/
|
25 |
|
26 |
# preprocess image
|
27 |
-
subprocess.run([f'python process.py tmp_data/
|
28 |
else:
|
29 |
-
image_block.save('tmp_data/
|
30 |
|
31 |
# stage 1
|
32 |
subprocess.run([
|
33 |
-
f'python main.py --config configs/image.yaml input=tmp_data/
|
34 |
shell=True)
|
35 |
|
36 |
-
return f'logs/
|
37 |
|
38 |
|
39 |
-
def optimize_stage_2(elevation_slider: float):
|
|
|
40 |
# stage 2
|
41 |
subprocess.run([
|
42 |
-
f'python main2.py --config configs/image.yaml input=tmp_data/
|
43 |
shell=True)
|
44 |
|
45 |
-
return f'logs/
|
46 |
|
47 |
|
48 |
if __name__ == "__main__":
|
@@ -117,7 +122,7 @@ if __name__ == "__main__":
|
|
117 |
elevation_slider],
|
118 |
outputs=[
|
119 |
obj3d_stage1]).success(
|
120 |
-
optimize_stage_2, inputs=[elevation_slider], outputs=[obj3d])
|
121 |
|
122 |
# demo.launch(enable_queue=True)
|
123 |
demo.queue(max_size=10) # <-- Sets up a queue with default parameters
|
|
|
2 |
import os
|
3 |
from PIL import Image
|
4 |
import subprocess
|
5 |
+
import hashlib
|
6 |
|
7 |
os.system('pip install -e ./simple-knn')
|
8 |
os.system('pip install -e ./diff-gaussian-rasterization')
|
|
|
14 |
|
15 |
def optimize(image_block: Image.Image, preprocess_chk=True, elevation_slider=0):
|
16 |
stage_1_output = optimize_stage_1(image_block, preprocess_chk, elevation_slider)
|
17 |
+
stage_2_output = optimize_stage_2(image_block, elevation_slider)
|
18 |
return stage_1_output, stage_2_output
|
19 |
|
20 |
+
|
21 |
def optimize_stage_1(image_block: Image.Image, preprocess_chk: bool, elevation_slider: float):
|
22 |
if not os.path.exists('tmp_data'):
|
23 |
os.makedirs('tmp_data')
|
24 |
+
|
25 |
+
img_hash = hashlib.sha256(image_block.tobytes()).hexdigest()
|
26 |
if preprocess_chk:
|
27 |
# save image to a designated path
|
28 |
+
image_block.save(f'tmp_data/{img_hash}.png')
|
29 |
|
30 |
# preprocess image
|
31 |
+
subprocess.run([f'python process.py tmp_data/{img_hash}.png'], shell=True)
|
32 |
else:
|
33 |
+
image_block.save(f'tmp_data/{img_hash}_rgba.png')
|
34 |
|
35 |
# stage 1
|
36 |
subprocess.run([
|
37 |
+
f'python main.py --config configs/image.yaml input=tmp_data/{img_hash}_rgba.png save_path={img_hash} mesh_format=glb elevation={elevation_slider} force_cuda_rast=True'],
|
38 |
shell=True)
|
39 |
|
40 |
+
return f'logs/{img_hash}_mesh.glb'
|
41 |
|
42 |
|
43 |
+
def optimize_stage_2(image_block: Image.Image, elevation_slider: float):
|
44 |
+
img_hash = hashlib.sha256(image_block.tobytes()).hexdigest()
|
45 |
# stage 2
|
46 |
subprocess.run([
|
47 |
+
f'python main2.py --config configs/image.yaml input=tmp_data/{img_hash}_rgba.png save_path={img_hash} mesh_format=glb elevation={elevation_slider} force_cuda_rast=True'],
|
48 |
shell=True)
|
49 |
|
50 |
+
return f'logs/{img_hash}.glb'
|
51 |
|
52 |
|
53 |
if __name__ == "__main__":
|
|
|
122 |
elevation_slider],
|
123 |
outputs=[
|
124 |
obj3d_stage1]).success(
|
125 |
+
optimize_stage_2, inputs=[image_block, elevation_slider], outputs=[obj3d])
|
126 |
|
127 |
# demo.launch(enable_queue=True)
|
128 |
demo.queue(max_size=10) # <-- Sets up a queue with default parameters
|