eliphatfs commited on
Commit
06bba7e
1 Parent(s): ce41dc5
Files changed (3) hide show
  1. app.py +52 -45
  2. openshape/__init__.py +1 -1
  3. openshape/caption.py +1 -1
app.py CHANGED
@@ -1,9 +1,13 @@
 
 
 
 
 
1
  import numpy
2
  import trimesh
3
  import objaverse
4
  import openshape
5
  import misc_utils
6
- import streamlit as st
7
  import plotly.graph_objects as go
8
 
9
 
@@ -12,7 +16,7 @@ def load_openshape(name):
12
  return openshape.load_pc_encoder(name)
13
 
14
 
15
- f32 = numpy.flaot32
16
  model_b32 = openshape.load_pc_encoder('openshape-pointbert-vitb32-rgb')
17
  model_l14 = openshape.load_pc_encoder('openshape-pointbert-vitl14-rgb')
18
  model_g14 = openshape.load_pc_encoder('openshape-pointbert-vitg14-rgb')
@@ -68,46 +72,49 @@ def render_pc(ncols, col, pc):
68
  return cols
69
 
70
 
71
- tab_cls, tab_pc2img, tab_cap = st.tabs(["Classification", "Point Cloud to Image Generation", "Point Cloud Captioning"])
72
-
73
- with tab_cls:
74
- if st.button("Run Classification on LVIS Categories"):
75
- pc = load_data()
76
- col1, col2 = render_pc(2, 0, pc)
77
- prog.progress(0.5, "Running Classification")
78
- with col2:
79
- pred = openshape.pred_lvis_sims(model_g14, pc)
80
- for i, (cat, sim) in zip(range(5), pred.items()):
81
- st.text(cat)
82
- st.caption("Similarity %.4f" % sim)
83
- prog.progress(1.0, "Idle")
84
-
85
- with tab_pc2img:
86
- prompt = st.text_input("Prompt")
87
- noise_scale = st.slider('Variation Level', 0, 5)
88
- cfg_scale = st.slider('Guidance Scale', 0.0, 30.0, 10.0)
89
- steps = st.slider('Diffusion Steps', 2, 80, 10)
90
- width = st.slider('Width', 128, 512, step=32)
91
- height = st.slider('Height', 128, 512, step=32)
92
- if st.button("Generate"):
93
- pc = load_data()
94
- col1, col2 = render_pc(2, 0, pc)
95
- prog.progress(0.49, "Running Generation")
96
- img = openshape.pc_to_image(
97
- model_l14, pc, prompt, noise_scale, width, height, cfg_scale, steps,
98
- lambda i, t, _: prog.progress(0.49 + i / (steps + 1) / 2, "Running Diffusion Step %d" % i)
99
- )
100
- with col2:
101
- st.image(img)
102
- prog.progress(1.0, "Idle")
103
-
104
- with tab_cap:
105
- cond_scale = st.slider('Conditioning Scale', 0.0, 4.0, 1.0)
106
- if st.button("Generate a Caption"):
107
- pc = load_data()
108
- col1, col2 = render_pc(2, 0, pc)
109
- prog.progress(0.5, "Running Generation")
110
- cap = openshape.pc_caption(model_b32, pc, cond_scale)
111
- with col2:
112
- st.text(cap)
113
- prog.progress(1.0, "Idle")
 
 
 
 
1
+ import streamlit as st
2
+ from huggingface_hub import HfFolder
3
+ HfFolder().save_token(st.secrets['etoken'])
4
+
5
+
6
  import numpy
7
  import trimesh
8
  import objaverse
9
  import openshape
10
  import misc_utils
 
11
  import plotly.graph_objects as go
12
 
13
 
 
16
  return openshape.load_pc_encoder(name)
17
 
18
 
19
+ f32 = numpy.float32
20
  model_b32 = openshape.load_pc_encoder('openshape-pointbert-vitb32-rgb')
21
  model_l14 = openshape.load_pc_encoder('openshape-pointbert-vitl14-rgb')
22
  model_g14 = openshape.load_pc_encoder('openshape-pointbert-vitg14-rgb')
 
72
  return cols
73
 
74
 
75
+ try:
76
+ tab_cls, tab_pc2img, tab_cap = st.tabs(["Classification", "Point Cloud to Image Generation", "Point Cloud Captioning"])
77
+
78
+ with tab_cls:
79
+ if st.button("Run Classification on LVIS Categories"):
80
+ pc = load_data()
81
+ col1, col2 = render_pc(2, 0, pc)
82
+ prog.progress(0.5, "Running Classification")
83
+ with col2:
84
+ pred = openshape.pred_lvis_sims(model_g14, pc)
85
+ for i, (cat, sim) in zip(range(5), pred.items()):
86
+ st.text(cat)
87
+ st.caption("Similarity %.4f" % sim)
88
+ prog.progress(1.0, "Idle")
89
+
90
+ with tab_pc2img:
91
+ prompt = st.text_input("Prompt")
92
+ noise_scale = st.slider('Variation Level', 0, 5)
93
+ cfg_scale = st.slider('Guidance Scale', 0.0, 30.0, 10.0)
94
+ steps = st.slider('Diffusion Steps', 2, 80, 10)
95
+ width = st.slider('Width', 128, 512, step=32)
96
+ height = st.slider('Height', 128, 512, step=32)
97
+ if st.button("Generate"):
98
+ pc = load_data()
99
+ col1, col2 = render_pc(2, 0, pc)
100
+ prog.progress(0.49, "Running Generation")
101
+ img = openshape.pc_to_image(
102
+ model_l14, pc, prompt, noise_scale, width, height, cfg_scale, steps,
103
+ lambda i, t, _: prog.progress(0.49 + i / (steps + 1) / 2, "Running Diffusion Step %d" % i)
104
+ )
105
+ with col2:
106
+ st.image(img)
107
+ prog.progress(1.0, "Idle")
108
+
109
+ with tab_cap:
110
+ cond_scale = st.slider('Conditioning Scale', 0.0, 4.0, 1.0)
111
+ if st.button("Generate a Caption"):
112
+ pc = load_data()
113
+ col1, col2 = render_pc(2, 0, pc)
114
+ prog.progress(0.5, "Running Generation")
115
+ cap = openshape.pc_caption(model_b32, pc, cond_scale)
116
+ with col2:
117
+ st.text(cap)
118
+ prog.progress(1.0, "Idle")
119
+ except Exception as exc:
120
+ st.error(repr(exc))
openshape/__init__.py CHANGED
@@ -40,7 +40,7 @@ model_list = {
40
 
41
 
42
  def load_pc_encoder(name):
43
- s = torch.load(hf_hub_download("OpenShape/" + name, "model.pt"), map_location='cpu')
44
  model = model_list[name](s).eval()
45
  if torch.cuda.is_available():
46
  model.cuda()
 
40
 
41
 
42
  def load_pc_encoder(name):
43
+ s = torch.load(hf_hub_download("OpenShape/" + name, "model.pt", token=True), map_location='cpu')
44
  model = model_list[name](s).eval()
45
  if torch.cuda.is_available():
46
  model.cuda()
openshape/caption.py CHANGED
@@ -157,7 +157,7 @@ tokenizer = GPT2Tokenizer.from_pretrained("gpt2")
157
  prefix_length = 10
158
  model = ClipCaptionModel(prefix_length)
159
  # print(model.gpt_embedding_size)
160
- model.load_state_dict(torch.load(hf_hub_download('OpenShape/clipcap-cc', 'conceptual_weights.pt'), map_location='cpu'))
161
  model.eval()
162
  if torch.cuda.is_available():
163
  model = model.cuda()
 
157
  prefix_length = 10
158
  model = ClipCaptionModel(prefix_length)
159
  # print(model.gpt_embedding_size)
160
+ model.load_state_dict(torch.load(hf_hub_download('OpenShape/clipcap-cc', 'conceptual_weights.pt', token=True), map_location='cpu'))
161
  model.eval()
162
  if torch.cuda.is_available():
163
  model = model.cuda()