Spaces:
Sleeping
Sleeping
File size: 1,464 Bytes
0e76cc0 ac852ab 0e76cc0 ac852ab c4c0404 ac852ab 0e76cc0 ac852ab c4c0404 0e76cc0 ac852ab c4c0404 0e76cc0 ac852ab c4c0404 ac852ab 0e76cc0 ac852ab 0e76cc0 ac852ab 0e76cc0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | from flask import Flask, render_template, request, Response
from huggingface_hub import HfApi
import requests
app = Flask(__name__)
DATASET = "gopallikehack/Skills_Lecture"
api = HfApi()
def get_videos():
files = api.list_repo_files(
repo_id=DATASET,
repo_type="dataset"
)
return [
x for x in files
if x.lower().endswith(".mp4")
]
@app.route("/")
def home():
videos = get_videos()
return render_template(
"index.html",
videos=videos
)
@app.route("/watch/<path:name>")
def watch(name):
return render_template(
"player.html",
title=name,
video=name
)
@app.route("/stream/<path:name>")
def stream(name):
url = (
f"https://huggingface.co/datasets/"
f"{DATASET}/resolve/main/{name}"
)
headers={}
if "Range" in request.headers:
headers["Range"] = request.headers["Range"]
r = requests.get(
url,
headers=headers,
stream=True
)
response = Response(
r.iter_content(
chunk_size=1024*1024
),
status=r.status_code,
content_type=r.headers.get(
"content-type"
)
)
if "Content-Range" in r.headers:
response.headers["Content-Range"] = r.headers["Content-Range"]
if "Accept-Ranges" in r.headers:
response.headers["Accept-Ranges"] = r.headers["Accept-Ranges"]
return response |