Spaces:
Running
Running
Download app.py from gopallikehack/Skills_Lecture: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/gopallikehack/Skills_Lecture/resolve/main/app.py
- Command line
-
hf download hf://spaces/gopallikehack/Skills_Lecture/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gopallikehack/Skills_Lecture/resolve/main/app.py
1.46 kB
| 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") | |
| ] | |
| def home(): | |
| videos = get_videos() | |
| return render_template( | |
| "index.html", | |
| videos=videos | |
| ) | |
| def watch(name): | |
| return render_template( | |
| "player.html", | |
| title=name, | |
| video=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 |