File size: 3,769 Bytes
60c56d7 |
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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# Deployment Guide
## Quick Start
### 1. Copy Firebase Credentials
Copy your Firebase Admin SDK JSON file to the project root:
```bash
# Windows
copy C:\Colorize\colorize-662df-firebase-adminsdk-fbsvc-e080668793.json .
# Linux/Mac
cp /path/to/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json .
```
**Important**: For Hugging Face Spaces, you should add this as a secret instead of committing it to the repository.
### 2. Deploy to Hugging Face Spaces
```bash
# Initialize git repository
git init
git add .
git commit -m "Deploy Colorize API"
# Add Hugging Face remote
git remote add origin https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize
# Push to Hugging Face
git push -u origin main
```
### 3. Configure Hugging Face Space Secrets
1. Go to your Space: https://huggingface.co/spaces/LogicGoInfotechSpaces/Colorize
2. Navigate to Settings → Secrets
3. Add a new secret:
- **Name**: `FIREBASE_CREDENTIALS`
- **Value**: Paste the entire contents of your Firebase Admin SDK JSON file
### 4. Update Dockerfile for Secrets (Optional)
If you want to use the secret, you can modify the Dockerfile to create the file from the secret:
```dockerfile
# Add this before the CMD line
RUN if [ -n "$FIREBASE_CREDENTIALS" ]; then \
echo "$FIREBASE_CREDENTIALS" > colorize-662df-firebase-adminsdk-fbsvc-e080668793.json; \
fi
```
## Testing Locally
### Run with Docker
```bash
# Build image
docker build -t colorize-api .
# Run container
docker run -p 7860:7860 \
-v $(pwd)/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json:/app/colorize-662df-firebase-adminsdk-fbsvc-e080668793.json \
colorize-api
```
### Run without Docker
```bash
# Install dependencies
pip install -r requirements.txt
# Run API
uvicorn app.main:app --host 0.0.0.0 --port 7860
```
## API Endpoints
Once deployed, your API will be available at:
- `https://logicgoinfotechspaces-colorize.hf.space/health` - Health check
- `https://logicgoinfotechspaces-colorize.hf.space/colorize` - Colorize image
- `https://logicgoinfotechspaces-colorize.hf.space/upload` - Upload image
## Frontend Integration Example
```javascript
// Initialize Firebase
import { initializeApp } from "firebase/app";
import { initializeAppCheck, ReCaptchaEnterpriseProvider } from "firebase/app-check";
const firebaseConfig = {
apiKey: "AIzaSyBIB6rcfyyqy5niERTXWvVD714Ter4Vx68",
authDomain: "colorize-662df.firebaseapp.com",
projectId: "colorize-662df",
storageBucket: "colorize-662df.firebasestorage.app",
messagingSenderId: "69166278311",
appId: "1:69166278311:web:0e8c50b8dd8627aaeadd82",
measurementId: "G-58CC2J8XKX"
};
const app = initializeApp(firebaseConfig);
const appCheck = initializeAppCheck(app, {
provider: new ReCaptchaEnterpriseProvider('YOUR_RECAPTCHA_SITE_KEY'),
isTokenAutoRefreshEnabled: true
});
// Colorize image function
async function colorizeImage(file) {
const { getToken } = await import('firebase/app-check');
const token = await getToken(appCheck);
const formData = new FormData();
formData.append('file', file);
const response = await fetch('https://logicgoinfotechspaces-colorize.hf.space/colorize', {
method: 'POST',
headers: {
'X-Firebase-AppCheck': token.token
},
body: formData
});
return await response.json();
}
```
## Troubleshooting
### Model Not Loading
- Check Hugging Face Space logs
- Verify model ID: `rsortino/ColorizeNet`
- Ensure sufficient disk space (models can be large)
### Firebase App Check Failing
- Verify credentials are correctly set as a secret
- Check that App Check is enabled in Firebase Console
- Ensure reCAPTCHA Enterprise is set up
### Port Issues
Hugging Face Spaces automatically handles port 7860. The Dockerfile is configured for this.
|