bjpromptly commited on
Commit
f372d26
Β·
verified Β·
1 Parent(s): 73e19fd

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +247 -0
README.md ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Garmin AI Coach
3
+ emoji: πŸƒβ€β™‚οΈ
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: "5.x"
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # Garmin AI Coach
13
+
14
+ Your personalized AI fitness assistant powered by Garmin Connect data. Analyse your activities, track progress, and get intelligent coaching recommendations through a conversational interface.
15
+
16
+ ## Features
17
+
18
+ - πŸƒβ€β™‚οΈ **Activity Analysis**: Query your Garmin Connect activities using natural language
19
+ - πŸ’¬ **Conversational AI**: Powered by state-of-the-art language models
20
+ - πŸ“Š **Progress Tracking**: Monitor your fitness journey over time
21
+ - πŸ” **Multi-User Support**: Secure authentication with per-user data isolation
22
+ - ☁️ **Cloud Storage**: Firestore backend for reliable data persistence
23
+
24
+ ## Deployment Guide
25
+
26
+ This guide explains how to deploy the Garmin AI Coach application to HuggingFace Spaces.
27
+
28
+ ### Prerequisites
29
+
30
+ 1. **HuggingFace Account**: [Sign up](https://huggingface.co/join) if you don't have one
31
+ 2. **Google Cloud Service Account Key**: See [Terraform setup](../../terraform/README.md)
32
+ 3. **HuggingFace CLI**: Install with `pip install huggingface_hub[cli]`
33
+
34
+ ### Quick Start
35
+
36
+ #### Option A: Automated Deployment (Recommended)
37
+
38
+ Use the deployment script from repository root:
39
+
40
+ ```bash
41
+ # Generate requirements.txt
42
+ ./infrastructure/deployment/scripts/generate-requirements.sh
43
+
44
+ # Deploy to HuggingFace Spaces
45
+ ./infrastructure/deployment/scripts/deploy-to-hf.sh
46
+ ```
47
+
48
+ #### Option B: Manual Deployment
49
+
50
+ 1. **Authenticate with HuggingFace**:
51
+
52
+ ```bash
53
+ huggingface-cli login
54
+ ```
55
+
56
+ 2. **Create a private Space**:
57
+ - Go to [HuggingFace Spaces](https://huggingface.co/spaces)
58
+ - Click "Create new Space"
59
+ - Set name: `garmin-agent` (or your preferred name)
60
+ - Choose SDK: **Gradio**
61
+ - Visibility: **Private**
62
+
63
+ 3. **Prepare deployment files**:
64
+
65
+ ```bash
66
+ # From repository root
67
+ cd infrastructure/deployment/scripts
68
+ ./generate-requirements.sh
69
+
70
+ # Copy files to repository root
71
+ cp infrastructure/deployment/huggingface/app.py ./app.py
72
+ cp infrastructure/deployment/huggingface/requirements.txt ./requirements.txt
73
+ cp infrastructure/deployment/huggingface/README.md ./README.md
74
+ ```
75
+
76
+ 4. **Deploy to Space**:
77
+
78
+ ```bash
79
+ # Clone your Space repository
80
+ git clone https://huggingface.co/spaces/YOUR_USERNAME/garmin-agent
81
+ cd garmin-agent
82
+
83
+ # Copy application files and workspace
84
+ cp /path/to/repo/app.py ./
85
+ cp /path/to/repo/requirements.txt ./
86
+ cp /path/to/repo/README.md ./
87
+ cp -r /path/to/repo/packages ./
88
+ cp -r /path/to/repo/services ./
89
+
90
+ # Commit and push
91
+ git add .
92
+ git commit -m "Initial deployment"
93
+ git push
94
+ ```
95
+
96
+ 5. **Configure Secrets and Variables**:
97
+
98
+ Go to your Space Settings:
99
+ - **Settings β†’ Secrets** (for sensitive values)
100
+ - **Settings β†’ Variables** (for non-sensitive configuration)
101
+
102
+ **Required Secret** (Settings β†’ Secrets):
103
+ - `GOOGLE_CREDENTIALS_JSON`: Paste the **entire contents** of your service account key JSON file
104
+
105
+ ```json
106
+ {
107
+ "type": "service_account",
108
+ "project_id": "savvy-bit-472903-g9",
109
+ ...
110
+ }
111
+ ```
112
+
113
+ **Required Variables** (Settings β†’ Variables):
114
+ - `DATABASE_TYPE=firestore`
115
+ - `GOOGLE_CLOUD_PROJECT=savvy-bit-472903-g9`
116
+ - `ENABLE_AUTH=true`
117
+ - `ENVIRONMENT=production`
118
+ - `CHAT_AGENT_MODEL=hf:meta-llama/Llama-3.2-3B-Instruct`
119
+
120
+ **Optional Variables**:
121
+ - `HUGGINGFACE_HUB_TOKEN`: Your HF token (required for HF models)
122
+ - `TELEMETRY_BACKEND=disabled`: Telemetry configuration
123
+
124
+ 6. **Restart Space**: After configuring secrets, restart your Space from the Settings page.
125
+
126
+ ### File Structure for Deployment
127
+
128
+ HuggingFace Spaces requires the following structure at repository root:
129
+
130
+ ```
131
+ repository-root/
132
+ β”œβ”€β”€ app.py # Entry point (from infrastructure/deployment/huggingface/app.py)
133
+ β”œβ”€β”€ requirements.txt # Generated dependencies
134
+ β”œβ”€β”€ README.md # This file with HF metadata header
135
+ β”œβ”€β”€ packages/ # Full workspace structure
136
+ β”‚ β”œβ”€β”€ ai-core/
137
+ β”‚ └── shared-config/
138
+ └── services/
139
+ β”œβ”€β”€ cli/
140
+ └── web-app/
141
+ ```
142
+
143
+ **Important**: Deploy the entire workspace structure to maintain package imports and dependencies.
144
+
145
+ ### Environment Variables Reference
146
+
147
+ | Variable | Required | Description | Example |
148
+ |----------|----------|-------------|---------|
149
+ | `GOOGLE_CREDENTIALS_JSON` | Yes (Secret) | Service account key JSON content | See Terraform outputs |
150
+ | `DATABASE_TYPE` | Yes | Database backend type | `firestore` |
151
+ | `GOOGLE_CLOUD_PROJECT` | Yes | GCP project ID | `savvy-bit-472903-g9` |
152
+ | `ENABLE_AUTH` | Yes | Enable multi-user authentication | `true` |
153
+ | `ENVIRONMENT` | Yes | Deployment environment | `production` |
154
+ | `CHAT_AGENT_MODEL` | Yes | AI model specification | `hf:meta-llama/Llama-3.2-3B-Instruct` |
155
+ | `HUGGINGFACE_HUB_TOKEN` | Conditional | HF token for HF models | `hf_xxxxx` |
156
+ | `TELEMETRY_BACKEND` | No | Telemetry configuration | `disabled` |
157
+
158
+ ### Monitoring and Troubleshooting
159
+
160
+ #### View Application Logs
161
+
162
+ In your Space:
163
+
164
+ 1. Go to your Space page
165
+ 2. Click "Logs" tab
166
+ 3. Monitor startup messages and errors
167
+
168
+ #### Common Issues
169
+
170
+ #### 1. "Missing required environment variables"
171
+
172
+ - Solution: Verify all required variables are set in Settings β†’ Variables
173
+ - Check secret `GOOGLE_CREDENTIALS_JSON` is set in Settings β†’ Secrets
174
+
175
+ #### 2. "Failed to parse GOOGLE_CREDENTIALS_JSON"
176
+
177
+ - Solution: Ensure the secret contains valid JSON (entire service account key file)
178
+ - Verify no extra quotes or formatting around the JSON content
179
+
180
+ #### 3. "Failed to import application modules"
181
+
182
+ - Solution: Ensure full workspace structure (packages/, services/) is deployed
183
+ - Verify requirements.txt includes all dependencies
184
+
185
+ **4. "Firestore connection failed"**
186
+
187
+ - Solution: Verify service account has `roles/datastore.user` permission
188
+ - Check `GOOGLE_CLOUD_PROJECT` matches your Firestore project
189
+ - Confirm Firestore database exists in your GCP project
190
+
191
+ **5. "Model not found" or authentication errors**
192
+
193
+ - Solution: For HF models, set `HUGGINGFACE_HUB_TOKEN` in Variables
194
+ - For OpenAI models, set `OPENAI_API_KEY`
195
+ - For Anthropic models, set `ANTHROPIC_API_KEY`
196
+
197
+ #### Testing the Deployment
198
+
199
+ After deployment:
200
+
201
+ 1. Visit your Space URL: `https://huggingface.co/spaces/YOUR_USERNAME/garmin-agent`
202
+ 2. Wait for the Space to build and start (first start takes 2-3 minutes)
203
+ 3. Register a new user account
204
+ 4. Test the chat interface with simple queries
205
+ 5. Verify Firestore connection by checking data persistence
206
+
207
+ ### Updating the Application
208
+
209
+ To update your deployed application:
210
+
211
+ 1. **Update code locally** and test
212
+ 2. **Regenerate requirements.txt** if dependencies changed:
213
+
214
+ ```bash
215
+ ./infrastructure/deployment/scripts/generate-requirements.sh
216
+ ```
217
+
218
+ 3. **Copy updated files** to Space repository
219
+ 4. **Commit and push** changes
220
+ 5. **HF Spaces will automatically rebuild** and restart
221
+
222
+ ### Security Best Practices
223
+
224
+ 1. **Keep Space Private**: Set visibility to "Private" for production
225
+ 2. **Rotate Service Account Keys**: Follow GCP key rotation guidelines
226
+ 3. **Use Secrets for Credentials**: Never commit credentials to repository
227
+ 4. **Monitor Access Logs**: Review Space access logs regularly
228
+ 5. **Enable Authentication**: Always deploy with `ENABLE_AUTH=true`
229
+
230
+ ### Performance Optimization
231
+
232
+ - **Model Selection**: Smaller models (e.g., Llama-3.2-3B) start faster and use less memory
233
+ - **Cold Start**: First request after inactivity may take 30-60 seconds
234
+ - **Firestore Region**: Database in `australia-southeast1` optimises latency for APAC users
235
+ - **Space Hardware**: Upgrade to GPU Space for better performance with larger models
236
+
237
+ ### Support
238
+
239
+ For issues specific to:
240
+
241
+ - **HuggingFace Spaces**: [HF Spaces Documentation](https://huggingface.co/docs/hub/spaces)
242
+ - **Firestore**: [Firestore Documentation](https://cloud.google.com/firestore/docs)
243
+ - **Application Issues**: See repository issues or documentation
244
+
245
+ ---
246
+
247
+ **Note**: This deployment uses HuggingFace Spaces' native Gradio SDK support. The platform automatically handles server configuration, port binding, and SSL certificates.