Spaces:
Build error
Build error
| from supabase import create_client, Client | |
| from PIL import Image | |
| from io import BytesIO | |
| import requests | |
| import os | |
| # function to add watermark to images | |
| def addWatermark(background: Image.Image, logo: Image.Image) -> Image.Image: | |
| background = background.convert("RGBA") | |
| logo = logo.convert("RGBA").resize((int(0.08 * background.size[0]), int(0.08 * background.size[0]))) | |
| background.paste(logo, (10, background.size[1] - logo.size[1] - 10), logo) | |
| return background | |
| # function to download an image from url and return as bytes objects | |
| def returnBytesData(url: str) -> BytesIO: | |
| response = requests.get(url) | |
| return BytesIO(response.content) | |
| # function to get public URLs of paths | |
| def supabaseGetPublicURL(path: str) -> str: | |
| url_string = f"https://lvuhhlrkcuexzqtsbqyu.supabase.co/storage/v1/object/public/Stores/{path}" | |
| return url_string.replace(" ", "%20") | |
| # function to deduct credit | |
| def deductAndTrackCredit(storename: str, endpoint: str) -> str: | |
| url: str = os.environ["SUPABASE_URL"] | |
| key: str = os.environ["SUPABASE_KEY"] | |
| supabase: Client = create_client(url, key) | |
| current, _ = supabase.table('ClientConfig').select('CreditBalance').eq("StoreName", f"{storename}").execute() | |
| if current[1] == []: | |
| return "Not Found" | |
| else: | |
| current = current[1][0]["CreditBalance"] | |
| if current > 0: | |
| data, _ = supabase.table('ClientConfig').update({'CreditBalance': current - 1}).eq("StoreName", | |
| f"{storename}").execute() | |
| data, _ = supabase.table('UsageHistory').insert( | |
| {'StoreName': f"{storename}", 'APIEndpoint': f"{endpoint}"}).execute() | |
| return "Success" | |
| else: | |
| return "No Credits Available" | |