Upload QUICKSTART_SECRETS.md with huggingface_hub
Browse files- QUICKSTART_SECRETS.md +143 -0
QUICKSTART_SECRETS.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# π Quick Start: Enable Captions on Your Space
|
| 2 |
+
|
| 3 |
+
Your HF Space is now deployed with **secure credential handling**. Follow these steps to enable AI captions for UI elements.
|
| 4 |
+
|
| 5 |
+
## 3-Step Setup
|
| 6 |
+
|
| 7 |
+
### Step 1: Get Your Qwen API Key
|
| 8 |
+
1. Sign up at: **https://dashscope.console.aliyun.com/**
|
| 9 |
+
2. Navigate to **API Keys**
|
| 10 |
+
3. Copy your API key (format: `sk-...`)
|
| 11 |
+
4. Keep it safe! β οΈ
|
| 12 |
+
|
| 13 |
+
### Step 2: Add Secret to Your Space (Choose One)
|
| 14 |
+
|
| 15 |
+
#### **Option A: Web UI (Easiest)**
|
| 16 |
+
1. Go to: https://huggingface.co/spaces/makeitfr/omniparsev2-ui-detector
|
| 17 |
+
2. Click **Settings** βοΈ (top right)
|
| 18 |
+
3. Scroll to **Secrets** section
|
| 19 |
+
4. Click **Add a secret**
|
| 20 |
+
5. Enter:
|
| 21 |
+
- **Name**: `QWEN_API_KEY`
|
| 22 |
+
- **Value**: `sk-your-api-key-here`
|
| 23 |
+
6. Click **Save**
|
| 24 |
+
7. Wait ~30 seconds for Space to restart
|
| 25 |
+
|
| 26 |
+
#### **Option B: Python Script**
|
| 27 |
+
```bash
|
| 28 |
+
# Set your HF token
|
| 29 |
+
export HF_TOKEN="hf_YOUR_TOKEN_HERE"
|
| 30 |
+
|
| 31 |
+
# Run setup script
|
| 32 |
+
python setup_hf_spaces_secrets.py \
|
| 33 |
+
--space makeitfr/omniparsev2-ui-detector \
|
| 34 |
+
--qwen-key "sk-your-api-key-here"
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
#### **Option C: cURL (Advanced)**
|
| 38 |
+
```bash
|
| 39 |
+
HF_TOKEN="hf_YOUR_TOKEN"
|
| 40 |
+
|
| 41 |
+
curl -X POST \
|
| 42 |
+
"https://huggingface.co/api/spaces/makeitfr/omniparsev2-ui-detector/secrets" \
|
| 43 |
+
-H "Authorization: Bearer ${HF_TOKEN}" \
|
| 44 |
+
-H "Content-Type: application/json" \
|
| 45 |
+
-d '{"key": "QWEN_API_KEY", "value": "sk-your-key"}'
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### Step 3: Test It! π―
|
| 49 |
+
1. Visit your Space: https://makeitfr-omniparsev2-ui-detector.hf.space
|
| 50 |
+
2. Upload a screenshot
|
| 51 |
+
3. Click **Analyze**
|
| 52 |
+
4. Check results - each element now has a caption!
|
| 53 |
+
|
| 54 |
+
**Example Output:**
|
| 55 |
+
```json
|
| 56 |
+
{
|
| 57 |
+
"element_id": "crop_0001",
|
| 58 |
+
"caption": "close button",
|
| 59 |
+
"x": 590,
|
| 60 |
+
"y": 21,
|
| 61 |
+
"confidence": 1.0
|
| 62 |
+
}
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Environment Variables
|
| 66 |
+
|
| 67 |
+
The Space automatically reads these from Secrets:
|
| 68 |
+
|
| 69 |
+
| Variable | Purpose | Required |
|
| 70 |
+
|---|---|---|
|
| 71 |
+
| `QWEN_API_KEY` | Qwen API key | β
Yes |
|
| 72 |
+
| `QWEN_BASE_URL` | Qwen endpoint | β No (default: DashScope) |
|
| 73 |
+
| `QWEN_MODEL` | Model name | β No (default: `qwen-vl-max`) |
|
| 74 |
+
|
| 75 |
+
## Without Secrets?
|
| 76 |
+
|
| 77 |
+
If you don't set up secrets:
|
| 78 |
+
- β
UI detection still works perfectly
|
| 79 |
+
- β Captions show as "unavailable"
|
| 80 |
+
- Everything else functions normally
|
| 81 |
+
|
| 82 |
+
## Verify Setup
|
| 83 |
+
|
| 84 |
+
After adding secrets, check Space logs:
|
| 85 |
+
1. Go to your Space
|
| 86 |
+
2. Look for this message in logs:
|
| 87 |
+
```
|
| 88 |
+
β Caption support enabled (Qwen VL configured)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Security Notes
|
| 92 |
+
|
| 93 |
+
β
**Secure:**
|
| 94 |
+
- Secrets stored encrypted on HF servers
|
| 95 |
+
- Never visible in code or logs
|
| 96 |
+
- Can be changed anytime
|
| 97 |
+
|
| 98 |
+
β **Not Secure:**
|
| 99 |
+
- Hardcoding keys in Python files
|
| 100 |
+
- Committing `.env` to git
|
| 101 |
+
- Sharing in error messages
|
| 102 |
+
|
| 103 |
+
## Get Help
|
| 104 |
+
|
| 105 |
+
### Common Issues
|
| 106 |
+
|
| 107 |
+
**"Caption shows 'unavailable'"**
|
| 108 |
+
- Check if secret is set: Settings β Secrets
|
| 109 |
+
- Verify key name is exactly `QWEN_API_KEY`
|
| 110 |
+
|
| 111 |
+
**"API rate limit"**
|
| 112 |
+
- Wait a few minutes
|
| 113 |
+
- Check Qwen quota: https://dashscope.console.aliyun.com/
|
| 114 |
+
|
| 115 |
+
**"Invalid API key"**
|
| 116 |
+
- Regenerate key at dashscope.console.aliyun.com
|
| 117 |
+
- Update Space secret with new key
|
| 118 |
+
|
| 119 |
+
## Next: Advanced Configuration
|
| 120 |
+
|
| 121 |
+
Want to customize captions? See these files:
|
| 122 |
+
- [`caption_cropped_images.py`](caption_cropped_images.py) - Captioning logic
|
| 123 |
+
- [`caption_integration.py`](caption_integration.py) - Integration with API
|
| 124 |
+
- [`HF_SPACES_SECRETS.md`](HF_SPACES_SECRETS.md) - Full secrets guide
|
| 125 |
+
|
| 126 |
+
## Pricing
|
| 127 |
+
|
| 128 |
+
**Alibaba Qwen VL Pricing:**
|
| 129 |
+
- ~$0.01-0.02 per image
|
| 130 |
+
- 100 images β $1-2
|
| 131 |
+
- Check current: https://dashscope.console.aliyun.com/pricing
|
| 132 |
+
|
| 133 |
+
## Done! π
|
| 134 |
+
|
| 135 |
+
Your Space now has:
|
| 136 |
+
- β
Secure credential handling
|
| 137 |
+
- β
AI-powered UI element captions
|
| 138 |
+
- β
JSON/CSV export with captions
|
| 139 |
+
- β
Beautiful web interface
|
| 140 |
+
|
| 141 |
+
**Start analyzing:** https://makeitfr-omniparsev2-ui-detector.hf.space
|
| 142 |
+
|
| 143 |
+
Questions? Check [HF_SPACES_SECRETS.md](HF_SPACES_SECRETS.md) for detailed docs.
|