Spaces:
Running
on
T4
Running
on
T4
| # from fastapi import FastAPI | |
| # import boto3 | |
| # import os | |
| # app = FastAPI() | |
| # # Configure DigitalOcean Spaces (S3 Compatible) | |
| # session = boto3.session.Session() | |
| # client = session.client( | |
| # 's3', | |
| # region_name='blr1', # DigitalOcean region | |
| # endpoint_url='https://blr1.digitaloceanspaces.com', # endpoint | |
| # aws_access_key_id=os.getenv("DO_SPACES_KEY"), | |
| # aws_secret_access_key=os.getenv("DO_SPACES_SECRET") | |
| # ) | |
| # BUCKET_NAME = "milestone" | |
| # BASE_URL = f"https://{BUCKET_NAME}.blr1.digitaloceanspaces.com" | |
| # @app.get("/list-images") | |
| # def list_images(): | |
| # category_name = "BirthdayParty" | |
| # original_prefix = f"faceswap/target/{category_name}/original/" | |
| # thumb_prefix = f"faceswap/target/{category_name}/thumb/" | |
| # # List objects in original | |
| # original_objects = client.list_objects_v2(Bucket=BUCKET_NAME, Prefix=original_prefix) | |
| # thumb_objects = client.list_objects_v2(Bucket=BUCKET_NAME, Prefix=thumb_prefix) | |
| # original_files = [obj["Key"].split("/")[-1] for obj in original_objects.get("Contents", []) if obj["Key"].endswith(".png")] | |
| # thumb_files = [obj["Key"].split("/")[-1] for obj in thumb_objects.get("Contents", []) if obj["Key"].endswith(".png")] | |
| # items = [] | |
| # for idx, filename in enumerate(sorted(original_files), start=1): | |
| # if filename in thumb_files: # match only if both exist | |
| # items.append({ | |
| # "categoryId": f"birthdaypartyimage_{idx}", | |
| # "url": f"{BASE_URL}/{original_prefix}{filename}", | |
| # "thumburl": f"{BASE_URL}/{thumb_prefix}{filename}" | |
| # }) | |
| # return { | |
| # "categoryName": category_name, | |
| # "items": items | |
| # } | |