Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from huggingface_hub import hf_hub_download, HfFolder
|
3 |
+
from PIL import Image
|
4 |
+
import requests, torch
|
5 |
+
import numpy as np
|
6 |
+
from io import BytesIO
|
7 |
+
import plotly.graph_objects as go
|
8 |
+
|
9 |
+
def load_ScanNet_sample(data_path):
|
10 |
+
|
11 |
+
all_data = torch.load(data_path)
|
12 |
+
|
13 |
+
point = np.array(all_data['coord'])
|
14 |
+
color = np.array(all_data['color'])
|
15 |
+
|
16 |
+
point = point - point.min(axis=0)
|
17 |
+
point = point / point.max(axis=0)
|
18 |
+
color = color / 255.
|
19 |
+
return point, color
|
20 |
+
|
21 |
+
def show_logo():
|
22 |
+
repo_id = "ZiyuG/Cache"
|
23 |
+
filename = "scene0000_00.pth"
|
24 |
+
token = HfFolder.get_token() # Ensure you are logged in via huggingface-cli login
|
25 |
+
|
26 |
+
try:
|
27 |
+
file_path = hf_hub_download(repo_id=repo_id, filename=filename, use_auth_token=token, repo_type='dataset')
|
28 |
+
point, color = load_ScanNet_sample(file_path)
|
29 |
+
if point.shape[0] > 100000:
|
30 |
+
indices = np.random.choice(point.shape[0], 100000, replace=False)
|
31 |
+
point = point[indices]
|
32 |
+
color = color[indices]
|
33 |
+
except Exception as e:
|
34 |
+
print(e)
|
35 |
+
point = np.random.rand(8000, 3)
|
36 |
+
color = np.random.rand(8000, 3)
|
37 |
+
|
38 |
+
fig = go.Figure(
|
39 |
+
data=[
|
40 |
+
go.Scatter3d(
|
41 |
+
x=point[:,0], y=point[:,1], z=point[:,2],
|
42 |
+
mode='markers',
|
43 |
+
marker=dict(size=1, color=color, opacity=0.5),
|
44 |
+
)
|
45 |
+
],
|
46 |
+
layout=dict(
|
47 |
+
scene=dict(
|
48 |
+
xaxis=dict(visible=False),
|
49 |
+
yaxis=dict(visible=False),
|
50 |
+
zaxis=dict(visible=False),
|
51 |
+
aspectratio=dict(x=1, y=1, z=1),
|
52 |
+
camera=dict(eye=dict(x=1.5, y=1.5, z=1.5))
|
53 |
+
)
|
54 |
+
)
|
55 |
+
)
|
56 |
+
return fig
|
57 |
+
|
58 |
+
iface = gr.Interface(fn=show_logo, inputs=[], outputs=gr.Plot(), title="Display Logo")
|
59 |
+
iface.launch(share=True)
|