File size: 3,388 Bytes
87ab4d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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)