# Habadashi Login Gateway - Local Testing Guide ## Prerequisites 1. Environment variables must be set: - `SUPABASE_URL`: Your Supabase project URL - `SUPABASE_KEY`: Your Supabase anon/service key - `HF_TOKEN`: Hugging Face token with access to private `DLPO/habadashi` Space - `OPENAI_KEY`: OpenAI API key (required by ver20) - `CLIENTPOOL`: Client pool configuration (required by ver20) 2. Install dependencies: ```bash pip install -r requirements.txt ``` ## Local Testing Steps ### Step 1: Set environment variables **PowerShell (Windows):** ```powershell $env:SUPABASE_URL="your-supabase-url" $env:SUPABASE_KEY="your-supabase-key" $env:HF_TOKEN="your-hf-token" $env:OPENAI_KEY="your-openai-key" $env:CLIENTPOOL="your-client-pool" ``` **Bash (Linux/Mac):** ```bash export SUPABASE_URL="your-supabase-url" export SUPABASE_KEY="your-supabase-key" export HF_TOKEN="your-hf-token" export OPENAI_KEY="your-openai-key" export CLIENTPOOL="your-client-pool" ``` ### Step 2: Test bootstrap (download private app) ```bash python bootstrap.py ``` Expected output: - `🔄 Downloading private app from DLPO/habadashi...` - `✅ Download complete: ./private_app` - `🎉 Bootstrap test successful!` This will create a `./private_app/` directory with ver20 files. ### Step 3: Start the application ```bash uvicorn app:app --host 0.0.0.0 --port 7860 ``` Or use Gradio's default launch (if app.py is configured to run directly): ```bash python app.py ``` ### Step 4: Verify routes 1. **Root route**: http://localhost:7860/ - Should redirect to `/login/` if not authenticated - Should redirect to `/app/` if authenticated 2. **Login UI**: http://localhost:7860/login/ - Enter email and password - On success, should set cookie and redirect to `/app/` 3. **Protected app**: http://localhost:7860/app/ - Should show ver20 Gradio interface if authenticated - Should redirect to login if not authenticated 4. **Logout**: http://localhost:7860/logout - Should clear cookie and redirect to `/login/` ## Troubleshooting ### Issue: "HF_TOKEN not found" - Make sure `HF_TOKEN` is set in environment variables - Verify token has access to private `DLPO/habadashi` Space ### Issue: "Failed to import ver20 app" - Check that `./private_app/app.py` exists - Verify ver20's `app.py` exports `app` variable (Gradio Blocks instance) - Check Python path is correctly set ### Issue: "SUPABASE_URL and SUPABASE_KEY must be set" - Set both environment variables before running the app ### Issue: Cookie not persisting (localhost HTTP) - For local development, you may need to modify cookie settings in `login.py` - Remove `Secure` flag for HTTP testing: `SameSite=Lax;` (remove `Secure;`) ## Deployment to HF Space Once local testing is successful, deploy to public HF Space: 1. Create new public Space: `DLPO/habadashi_login` 2. Set secrets in Space settings: - `SUPABASE_URL` - `SUPABASE_KEY` - `HF_TOKEN` - `OPENAI_KEY` - `CLIENTPOOL` 3. Upload files: - `app.py` - `bootstrap.py` - `login.py` - `requirements.txt` - `README.md` The Space will automatically: 1. Download ver20 from private `DLPO/habadashi` on startup 2. Mount login UI at `/login/` 3. Mount ver20 app at `/app/` (protected by auth)