Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,55 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
app = FastAPI()
|
| 11 |
-
templates = Jinja2Templates(directory="templates")
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
def load_videos():
|
| 15 |
-
"""Fetch the current video list from the public dataset. Returns [] if
|
| 16 |
-
metadata.json doesn't exist yet (e.g. before the first upload)."""
|
| 17 |
-
try:
|
| 18 |
-
resp = requests.get(METADATA_URL, timeout=10, params={"_": "nocache"})
|
| 19 |
-
if resp.status_code != 200:
|
| 20 |
-
return []
|
| 21 |
-
entries = resp.json()
|
| 22 |
-
return sorted(entries, key=lambda e: e.get("uploadedAt", ""), reverse=True)
|
| 23 |
-
except Exception:
|
| 24 |
-
return []
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
@app.get("/", response_class=HTMLResponse)
|
| 28 |
-
def home(request: Request):
|
| 29 |
-
videos = load_videos()
|
| 30 |
-
return templates.TemplateResponse(
|
| 31 |
-
"index.html", {"request": request, "videos": videos}
|
| 32 |
-
)
|
| 33 |
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
| 43 |
)
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, send_file
|
| 2 |
+
from huggingface_hub import HfApi
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
DATASET = "gopallikehack/Skills_Lecture"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
+
api = HfApi()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.route("/")
|
| 16 |
+
def home():
|
| 17 |
+
|
| 18 |
+
files = api.list_repo_files(
|
| 19 |
+
repo_id=DATASET,
|
| 20 |
+
repo_type="dataset"
|
| 21 |
+
)
|
| 22 |
|
| 23 |
+
videos = [
|
| 24 |
+
f for f in files
|
| 25 |
+
if f.lower().endswith(
|
| 26 |
+
(".mp4", ".mkv", ".webm")
|
| 27 |
)
|
| 28 |
+
]
|
| 29 |
|
| 30 |
+
return render_template(
|
| 31 |
+
"index.html",
|
| 32 |
+
videos=videos
|
| 33 |
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@app.route("/watch/<path:name>")
|
| 37 |
+
def watch(name):
|
| 38 |
+
|
| 39 |
+
url = (
|
| 40 |
+
f"https://huggingface.co/datasets/"
|
| 41 |
+
f"{DATASET}/resolve/main/{name}"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
return render_template(
|
| 45 |
+
"player.html",
|
| 46 |
+
video=url,
|
| 47 |
+
title=name
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
app.run(
|
| 53 |
+
host="0.0.0.0",
|
| 54 |
+
port=7860
|
| 55 |
+
)
|