Spaces:
Running on Zero
Running on Zero
feat: add Hugging Face Space LFS support and improve error handling for remote example videos
Browse files- app.py +14 -1
- index.html +16 -5
app.py
CHANGED
|
@@ -169,8 +169,14 @@ def list_sample_videos(asset_dir: str = "__assets__", max_samples: int = 8) -> L
|
|
| 169 |
app = Server()
|
| 170 |
|
| 171 |
@app.api()
|
| 172 |
-
def get_examples() -> List[
|
| 173 |
samples = list_sample_videos("__assets__/", max_samples=16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
return [FileData(path=s["path"], orig_name=s["name"]) for s in samples]
|
| 175 |
|
| 176 |
@app.api()
|
|
@@ -190,6 +196,13 @@ def run_inference(video_file: dict) -> dict:
|
|
| 190 |
if not os.path.exists(video_path):
|
| 191 |
return {"error": "Video file not found"}
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
print(f"Start processing: {video_path}")
|
| 194 |
pred_ranges, pred_intra_labels, pred_inter_labels, video_np_full, fps = single_video_inference(
|
| 195 |
video_path=video_path,
|
|
|
|
| 169 |
app = Server()
|
| 170 |
|
| 171 |
@app.api()
|
| 172 |
+
def get_examples() -> List[dict]:
|
| 173 |
samples = list_sample_videos("__assets__/", max_samples=16)
|
| 174 |
+
space_id = os.getenv("SPACE_ID")
|
| 175 |
+
|
| 176 |
+
if space_id:
|
| 177 |
+
hub_base = f"https://huggingface.co/spaces/{space_id}/resolve/main/__assets__/"
|
| 178 |
+
return [{"url": f"{hub_base}{s['name']}", "orig_name": s["name"]} for s in samples]
|
| 179 |
+
|
| 180 |
return [FileData(path=s["path"], orig_name=s["name"]) for s in samples]
|
| 181 |
|
| 182 |
@app.api()
|
|
|
|
| 196 |
if not os.path.exists(video_path):
|
| 197 |
return {"error": "Video file not found"}
|
| 198 |
|
| 199 |
+
# Check if it's a Git LFS pointer instead of a real video
|
| 200 |
+
if os.path.getsize(video_path) < 1000:
|
| 201 |
+
with open(video_path, "rb") as f:
|
| 202 |
+
header = f.read(100)
|
| 203 |
+
if b"version https://git-lfs" in header:
|
| 204 |
+
return {"error": "LFS pointer detected. Please ensure video files are fully downloaded on the Space."}
|
| 205 |
+
|
| 206 |
print(f"Start processing: {video_path}")
|
| 207 |
pred_ranges, pred_intra_labels, pred_inter_labels, video_np_full, fps = single_video_inference(
|
| 208 |
video_path=video_path,
|
index.html
CHANGED
|
@@ -637,11 +637,22 @@
|
|
| 637 |
item.appendChild(label);
|
| 638 |
|
| 639 |
item.onclick = async () => {
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
};
|
| 646 |
|
| 647 |
examplesGrid.appendChild(item);
|
|
|
|
| 637 |
item.appendChild(label);
|
| 638 |
|
| 639 |
item.onclick = async () => {
|
| 640 |
+
try {
|
| 641 |
+
const response = await fetch(ex.url);
|
| 642 |
+
if (!response.ok) throw new Error("Fetch failed");
|
| 643 |
+
|
| 644 |
+
const blob = await response.blob();
|
| 645 |
+
if (blob.size < 1000) {
|
| 646 |
+
alert("Warning: This file appears to be a Git LFS pointer and not a real video. Please check your Space's LFS settings.");
|
| 647 |
+
}
|
| 648 |
+
|
| 649 |
+
const file = new File([blob], ex.orig_name || 'example.mp4', { type: 'video/mp4' });
|
| 650 |
+
handleFile(file);
|
| 651 |
+
window.scrollTo({ top: dropZone.offsetTop - 100, behavior: 'smooth' });
|
| 652 |
+
} catch (err) {
|
| 653 |
+
console.error(err);
|
| 654 |
+
alert("Failed to load example video. It may be missing from the server.");
|
| 655 |
+
}
|
| 656 |
};
|
| 657 |
|
| 658 |
examplesGrid.appendChild(item);
|