divya-22 commited on
Commit
be6af3b
1 Parent(s): d3c1046

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """3D-DreamGaussian_demo.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1ll2NcJouGKXw1Qv0u7CpnOX5JMFiBfZH
8
+
9
+ # [DreamGaussian](https://github.com/dreamgaussian/dreamgaussian) image-to-3D demo
10
+ """
11
+
12
+ # Commented out IPython magic to ensure Python compatibility.
13
+ #@title install (only run once)
14
+ # %rm -r dreamgaussian
15
+ !git clone https://github.com/dreamgaussian/dreamgaussian
16
+ # %cd dreamgaussian
17
+
18
+ # install dependencies
19
+ !pip install -q einops plyfile dearpygui huggingface_hub diffusers accelerate transformers xatlas trimesh PyMCubes pymeshlab rembg[gpu,cli] omegaconf ninja
20
+
21
+ # build extension from source (can be slow)
22
+ # !git clone --recursive https://github.com/ashawkey/diff-gaussian-rasterization
23
+ # !pip install -q ./diff-gaussian-rasterization
24
+ # !pip install -q ./simple-knn
25
+
26
+ # pre-built wheels (faster)
27
+ !pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.1.whl
28
+ !pip install -q https://github.com/camenduru/diff-gaussian-rasterization/releases/download/v1.0/simple_knn-0.0.0-cp310-cp310-linux_x86_64.1.whl
29
+
30
+ # nvdiffrast
31
+ !pip install -q git+https://github.com/NVlabs/nvdiffrast
32
+
33
+ # kiuikit
34
+ !pip install -q git+https://github.com/ashawkey/kiuikit
35
+
36
+ # %mkdir -p data
37
+
38
+ # Commented out IPython magic to ensure Python compatibility.
39
+ #@title upload image
40
+
41
+ import os
42
+
43
+ # %cd data/
44
+ # %rm * # remove all old files!
45
+ from google.colab import files
46
+ uploaded = files.upload()
47
+ IMAGE = os.path.basename(next(iter(uploaded))) # filename
48
+ # %cd ..
49
+
50
+ # display image
51
+ from IPython.display import Image, display
52
+ display(Image(f'data/{IMAGE}', width=256, height=256))
53
+
54
+ # Commented out IPython magic to ensure Python compatibility.
55
+ #@title preprocess image
56
+
57
+ # preprocess
58
+ # %run process.py data/{IMAGE}
59
+
60
+ NAME = os.path.splitext(IMAGE)[0]
61
+ IMAGE_PROCESSED = NAME + '_rgba.png'
62
+
63
+ # display processed image
64
+ from IPython.display import Image, display
65
+ display(Image(f'data/{IMAGE_PROCESSED}', width=256, height=256))
66
+
67
+ """# Settings
68
+ * Elevation: estimated elevation angle, default to 0 (horizontal), range from [-90, 90]. If you upload a look-down image, try a value like -30.
69
+ """
70
+
71
+ #@markdown ####**Settings:**
72
+ Elevation = 0 #@param {type: 'integer'}
73
+
74
+ # Commented out IPython magic to ensure Python compatibility.
75
+ #@title training!
76
+
77
+ # stage 1
78
+ # %run main.py --config configs/image.yaml input=data/{IMAGE_PROCESSED} save_path={NAME} elevation={Elevation} force_cuda_rast=True
79
+
80
+ # stage 2
81
+ # %run main2.py --config configs/image.yaml input=data/{IMAGE_PROCESSED} save_path={NAME} elevation={Elevation} force_cuda_rast=True
82
+
83
+ # Commented out IPython magic to ensure Python compatibility.
84
+ #@title render a video for displaying
85
+
86
+ # the final mesh is saved to ./logs/NAME.obj
87
+ # %run -m kiui.render logs/{NAME}.obj --save_video {NAME}.mp4 --wogui --force_cuda_rast
88
+
89
+ from IPython.display import HTML
90
+ from base64 import b64encode
91
+
92
+ def show_video(video_path, video_width=450):
93
+ video_file = open(video_path, "r+b").read()
94
+ video_url = f"data:video/mp4;base64,{b64encode(video_file).decode()}"
95
+ return HTML(f"""<video width={video_width} controls><source src="{video_url}"></video>""")
96
+
97
+ show_video(f'{NAME}.mp4')