angkul07 commited on
Commit
fbfee94
Β·
verified Β·
1 Parent(s): 5ff9ed8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -30
app.py CHANGED
@@ -84,45 +84,35 @@ def decode_frame(frame):
84
  raise RuntimeError("Failed to decode JPEG frame")
85
  return img
86
 
87
-
88
  def convert_zarr_from_hf(uuid: str, tmp_dir: str) -> str:
89
- """
90
- Open images.front_1 directly from HF via fsspec, convert to mp4.
91
- Returns path to the output mp4.
92
- """
93
- fs = HfFileSystem()
94
- store_path = f"hf://datasets/{EGOVERSE_REPO}/{uuid}/images.front_1"
95
 
96
- store = zarr.storage.FsspecStore.from_url(store_path)
97
- root = zarr.open(store, mode="r", zarr_format=3)
98
 
99
- if "c" not in root and not hasattr(root, "shape"):
100
- # root IS the array when opened at images.front_1
101
- frames = root
102
- else:
103
- frames = root # images.front_1 is the array itself
 
 
 
 
 
 
104
 
105
  n_frames = frames.shape[0]
106
- first = decode_frame(frames[0])
107
  h, w = first.shape[:2]
108
 
 
 
109
  temp_avi = os.path.join(tmp_dir, f"{uuid}.avi")
110
  output = os.path.join(tmp_dir, f"{uuid}.mp4")
111
 
112
- # writer = cv2.VideoWriter(
113
- # temp_avi,
114
- # cv2.VideoWriter_fourcc(*"MJPG"),
115
- # FPS,
116
- # (w, h),
117
- # )
118
- # for i in range(n_frames):
119
- # writer.write(decode_frame(frames[i]))
120
- # writer.release()
121
-
122
- # Instead of fetching frame by frame
123
- all_frames = frames[0:n_frames] # single batched network read
124
-
125
- writer = cv2.VideoWriter(temp_avi, cv2.VideoWriter_fourcc(*"MJPG"), FPS, (w, h))
126
  for i in range(n_frames):
127
  writer.write(decode_frame(all_frames[i]))
128
  writer.release()
@@ -139,6 +129,60 @@ def convert_zarr_from_hf(uuid: str, tmp_dir: str) -> str:
139
  os.remove(temp_avi)
140
  return output
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  # ─────────────────────────────────────────────
143
  # MCAP helpers (abc-teleop)
144
  # ─────────────────────────────────────────────
@@ -207,8 +251,16 @@ def stream_videos(dataset: str, uuid_input: str, task: str):
207
  tmp_dir = tempfile.mkdtemp(prefix="viewer_")
208
  try:
209
  # ── Egoverse (zarr β†’ single front camera) ───────────────────────
 
 
 
 
 
 
 
 
210
  if dataset == "EgoVerse":
211
- yield f"Fetching zarr for {uuid} ...", None, None, None
212
  try:
213
  mp4 = convert_zarr_from_hf(uuid, tmp_dir)
214
  yield f"Done: {uuid}", mp4, None, None
 
84
  raise RuntimeError("Failed to decode JPEG frame")
85
  return img
86
 
 
87
  def convert_zarr_from_hf(uuid: str, tmp_dir: str) -> str:
88
+ from huggingface_hub import snapshot_download
 
 
 
 
 
89
 
90
+ yield_status = f"Downloading zarr for {uuid} ..." # caller will show this
 
91
 
92
+ # Download only the images.front_1 array for this episode
93
+ local_dir = snapshot_download(
94
+ repo_id=EGOVERSE_REPO,
95
+ repo_type="dataset",
96
+ allow_patterns=[f"{uuid}/images.front_1/**"],
97
+ local_dir=os.path.join(tmp_dir, uuid),
98
+ )
99
+
100
+ array_path = os.path.join(local_dir, uuid, "images.front_1")
101
+ root = zarr.open(array_path, mode="r", zarr_format=3)
102
+ frames = root
103
 
104
  n_frames = frames.shape[0]
105
+ first = decode_frame(frames[0:1][0])
106
  h, w = first.shape[:2]
107
 
108
+ all_frames = frames[0:n_frames] # single read, now local so fast
109
+
110
  temp_avi = os.path.join(tmp_dir, f"{uuid}.avi")
111
  output = os.path.join(tmp_dir, f"{uuid}.mp4")
112
 
113
+ writer = cv2.VideoWriter(
114
+ temp_avi, cv2.VideoWriter_fourcc(*"MJPG"), FPS, (w, h)
115
+ )
 
 
 
 
 
 
 
 
 
 
 
116
  for i in range(n_frames):
117
  writer.write(decode_frame(all_frames[i]))
118
  writer.release()
 
129
  os.remove(temp_avi)
130
  return output
131
 
132
+ # def convert_zarr_from_hf(uuid: str, tmp_dir: str) -> str:
133
+ # """
134
+ # Open images.front_1 directly from HF via fsspec, convert to mp4.
135
+ # Returns path to the output mp4.
136
+ # """
137
+ # fs = HfFileSystem()
138
+ # store_path = f"hf://datasets/{EGOVERSE_REPO}/{uuid}/images.front_1"
139
+
140
+ # store = zarr.storage.FsspecStore.from_url(store_path)
141
+ # root = zarr.open(store, mode="r", zarr_format=3)
142
+
143
+ # if "c" not in root and not hasattr(root, "shape"):
144
+ # # root IS the array when opened at images.front_1
145
+ # frames = root
146
+ # else:
147
+ # frames = root # images.front_1 is the array itself
148
+
149
+ # n_frames = frames.shape[0]
150
+ # first = decode_frame(frames[0])
151
+ # h, w = first.shape[:2]
152
+
153
+ # temp_avi = os.path.join(tmp_dir, f"{uuid}.avi")
154
+ # output = os.path.join(tmp_dir, f"{uuid}.mp4")
155
+
156
+ # # writer = cv2.VideoWriter(
157
+ # # temp_avi,
158
+ # # cv2.VideoWriter_fourcc(*"MJPG"),
159
+ # # FPS,
160
+ # # (w, h),
161
+ # # )
162
+ # # for i in range(n_frames):
163
+ # # writer.write(decode_frame(frames[i]))
164
+ # # writer.release()
165
+
166
+ # # Instead of fetching frame by frame
167
+ # all_frames = frames[0:n_frames] # single batched network read
168
+
169
+ # writer = cv2.VideoWriter(temp_avi, cv2.VideoWriter_fourcc(*"MJPG"), FPS, (w, h))
170
+ # for i in range(n_frames):
171
+ # writer.write(decode_frame(all_frames[i]))
172
+ # writer.release()
173
+
174
+ # subprocess.run(
175
+ # ["ffmpeg", "-y",
176
+ # "-i", temp_avi,
177
+ # "-c:v", "libx264", "-preset", "fast",
178
+ # "-crf", "18", "-pix_fmt", "yuv420p",
179
+ # "-movflags", "+faststart",
180
+ # output],
181
+ # check=True, capture_output=True,
182
+ # )
183
+ # os.remove(temp_avi)
184
+ # return output
185
+
186
  # ─────────────────────────────────────────────
187
  # MCAP helpers (abc-teleop)
188
  # ─────────────────────────────────────────────
 
251
  tmp_dir = tempfile.mkdtemp(prefix="viewer_")
252
  try:
253
  # ── Egoverse (zarr β†’ single front camera) ───────────────────────
254
+ # if dataset == "EgoVerse":
255
+ # yield f"Fetching zarr for {uuid} ...", None, None, None
256
+ # try:
257
+ # mp4 = convert_zarr_from_hf(uuid, tmp_dir)
258
+ # yield f"Done: {uuid}", mp4, None, None
259
+ # except Exception as e:
260
+ # yield f"Error: {e}", None, None, None
261
+
262
  if dataset == "EgoVerse":
263
+ yield f"Downloading zarr for {uuid} ...", None, None, None
264
  try:
265
  mp4 = convert_zarr_from_hf(uuid, tmp_dir)
266
  yield f"Done: {uuid}", mp4, None, None