Spaces:
Sleeping
Sleeping
Add password authentication for users without HF accounts
Browse files- PASSWORD_AUTH_SETUP.md +109 -0
- app.py +9 -1
PASSWORD_AUTH_SETUP.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Password Protection Setup (No HF Account Required)
|
| 2 |
+
|
| 3 |
+
## β
Solution: Gradio Built-in Authentication
|
| 4 |
+
|
| 5 |
+
**Good news**: You don't need to build your own frontend! Gradio has built-in password protection that works without Hugging Face accounts.
|
| 6 |
+
|
| 7 |
+
## How It Works
|
| 8 |
+
|
| 9 |
+
- Users visit your Space URL
|
| 10 |
+
- They see a login screen (username/password)
|
| 11 |
+
- No Hugging Face account needed!
|
| 12 |
+
- Simple and secure
|
| 13 |
+
|
| 14 |
+
## Setup Steps
|
| 15 |
+
|
| 16 |
+
### Step 1: Update app.py
|
| 17 |
+
|
| 18 |
+
The code is already updated! Just change the password:
|
| 19 |
+
|
| 20 |
+
```python
|
| 21 |
+
demo.launch(
|
| 22 |
+
auth=("starflow", "your-password-here"), # Change this!
|
| 23 |
+
share=False
|
| 24 |
+
)
|
| 25 |
+
```
|
| 26 |
+
|
| 27 |
+
### Step 2: Set Your Password
|
| 28 |
+
|
| 29 |
+
1. **Edit app.py** in your Space (or locally and push)
|
| 30 |
+
2. **Change**: `"your-password-here"` to your actual password
|
| 31 |
+
3. **Save and push**
|
| 32 |
+
|
| 33 |
+
### Step 3: Share Access
|
| 34 |
+
|
| 35 |
+
**Option A: Single Username/Password**
|
| 36 |
+
```python
|
| 37 |
+
auth=("starflow", "my-secure-password")
|
| 38 |
+
```
|
| 39 |
+
- Everyone uses same login
|
| 40 |
+
- Simple to share
|
| 41 |
+
|
| 42 |
+
**Option B: Multiple Users**
|
| 43 |
+
```python
|
| 44 |
+
auth=[
|
| 45 |
+
("user1", "password1"),
|
| 46 |
+
("user2", "password2"),
|
| 47 |
+
("user3", "password3")
|
| 48 |
+
]
|
| 49 |
+
```
|
| 50 |
+
- Different login for each person
|
| 51 |
+
- More control
|
| 52 |
+
|
| 53 |
+
## Usage
|
| 54 |
+
|
| 55 |
+
1. **Make Space Public** (so anyone can access the URL)
|
| 56 |
+
- Settings β Visibility β Public
|
| 57 |
+
- Or keep Private (only collaborators see it)
|
| 58 |
+
|
| 59 |
+
2. **Share the Space URL**:
|
| 60 |
+
- https://huggingface.co/spaces/GlobalStudio/starflow
|
| 61 |
+
|
| 62 |
+
3. **Users visit URL**:
|
| 63 |
+
- See login screen
|
| 64 |
+
- Enter username/password
|
| 65 |
+
- No HF account needed!
|
| 66 |
+
- Access granted β
|
| 67 |
+
|
| 68 |
+
## Security Tips
|
| 69 |
+
|
| 70 |
+
- β
Use strong passwords
|
| 71 |
+
- β
Change password regularly
|
| 72 |
+
- β
Don't share password publicly
|
| 73 |
+
- β
Use different passwords for different users (if using multiple)
|
| 74 |
+
|
| 75 |
+
## Alternative: Environment Variables (More Secure)
|
| 76 |
+
|
| 77 |
+
For better security, use environment variables:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
import os
|
| 81 |
+
|
| 82 |
+
username = os.getenv("STARFLOW_USERNAME", "starflow")
|
| 83 |
+
password = os.getenv("STARFLOW_PASSWORD", "default-password")
|
| 84 |
+
|
| 85 |
+
demo.launch(auth=(username, password))
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
Then set in Space Settings β Variables:
|
| 89 |
+
- `STARFLOW_USERNAME` = your-username
|
| 90 |
+
- `STARFLOW_PASSWORD` = your-password
|
| 91 |
+
|
| 92 |
+
## Benefits
|
| 93 |
+
|
| 94 |
+
β
**No HF account needed** - Users just need password
|
| 95 |
+
β
**Simple** - Built into Gradio
|
| 96 |
+
β
**Secure** - Password protected
|
| 97 |
+
β
**Easy to manage** - Change password anytime
|
| 98 |
+
β
**No custom frontend** - Uses existing Gradio UI
|
| 99 |
+
|
| 100 |
+
## Summary
|
| 101 |
+
|
| 102 |
+
**You DON'T need to build your own frontend!**
|
| 103 |
+
|
| 104 |
+
Just:
|
| 105 |
+
1. Add password to app.py
|
| 106 |
+
2. Make Space Public (or keep Private + share URL)
|
| 107 |
+
3. Share URL + password with users
|
| 108 |
+
4. Done! β
|
| 109 |
+
|
app.py
CHANGED
|
@@ -303,5 +303,13 @@ with gr.Blocks(title="STARFlow - Text-to-Image & Video Generation") as demo:
|
|
| 303 |
)
|
| 304 |
|
| 305 |
if __name__ == "__main__":
|
| 306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
|
|
|
|
| 303 |
)
|
| 304 |
|
| 305 |
if __name__ == "__main__":
|
| 306 |
+
# Password protection - users don't need HF accounts!
|
| 307 |
+
# Change these to your desired username/password
|
| 308 |
+
# For multiple users, use: auth=[("user1", "pass1"), ("user2", "pass2")]
|
| 309 |
+
demo.launch(
|
| 310 |
+
server_name="0.0.0.0",
|
| 311 |
+
server_port=7860,
|
| 312 |
+
auth=("starflow", "your-password-here"), # Change password!
|
| 313 |
+
share=False # Set to True if you want public Gradio link
|
| 314 |
+
)
|
| 315 |
|