Spaces:
Sleeping
Sleeping
Commit
·
4c11400
1
Parent(s):
46e19a2
adding code
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import nerf
|
4 |
+
import torch
|
5 |
+
|
6 |
+
# Check if the directory called Model exists
|
7 |
+
if not os.path.exists("Model"):
|
8 |
+
# Create the directory
|
9 |
+
os.mkdir("Model")
|
10 |
+
|
11 |
+
# Check if the model is downloaded
|
12 |
+
if not os.path.exists("Model/nerf_model.ckpt"):
|
13 |
+
# Download the model
|
14 |
+
wget https://github.com/bmild/nerf/releases/download/v0.5/nerf_model.ckpt
|
15 |
+
|
16 |
+
# Load the NeRF model
|
17 |
+
nerf_model = nerf.NeRF.load("Model/nerf_model.ckpt")
|
18 |
+
|
19 |
+
# Define the camera parameters
|
20 |
+
camera = nerf.Camera(
|
21 |
+
fov=60,
|
22 |
+
focal_length=50,
|
23 |
+
znear=1,
|
24 |
+
zfar=100,
|
25 |
+
principal_point=(0.5, 0.5),
|
26 |
+
)
|
27 |
+
|
28 |
+
# Define the viewing direction
|
29 |
+
viewing_direction = torch.tensor([0, 0, 1])
|
30 |
+
|
31 |
+
# Render the novel view
|
32 |
+
novel_view = nerf_model.render(viewing_direction, camera)
|
33 |
+
|
34 |
+
# Save the novel view
|
35 |
+
torch.save(novel_view, "novel_view.png")
|
36 |
+
|
37 |
+
# Create a Streamlit app
|
38 |
+
st.title("NeRF with Dolly Zoom")
|
39 |
+
|
40 |
+
# Show the image
|
41 |
+
st.image("novel_view.png")
|