Spaces:
Sleeping
Sleeping
Download scripts/verify_setup.py from Abrar144/stylesense-backend: direct link, hf CLI and curl.
- Browser
- Download file 4.4 kB
-
https://huggingface.co/spaces/Abrar144/stylesense-backend/resolve/main/scripts/verify_setup.py
- Command line
-
hf download hf://spaces/Abrar144/stylesense-backend/scripts/verify_setup.py
-
curl -L -o verify_setup.py https://huggingface.co/spaces/Abrar144/stylesense-backend/resolve/main/scripts/verify_setup.py
4.4 kB
| """ | |
| Verify Setup Script β Tests connectivity to all services. | |
| Run this after setting up .env to verify everything works. | |
| """ | |
| import sys | |
| import os | |
| # Add parent to path so we can import app | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def check_supabase(): | |
| """Test Supabase connectivity.""" | |
| print("\nπ Checking Supabase connection...") | |
| try: | |
| from supabase import create_client | |
| url = os.getenv("SUPABASE_URL") | |
| key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") | |
| if not url or not key: | |
| print(" β SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY not set") | |
| return False | |
| client = create_client(url, key) | |
| # Try to query β will fail if tables don't exist yet, but connection works | |
| try: | |
| result = client.table("products").select("id", count="exact").limit(1).execute() | |
| print(f" β Connected! Products table exists with {result.count} rows") | |
| except Exception as e: | |
| if "does not exist" in str(e).lower() or "relation" in str(e).lower(): | |
| print(" β οΈ Connected, but 'products' table doesn't exist yet (run schema.sql)") | |
| else: | |
| print(f" β Connected! (table check: {str(e)[:80]})") | |
| return True | |
| except Exception as e: | |
| print(f" β Failed: {e}") | |
| return False | |
| def check_storage(): | |
| """Test Supabase Storage access.""" | |
| print("\nπ Checking Supabase Storage...") | |
| try: | |
| from supabase import create_client | |
| url = os.getenv("SUPABASE_URL") | |
| key = os.getenv("SUPABASE_SERVICE_ROLE_KEY") | |
| bucket = os.getenv("SUPABASE_STORAGE_BUCKET", "product-images") | |
| client = create_client(url, key) | |
| buckets = client.storage.list_buckets() | |
| bucket_names = [b.name for b in buckets] | |
| if bucket in bucket_names: | |
| print(f" β Storage bucket '{bucket}' exists") | |
| else: | |
| print(f" β οΈ Storage bucket '{bucket}' not found. Available: {bucket_names}") | |
| print(f" Create it in Supabase Dashboard β Storage β New Bucket") | |
| return True | |
| except Exception as e: | |
| print(f" β Failed: {e}") | |
| return False | |
| def check_gemini(): | |
| """Test Gemini API connectivity.""" | |
| print("\nπ Checking Gemini API...") | |
| try: | |
| from google import genai | |
| api_key = os.getenv("GEMINI_API_KEY") | |
| if not api_key: | |
| print(" β GEMINI_API_KEY not set") | |
| return False | |
| client = genai.Client(api_key=api_key) | |
| response = client.models.generate_content( | |
| model="gemini-2.5-flash", | |
| contents="Say 'StyleSense AI is ready' in exactly those words.", | |
| ) | |
| print(f" β Gemini API working! Response: {response.text.strip()[:80]}") | |
| return True | |
| except Exception as e: | |
| print(f" β Failed: {e}") | |
| return False | |
| def check_env_vars(): | |
| """Check all required environment variables are set.""" | |
| print("\nπ Checking environment variables...") | |
| required = [ | |
| "SUPABASE_URL", | |
| "SUPABASE_ANON_KEY", | |
| "SUPABASE_SERVICE_ROLE_KEY", | |
| "SUPABASE_STORAGE_BUCKET", | |
| "GEMINI_API_KEY", | |
| "ADMIN_PASSWORD", | |
| ] | |
| all_set = True | |
| for var in required: | |
| val = os.getenv(var) | |
| if val: | |
| # Mask the value for security | |
| masked = val[:8] + "..." if len(val) > 8 else val | |
| print(f" β {var} = {masked}") | |
| else: | |
| print(f" β {var} is NOT set") | |
| all_set = False | |
| return all_set | |
| if __name__ == "__main__": | |
| print("=" * 60) | |
| print(" StyleSense β Setup Verification") | |
| print("=" * 60) | |
| results = { | |
| "Environment Variables": check_env_vars(), | |
| "Supabase Connection": check_supabase(), | |
| "Supabase Storage": check_storage(), | |
| "Gemini API": check_gemini(), | |
| } | |
| print("\n" + "=" * 60) | |
| print(" RESULTS") | |
| print("=" * 60) | |
| for check, passed in results.items(): | |
| status = "β PASS" if passed else "β FAIL" | |
| print(f" {status} β {check}") | |
| all_passed = all(results.values()) | |
| print(f"\n{'π All checks passed!' if all_passed else 'β οΈ Some checks failed. Fix the issues above.'}") | |
| print("=" * 60) | |