Delete HUGGINGFACE_DEPLOYMENT.md
Browse files- HUGGINGFACE_DEPLOYMENT.md +0 -156
HUGGINGFACE_DEPLOYMENT.md
DELETED
|
@@ -1,156 +0,0 @@
|
|
| 1 |
-
# Hugging Face Deployment Guide
|
| 2 |
-
|
| 3 |
-
This guide will help you deploy the Smart Budget Recommendation API to Hugging Face Spaces.
|
| 4 |
-
|
| 5 |
-
## Prerequisites
|
| 6 |
-
|
| 7 |
-
1. A Hugging Face account (sign up at https://huggingface.co)
|
| 8 |
-
2. MongoDB connection string ready
|
| 9 |
-
3. Git installed (optional, you can also use the web interface)
|
| 10 |
-
|
| 11 |
-
## Step-by-Step Deployment
|
| 12 |
-
|
| 13 |
-
### Step 1: Create a New Space
|
| 14 |
-
|
| 15 |
-
1. Go to https://huggingface.co/spaces
|
| 16 |
-
2. Click "Create new Space"
|
| 17 |
-
3. Fill in the details:
|
| 18 |
-
- **Space name**: `smart-budget-recommendation` (or your preferred name)
|
| 19 |
-
- **SDK**: Select **Docker**
|
| 20 |
-
- **Visibility**: Choose Public or Private
|
| 21 |
-
4. Click "Create Space"
|
| 22 |
-
|
| 23 |
-
### Step 2: Add secrets (MongoDB and optional OpenAI)
|
| 24 |
-
|
| 25 |
-
1. In your Space, go to **Settings** (gear icon)
|
| 26 |
-
2. Navigate to **Variables and secrets** section
|
| 27 |
-
3. Click **New secret**
|
| 28 |
-
4. Add the following secrets:
|
| 29 |
-
- **Name**: `MONGODB_URI`
|
| 30 |
-
- **Value**: `mongodb://expenseuser:Kem_6o%3F%3F@165.227.69.221:27017/expense?authSource=admin`
|
| 31 |
-
- **Name**: `OPENAI_API_KEY` *(optional, enables GPT-based recommendations)*
|
| 32 |
-
- **Value**: `sk-...`
|
| 33 |
-
5. Click **Add secret** after each entry
|
| 34 |
-
|
| 35 |
-
### Step 3: Upload Files
|
| 36 |
-
|
| 37 |
-
You can upload files in two ways:
|
| 38 |
-
|
| 39 |
-
#### Option A: Using Git (Recommended)
|
| 40 |
-
|
| 41 |
-
1. Clone your Space repository:
|
| 42 |
-
```bash
|
| 43 |
-
git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
|
| 44 |
-
cd YOUR_SPACE_NAME
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
2. Copy all files from this project:
|
| 48 |
-
- `app/` directory (all Python files)
|
| 49 |
-
- `Dockerfile`
|
| 50 |
-
- `requirements.txt`
|
| 51 |
-
- `.dockerignore`
|
| 52 |
-
- `README.md` (optional)
|
| 53 |
-
|
| 54 |
-
3. Commit and push:
|
| 55 |
-
```bash
|
| 56 |
-
git add .
|
| 57 |
-
git commit -m "Initial deployment"
|
| 58 |
-
git push
|
| 59 |
-
```
|
| 60 |
-
|
| 61 |
-
#### Option B: Using Web Interface
|
| 62 |
-
|
| 63 |
-
1. In your Space, click **Files and versions** tab
|
| 64 |
-
2. Click **Add file** → **Upload files**
|
| 65 |
-
3. Upload all files:
|
| 66 |
-
- All files from `app/` directory
|
| 67 |
-
- `Dockerfile`
|
| 68 |
-
- `requirements.txt`
|
| 69 |
-
- `.dockerignore`
|
| 70 |
-
|
| 71 |
-
### Step 4: Wait for Build
|
| 72 |
-
|
| 73 |
-
1. Hugging Face will automatically detect the `Dockerfile` and start building
|
| 74 |
-
2. You can monitor the build progress in the **Logs** tab
|
| 75 |
-
3. The build typically takes 2-5 minutes
|
| 76 |
-
|
| 77 |
-
### Step 5: Verify Deployment
|
| 78 |
-
|
| 79 |
-
Once the build completes:
|
| 80 |
-
|
| 81 |
-
1. Your API will be available at: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space`
|
| 82 |
-
2. Test the health endpoint: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/health`
|
| 83 |
-
3. View API documentation: `https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/docs`
|
| 84 |
-
|
| 85 |
-
## Testing Your Deployment
|
| 86 |
-
|
| 87 |
-
### Using cURL
|
| 88 |
-
|
| 89 |
-
```bash
|
| 90 |
-
# Health check
|
| 91 |
-
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/health
|
| 92 |
-
|
| 93 |
-
# Get recommendations (replace user123 with actual user_id)
|
| 94 |
-
curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/recommendations/user123
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
### Using Python
|
| 98 |
-
|
| 99 |
-
```python
|
| 100 |
-
import requests
|
| 101 |
-
|
| 102 |
-
BASE_URL = "https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space"
|
| 103 |
-
|
| 104 |
-
# Health check
|
| 105 |
-
response = requests.get(f"{BASE_URL}/health")
|
| 106 |
-
print(response.json())
|
| 107 |
-
|
| 108 |
-
# Get recommendations
|
| 109 |
-
response = requests.get(f"{BASE_URL}/recommendations/user123")
|
| 110 |
-
print(response.json())
|
| 111 |
-
```
|
| 112 |
-
|
| 113 |
-
## Important Notes
|
| 114 |
-
|
| 115 |
-
1. **Port Configuration**: Hugging Face Spaces expect apps to serve on port **7860**, so the Dockerfile exposes and binds to that port.
|
| 116 |
-
|
| 117 |
-
2. **Environment Variables**: Secrets such as `MONGODB_URI` (and optional `OPENAI_API_KEY`) are injected automatically into the container environment.
|
| 118 |
-
|
| 119 |
-
3. **Cold Starts**: The first request after inactivity may take longer (cold start). Subsequent requests will be faster
|
| 120 |
-
|
| 121 |
-
4. **Resource Limits**: Free Hugging Face Spaces have resource limits. For production use, consider upgrading
|
| 122 |
-
|
| 123 |
-
5. **Custom Domain**: You can add a custom domain in Space settings if needed
|
| 124 |
-
|
| 125 |
-
## Troubleshooting
|
| 126 |
-
|
| 127 |
-
### Build Fails
|
| 128 |
-
|
| 129 |
-
- Check the **Logs** tab for error messages
|
| 130 |
-
- Ensure `Dockerfile` is in the root directory
|
| 131 |
-
- Verify all required files are uploaded
|
| 132 |
-
|
| 133 |
-
### Connection Errors
|
| 134 |
-
|
| 135 |
-
- Verify `MONGODB_URI` secret is set correctly
|
| 136 |
-
- Check MongoDB server is accessible from Hugging Face's servers
|
| 137 |
-
- Review connection string encoding (special characters should be URL-encoded)
|
| 138 |
-
|
| 139 |
-
### API Not Responding
|
| 140 |
-
|
| 141 |
-
- Check the **Logs** tab for runtime errors
|
| 142 |
-
- Verify the application starts successfully
|
| 143 |
-
- Test the `/health` endpoint first
|
| 144 |
-
|
| 145 |
-
## Updating Your Deployment
|
| 146 |
-
|
| 147 |
-
1. Make changes to your code locally
|
| 148 |
-
2. Commit and push to your Space repository
|
| 149 |
-
3. Hugging Face will automatically rebuild and redeploy
|
| 150 |
-
|
| 151 |
-
## Support
|
| 152 |
-
|
| 153 |
-
For issues specific to:
|
| 154 |
-
- **Hugging Face Spaces**: Check [Hugging Face Documentation](https://huggingface.co/docs/hub/spaces)
|
| 155 |
-
- **This Application**: Check the main README.md file
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|