Upload 16 files
Browse files- app.py +16 -0
- check_repo_db.py +114 -0
app.py
CHANGED
|
@@ -434,6 +434,14 @@ def run_v3_retry():
|
|
| 434 |
except Exception as e:
|
| 435 |
return f"Error: {e}"
|
| 436 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
with gr.Blocks() as app:
|
| 438 |
gr.Markdown("# YouTube Video Orchestrator Host")
|
| 439 |
gr.Markdown("Deploy this to Hugging Face Spaces or run locally. It fetches pending links from your database and delegates them to FastAPI workers or Kaggle.")
|
|
@@ -452,12 +460,20 @@ with gr.Blocks() as app:
|
|
| 452 |
v3_status_btn = gr.Button("Check Status")
|
| 453 |
v3_retry_btn = gr.Button("Retry Failed Videos")
|
| 454 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
v3_output_log = gr.Textbox(label="Terminal Output", lines=15)
|
| 456 |
|
| 457 |
v3_launch_btn.click(fn=run_v3_launch, inputs=[v3_max_workers, v3_videos], outputs=v3_output_log)
|
| 458 |
v3_sync_btn.click(fn=run_v3_sync, inputs=[], outputs=v3_output_log)
|
| 459 |
v3_status_btn.click(fn=run_v3_status, inputs=[], outputs=v3_output_log)
|
| 460 |
v3_retry_btn.click(fn=run_v3_retry, inputs=[], outputs=v3_output_log)
|
|
|
|
| 461 |
|
| 462 |
with gr.Tab("Database Sync"):
|
| 463 |
gr.Markdown("Sync (Add) new API keys and YouTube Links into your database.")
|
|
|
|
| 434 |
except Exception as e:
|
| 435 |
return f"Error: {e}"
|
| 436 |
|
| 437 |
+
def run_verify_repo(repo_id):
|
| 438 |
+
cmd = ["python", "check_repo_db.py", "--repo-id", repo_id]
|
| 439 |
+
try:
|
| 440 |
+
res = subprocess.run(cmd, capture_output=True, text=True, cwd=os.path.dirname(os.path.abspath(__file__)))
|
| 441 |
+
return f"--- REPO VERIFICATION OUTPUT ---\n{res.stdout}\n{res.stderr}"
|
| 442 |
+
except Exception as e:
|
| 443 |
+
return f"Error: {e}"
|
| 444 |
+
|
| 445 |
with gr.Blocks() as app:
|
| 446 |
gr.Markdown("# YouTube Video Orchestrator Host")
|
| 447 |
gr.Markdown("Deploy this to Hugging Face Spaces or run locally. It fetches pending links from your database and delegates them to FastAPI workers or Kaggle.")
|
|
|
|
| 460 |
v3_status_btn = gr.Button("Check Status")
|
| 461 |
v3_retry_btn = gr.Button("Retry Failed Videos")
|
| 462 |
|
| 463 |
+
gr.Markdown("---")
|
| 464 |
+
gr.Markdown("### Verify Database against any HF Repository")
|
| 465 |
+
gr.Markdown("List files in a target HF repo and mark any matching pending videos as 'done' in your tracker database.")
|
| 466 |
+
with gr.Row():
|
| 467 |
+
verify_repo_id = gr.Textbox(label="Hugging Face Repo ID", value="AdhyanshVerma/YT")
|
| 468 |
+
verify_btn = gr.Button("Verify and Update DB", variant="primary")
|
| 469 |
+
|
| 470 |
v3_output_log = gr.Textbox(label="Terminal Output", lines=15)
|
| 471 |
|
| 472 |
v3_launch_btn.click(fn=run_v3_launch, inputs=[v3_max_workers, v3_videos], outputs=v3_output_log)
|
| 473 |
v3_sync_btn.click(fn=run_v3_sync, inputs=[], outputs=v3_output_log)
|
| 474 |
v3_status_btn.click(fn=run_v3_status, inputs=[], outputs=v3_output_log)
|
| 475 |
v3_retry_btn.click(fn=run_v3_retry, inputs=[], outputs=v3_output_log)
|
| 476 |
+
verify_btn.click(fn=run_verify_repo, inputs=[verify_repo_id], outputs=v3_output_log)
|
| 477 |
|
| 478 |
with gr.Tab("Database Sync"):
|
| 479 |
gr.Markdown("Sync (Add) new API keys and YouTube Links into your database.")
|
check_repo_db.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sqlite3
|
| 3 |
+
import argparse
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from huggingface_hub import HfApi, login
|
| 6 |
+
|
| 7 |
+
def get_db_path():
|
| 8 |
+
# Priority list of where the DB might be
|
| 9 |
+
paths = [
|
| 10 |
+
"/data/tracker.db",
|
| 11 |
+
"/home/adhyansh/datasets/yt/hf_space_host/db/tracker.db",
|
| 12 |
+
"/home/adhyansh/datasets/yt/scripts/db/tracker.db"
|
| 13 |
+
]
|
| 14 |
+
for p in paths:
|
| 15 |
+
if os.path.exists(p):
|
| 16 |
+
return p
|
| 17 |
+
return None
|
| 18 |
+
|
| 19 |
+
def load_hf_token():
|
| 20 |
+
token = os.environ.get("HF_TOKEN", "")
|
| 21 |
+
if not token:
|
| 22 |
+
p = Path.home() / ".cache" / "huggingface" / "token"
|
| 23 |
+
if p.exists():
|
| 24 |
+
token = p.read_text().strip()
|
| 25 |
+
return token
|
| 26 |
+
|
| 27 |
+
def main():
|
| 28 |
+
parser = argparse.ArgumentParser(description="List files in an HF Repo and mark matching videos as 'done' in the local database.")
|
| 29 |
+
parser.add_argument("--repo-id", default="AdhyanshVerma/YT", help="Hugging Face Repository ID")
|
| 30 |
+
parser.add_argument("--db-path", default=None, help="Explicit path to the tracker.db SQLite database")
|
| 31 |
+
args = parser.parse_args()
|
| 32 |
+
|
| 33 |
+
# 1. Connect to Database
|
| 34 |
+
db_path = args.db_path or get_db_path()
|
| 35 |
+
if not db_path:
|
| 36 |
+
print("β Error: Could not find tracker.db in default locations. Please specify with --db-path")
|
| 37 |
+
return
|
| 38 |
+
|
| 39 |
+
print(f"β
Using Database: {db_path}")
|
| 40 |
+
conn = sqlite3.connect(db_path)
|
| 41 |
+
cursor = conn.cursor()
|
| 42 |
+
|
| 43 |
+
# Fetch all video_ids that are NOT done
|
| 44 |
+
try:
|
| 45 |
+
cursor.execute("SELECT video_id FROM videos WHERE status != 'done'")
|
| 46 |
+
pending_videos = [row[0] for row in cursor.fetchall()]
|
| 47 |
+
print(f"π Found {len(pending_videos)} videos in DB that are not marked as 'done'.")
|
| 48 |
+
except Exception as e:
|
| 49 |
+
print(f"β Database error: {e}")
|
| 50 |
+
return
|
| 51 |
+
|
| 52 |
+
if not pending_videos:
|
| 53 |
+
print("β
All videos are already marked as done. Exiting.")
|
| 54 |
+
return
|
| 55 |
+
|
| 56 |
+
# 2. Authenticate with Hugging Face
|
| 57 |
+
token = load_hf_token()
|
| 58 |
+
if token:
|
| 59 |
+
login(token=token)
|
| 60 |
+
print("β
Authenticated with Hugging Face token.")
|
| 61 |
+
else:
|
| 62 |
+
print("β οΈ Warning: No HF_TOKEN found. If the repo is private, this might fail.")
|
| 63 |
+
|
| 64 |
+
api = HfApi()
|
| 65 |
+
|
| 66 |
+
# 3. List all files from the target repository
|
| 67 |
+
repo_types_to_try = ["dataset", "space", "model"]
|
| 68 |
+
files = []
|
| 69 |
+
|
| 70 |
+
print(f"π Searching for files in repository '{args.repo_id}'...")
|
| 71 |
+
for repo_type in repo_types_to_try:
|
| 72 |
+
try:
|
| 73 |
+
# We use recursive=True to list ALL files without downloading them
|
| 74 |
+
files = api.list_repo_files(repo_id=args.repo_id, repo_type=repo_type)
|
| 75 |
+
print(f"β
Successfully listed {len(files)} files as a '{repo_type}' repo.")
|
| 76 |
+
break
|
| 77 |
+
except Exception as e:
|
| 78 |
+
# Continue checking other repo types
|
| 79 |
+
pass
|
| 80 |
+
|
| 81 |
+
if not files:
|
| 82 |
+
print(f"β Error: Could not find or list files in repository '{args.repo_id}'. Make sure it exists and you have access.")
|
| 83 |
+
return
|
| 84 |
+
|
| 85 |
+
# 4. Check files against database and modify DB
|
| 86 |
+
print("\nπ Analyzing files against the database...")
|
| 87 |
+
|
| 88 |
+
marked_done_count = 0
|
| 89 |
+
|
| 90 |
+
for vid in pending_videos:
|
| 91 |
+
match_found = False
|
| 92 |
+
|
| 93 |
+
# Search for the video ID anywhere in the full file paths (this catches directory names like staging/.../Jb9Jx0KkJl8/...)
|
| 94 |
+
for f in files:
|
| 95 |
+
if vid in f:
|
| 96 |
+
match_found = True
|
| 97 |
+
break
|
| 98 |
+
|
| 99 |
+
if match_found:
|
| 100 |
+
print(f" π’ Match found for video: {vid} - Marking as 'done'!")
|
| 101 |
+
cursor.execute("UPDATE videos SET status='done' WHERE video_id=?", (vid,))
|
| 102 |
+
marked_done_count += 1
|
| 103 |
+
|
| 104 |
+
# 5. Save changes
|
| 105 |
+
if marked_done_count > 0:
|
| 106 |
+
conn.commit()
|
| 107 |
+
print(f"\nπ Success! Updated {marked_done_count} videos to 'done' in the database.")
|
| 108 |
+
else:
|
| 109 |
+
print("\nβ οΈ No new matching videos found in the repository. No database changes made.")
|
| 110 |
+
|
| 111 |
+
conn.close()
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
main()
|