BakoAI / scripts /setup_annotated_bucket.py
icanedit2's picture
Deploy backend to HF with player video visibility fix
32bc095
Raw
History Blame Contribute Delete
1.61 kB
"""
Setup script: Creates the 'annotated-videos' public bucket in Supabase Storage.
Run this once from the back-end directory:
python scripts/setup_annotated_bucket.py
"""
import os
import sys
from dotenv import load_dotenv
# Allow running from any directory
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
load_dotenv(os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env"))
from supabase import create_client
SUPABASE_URL = os.environ["SUPABASE_URL"]
SERVICE_KEY = os.environ.get("SUPABASE_SERVICE_KEY") or os.environ["SUPABASE_KEY"]
BUCKET_NAME = "annotated-videos"
def main():
client = create_client(SUPABASE_URL, SERVICE_KEY)
# List existing buckets
try:
buckets = client.storage.list_buckets()
names = [b.name for b in buckets]
if BUCKET_NAME in names:
print(f"✅ Bucket '{BUCKET_NAME}' already exists.")
return
except Exception as e:
print(f"⚠️ Could not list buckets: {e}")
# Create the bucket as public so the frontend can stream videos directly
# without needing signed URLs.
try:
try:
from storage3.types import CreateOrUpdateBucketOptions
opts = CreateOrUpdateBucketOptions(public=True)
except ImportError:
opts = {"public": True}
client.storage.create_bucket(BUCKET_NAME, options=opts)
print(f"✅ Created public bucket '{BUCKET_NAME}'.")
except Exception as e:
print(f"❌ Failed to create bucket: {e}")
sys.exit(1)
if __name__ == "__main__":
main()