|
| 1 | +# Streamlit Cloud Deployment Guide |
| 2 | + |
| 3 | +This guide covers deploying the Napkin AI Visual Generator web interface to Streamlit Cloud. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- GitHub account with repository access |
| 8 | +- Napkin AI API token |
| 9 | +- Python 3.10+ locally for testing |
| 10 | + |
| 11 | +## Local Testing |
| 12 | + |
| 13 | +Before deploying, test the app locally: |
| 14 | + |
| 15 | +```bash |
| 16 | +# Install dependencies |
| 17 | +poetry install |
| 18 | + |
| 19 | +# Set environment variable (optional, can use UI input) |
| 20 | +export NAPKIN_API_TOKEN="your-token-here" |
| 21 | + |
| 22 | +# Run the app |
| 23 | +poetry run streamlit run streamlit_app.py |
| 24 | + |
| 25 | +# Open in browser |
| 26 | +# http://localhost:8501 |
| 27 | +``` |
| 28 | + |
| 29 | +## Deployment Steps |
| 30 | + |
| 31 | +### 1. Prepare Your Repository |
| 32 | + |
| 33 | +Ensure these files are in your repository: |
| 34 | +- `streamlit_app.py` - Main application file |
| 35 | +- `pyproject.toml` - Poetry dependencies (Streamlit Cloud supports Poetry) |
| 36 | +- `.streamlit/config.toml` - App configuration |
| 37 | + |
| 38 | +### 2. Create Streamlit Cloud Account |
| 39 | + |
| 40 | +1. Go to [share.streamlit.io](https://share.streamlit.io) |
| 41 | +2. Sign up with GitHub |
| 42 | +3. Authorize Streamlit to access your repositories |
| 43 | + |
| 44 | +### 3. Deploy Your App |
| 45 | + |
| 46 | +1. Click **"New app"** in Streamlit Cloud dashboard |
| 47 | +2. Select your repository and branch |
| 48 | +3. Set **Main file path**: `streamlit_app.py` |
| 49 | +4. Open **Advanced settings** |
| 50 | + |
| 51 | +### 4. Configure Secrets |
| 52 | + |
| 53 | +In Advanced settings, add your secrets in TOML format: |
| 54 | + |
| 55 | +```toml |
| 56 | +# Required |
| 57 | +NAPKIN_API_TOKEN = "your-actual-napkin-api-token" |
| 58 | + |
| 59 | +# Optional defaults |
| 60 | +[defaults] |
| 61 | +style = "vibrant-strokes" |
| 62 | +format = "svg" |
| 63 | +variations = 1 |
| 64 | +``` |
| 65 | + |
| 66 | +**Important**: Never commit secrets to your repository! |
| 67 | + |
| 68 | +### 5. Python Version |
| 69 | + |
| 70 | +In Advanced settings, set: |
| 71 | +- **Python version**: `3.10` |
| 72 | + |
| 73 | +### 6. Deploy |
| 74 | + |
| 75 | +Click **Deploy!** Your app will be available at: |
| 76 | +``` |
| 77 | +https://[your-app-name].streamlit.app |
| 78 | +``` |
| 79 | + |
| 80 | +## Post-Deployment |
| 81 | + |
| 82 | +### Viewing Logs |
| 83 | + |
| 84 | +1. Go to your app in Streamlit Cloud dashboard |
| 85 | +2. Click **"Manage app"** |
| 86 | +3. Select **"Logs"** to view deployment and runtime logs |
| 87 | + |
| 88 | +### Updating the App |
| 89 | + |
| 90 | +The app auto-deploys when you push to the configured branch: |
| 91 | + |
| 92 | +```bash |
| 93 | +# Make changes locally |
| 94 | +git add . |
| 95 | +git commit -m "Update streamlit app" |
| 96 | +git push origin main |
| 97 | +``` |
| 98 | + |
| 99 | +### Monitoring |
| 100 | + |
| 101 | +Check the footer of your deployed app for: |
| 102 | +- Version number (currently v0.2.1) |
| 103 | +- Git commit hash |
| 104 | +- Last update timestamp |
| 105 | + |
| 106 | +## Configuration |
| 107 | + |
| 108 | +### Environment Variables |
| 109 | + |
| 110 | +The app supports these environment variables: |
| 111 | + |
| 112 | +| Variable | Description | Required | |
| 113 | +|----------|-------------|----------| |
| 114 | +| `NAPKIN_API_TOKEN` | Your Napkin AI API token | Yes* | |
| 115 | + |
| 116 | +*Can be entered via UI if not set in environment |
| 117 | + |
| 118 | +### Custom Theme |
| 119 | + |
| 120 | +Edit `.streamlit/config.toml` to customize appearance: |
| 121 | + |
| 122 | +```toml |
| 123 | +[theme] |
| 124 | +primaryColor = "#FF6B6B" |
| 125 | +backgroundColor = "#FFFFFF" |
| 126 | +secondaryBackgroundColor = "#F0F2F6" |
| 127 | +textColor = "#262730" |
| 128 | +font = "sans serif" |
| 129 | +``` |
| 130 | + |
| 131 | +## Troubleshooting |
| 132 | + |
| 133 | +### App Won't Start |
| 134 | + |
| 135 | +1. Check Python version is 3.10+ |
| 136 | +2. Verify all dependencies in `pyproject.toml` |
| 137 | +3. Check logs for import errors |
| 138 | + |
| 139 | +### 403 Forbidden Errors |
| 140 | + |
| 141 | +This was fixed in v0.2.1. The app now: |
| 142 | +- Adds Bearer token authentication to API requests |
| 143 | +- Pre-downloads files in worker thread |
| 144 | +- Handles both CDN URLs and authenticated endpoints |
| 145 | + |
| 146 | +### Memory Issues |
| 147 | + |
| 148 | +If you encounter memory errors: |
| 149 | +1. Reduce image dimensions (PNG) |
| 150 | +2. Generate fewer variations |
| 151 | +3. Use SVG format when possible |
| 152 | + |
| 153 | +### Slow Generation |
| 154 | + |
| 155 | +- Check Napkin AI service status |
| 156 | +- Verify network connectivity |
| 157 | +- Consider reducing variations |
| 158 | + |
| 159 | +## Security Best Practices |
| 160 | + |
| 161 | +1. **Never commit API tokens** to your repository |
| 162 | +2. **Use Streamlit secrets** for sensitive data |
| 163 | +3. **Rotate tokens regularly** |
| 164 | +4. **Monitor usage** in your Napkin AI dashboard |
| 165 | +5. **Set spending limits** if available |
| 166 | + |
| 167 | +## Advanced Configuration |
| 168 | + |
| 169 | +### Custom Domain |
| 170 | + |
| 171 | +Streamlit Cloud supports custom domains (Pro plan): |
| 172 | +1. Go to app settings |
| 173 | +2. Add your domain |
| 174 | +3. Configure DNS CNAME |
| 175 | + |
| 176 | +### Analytics |
| 177 | + |
| 178 | +Add analytics by modifying `streamlit_app.py`: |
| 179 | + |
| 180 | +```python |
| 181 | +# Google Analytics example |
| 182 | +st.markdown(''' |
| 183 | +<script async src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script> |
| 184 | +<script> |
| 185 | + window.dataLayer = window.dataLayer || []; |
| 186 | + function gtag(){dataLayer.push(arguments);} |
| 187 | + gtag('js', new Date()); |
| 188 | + gtag('config', 'GA_ID'); |
| 189 | +</script> |
| 190 | +''', unsafe_allow_html=True) |
| 191 | +``` |
| 192 | + |
| 193 | +### Caching |
| 194 | + |
| 195 | +Implement caching for better performance: |
| 196 | + |
| 197 | +```python |
| 198 | +@st.cache_data(ttl=3600) |
| 199 | +def get_cached_styles(): |
| 200 | + return STYLES |
| 201 | +``` |
| 202 | + |
| 203 | +## Support |
| 204 | + |
| 205 | +- **Streamlit Issues**: [Streamlit Community](https://discuss.streamlit.io) |
| 206 | +- **Napkin AI Issues**: api@napkin.ai |
| 207 | +- **App Issues**: [GitHub Issues](https://github.com/yourusername/napkin-api-playground/issues) |
| 208 | + |
| 209 | +## Version History |
| 210 | + |
| 211 | +- **v0.2.1** - Fixed authentication issues, improved error handling |
| 212 | +- **v0.2.0** - Initial Streamlit web interface |
| 213 | +- **v0.1.x** - CLI only versions |
| 214 | + |
| 215 | +--- |
| 216 | + |
| 217 | +Last updated: 2025-08-07 |
0 commit comments