Download app.py from 000x/sinhala-subtitle-hardcoder: direct link, hf CLI and curl.
- Browser
- Download file 2.59 kB
-
https://huggingface.co/spaces/000x/sinhala-subtitle-hardcoder/resolve/main/app.py
- Command line
-
hf download hf://spaces/000x/sinhala-subtitle-hardcoder/app.py
-
curl -L -o app.py https://huggingface.co/spaces/000x/sinhala-subtitle-hardcoder/resolve/main/app.py
2.59 kB
| import os | |
| from flask import Flask, render_template, request, redirect, url_for, flash, jsonify | |
| import database as db | |
| import credentials | |
| from scheduler import start_background_worker | |
| app = Flask(__name__) | |
| app.secret_key = os.environ.get("SECRET_KEY", "dev-key-change-me") | |
| db.init_db() | |
| start_background_worker() | |
| def index(): | |
| tasks = db.list_tasks() | |
| configured = credentials.is_configured() | |
| return render_template("index.html", tasks=tasks, configured=configured) | |
| def add_task(): | |
| video_url = request.form.get("video_url", "").strip() | |
| title = request.form.get("title", "").strip() | |
| description = request.form.get("description", "").strip() | |
| privacy = request.form.get("privacy", "SELF") | |
| if not video_url or not title: | |
| flash("Video URL and title are required.", "error") | |
| return redirect(url_for("index")) | |
| if not credentials.is_configured(): | |
| flash("Add your Page ID and access token (Settings, or as env secrets) before queuing a task.", "error") | |
| return redirect(url_for("index")) | |
| db.create_task(video_url, title, description, privacy) | |
| flash("Task queued. You can close this tab -- it keeps uploading in the background.", "success") | |
| return redirect(url_for("index")) | |
| def remove_task(task_id): | |
| db.delete_task(task_id) | |
| return redirect(url_for("index")) | |
| def tasks_json(): | |
| """Polled by the page's JS to refresh statuses without a full reload.""" | |
| return jsonify(db.list_tasks()) | |
| def settings(): | |
| env_active = credentials.using_env_secrets() | |
| if request.method == "POST": | |
| if env_active: | |
| flash("Page ID / token are set via env secrets and can't be edited here.", "error") | |
| return redirect(url_for("settings")) | |
| page_id = request.form.get("page_id", "").strip() | |
| token = request.form.get("access_token", "").strip() | |
| if page_id: | |
| db.set_setting("page_id", page_id) | |
| if token: | |
| db.set_setting("access_token", token) | |
| flash("Settings saved.", "success") | |
| return redirect(url_for("settings")) | |
| return render_template( | |
| "settings.html", | |
| page_id=db.get_setting("page_id", ""), | |
| access_token=db.get_setting("access_token", ""), | |
| env_active=env_active, | |
| ) | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 7860)) | |
| app.run(host="0.0.0.0", port=port) | |