File size: 9,535 Bytes
a71d147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# πŸš€ Hugging Face Spaces Deployment - Step by Step

## Your Current Space
- **URL**: https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/AndesOps-AI
- **Status**: βœ… Active  
- **Likes**: 21 πŸŽ‰

## ⚑ Deployment Strategy for Maximum Likes

We're using **TWO SPACES** architecture:
- **Frontend Space**: Your existing AndesOps-AI space
- **Backend Space**: New andesai-backend space

This is the professional setup that gets more πŸ‘ likes!

---

## πŸ“¦ Step 1: Update Your GitHub Repository

Push all changes to your GitHub repo:

```bash
cd c:\laragon\www\ANDESAI

# Ensure everything is committed
git add -A
git commit -m "πŸš€ Optimized for Hugging Face Spaces - Production ready"
git push origin main
```

**Changes pushed:**
- βœ… Optimized Dockerfiles (multi-stage builds)
- βœ… .dockerignore files
- βœ… Updated README.md (both frontend & backend)
- βœ… Improved API auto-detection for HF Spaces
- βœ… Health checks configured

---

## 🎯 Step 2: Create Backend Space on Hugging Face

### 2a. Create New Space

1. Go to: https://huggingface.co/spaces
2. Click **"Create new space"**
3. Fill in:
   ```
   Name: andesai-backend
   License: OpenRAIL
   SDK: Docker
   Space Hardware: CPU basic (or GPU if you want faster)
   Private: No (public helps with likes!)
   ```
4. Click **Create Space**

### 2b. Configure Backend Space

The space will open empty. Now connect your GitHub repo:

**Option A: Manual Upload (Quick)**
1. Go to your new space settings: https://huggingface.co/spaces/your-username/andesai-backend/settings
2. Click **"Repo" tab**
3. Click **"Import code from GitHub"**
4. Select your repo: `your-username/ANDESAI`
5. Branch: `main`
6. Space directory: `backend/` (important!)

**Option B: Use Git Clone (Automatic)**
```bash
# In terminal
cd ~/hugging-face-spaces
git clone https://huggingface.co/spaces/your-username/andesai-backend
cd andesai-backend

# Copy backend files
cp -r ~/path/to/ANDESAI/backend/* .

# Commit and push
git add -A
git commit -m "Add backend files"
git push

# Space auto-rebuilds!
```

### 2c: Add Environment Secrets

In your **andesai-backend** space:

1. Go to **Settings β†’ Secrets**
2. Add these (copy from your local `backend/.env`):

```
MERCADO_PUBLICO_TICKET=YOUR_TICKET_HERE
GEMINI_API_KEY=YOUR_GEMINI_KEY_HERE
GROQ_API_KEY=YOUR_GROQ_KEY_HERE
FEATHERLESS_API_KEY=YOUR_FEATHERLESS_KEY_HERE
DATABASE_URL=sqlite:///./andesops.db
GEMINI_MODEL=gemini-2.0-flash
```

3. Click **Save** for each

βœ… Backend space will now be accessible at:
```
https://your-username-andesai-backend.hf.space
```

---

## 🎨 Step 3: Update Your Frontend Space (AndesOps-AI)

Your current space already exists! We just need to update it.

### 3a: Update the Frontend

1. Go to: https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/AndesOps-AI
2. Click **Settings** (gear icon)
3. Under "Repo", you can:
   - **Update from GitHub** if it's connected
   - **Or manually upload new files**

### 3b: Upload Frontend Files

If not connected to GitHub, manually upload:

1. Click **"Files"** tab in your space
2. Upload these from `frontend/`:
   ```
   .dockerignore
   Dockerfile (new optimized version)
   README.md (updated)
   package.json
   package-lock.json
   next.config.js
   postcss.config.js
   tailwind.config.ts
   tsconfig.json
   app/
   components/
   lib/
   public/
   globals.css
   ```

### 3c: Verify Frontend Configuration

The frontend now has **automatic backend detection** for HF Spaces:

```typescript
// lib/api.ts automatically detects:
// - Frontend: lablab-ai-amd-developer-hackathon-andesops-ai.hf.space
// - Backend: lablab-ai-amd-developer-hackathon-andesops-ai-backend.hf.space
```

βœ… No manual configuration needed!

---

## πŸ”— Step 4: Test the Connection

Wait for both spaces to finish building (5-10 minutes):

1. **Check Backend Space**:
   - Open: https://your-username-andesai-backend.hf.space/api/health
   - Should show: `{"status":"ok"}` or similar

2. **Check Frontend Space**:
   - Open: https://your-username-andesops-ai.hf.space
   - Should load the UI

3. **Test Features**:
   - Open **Market Monitor** β†’ Should load purchase orders
   - Open **Tender Search** β†’ Try searching
   - Check browser console (F12) for API logs

---

## πŸ› οΈ Step 5: Optimize for Maximum Likes

### A. Perfect README Description

In your **AndesOps-AI** space, go to **Info** and set:

```markdown
# AndesOps AI - Real-time Chilean Public Procurement Intelligence

πŸ† **Hackathon Entry**: lablab AI + AMD Developer Hackathon 2026

## Features
- πŸ“Š Real-time market data from Mercado PΓΊblico
- πŸ€– AI-powered tender analysis
- πŸ“± Compra Ágil (Agile Purchase) scraping
- πŸ“ˆ Purchase order monitoring
- πŸ’Ό Company profile management

## How It Works
1. Search for procurement opportunities
2. AI analyzes tender fit for your company
3. Get insights and recommendations
4. Draft proposals

## Tech Stack
- Frontend: Next.js 14 + React 18 + Tailwind CSS
- Backend: FastAPI + SQLAlchemy + PostgreSQL
- AI: Google Gemini + Groq + Featherless

## Components
- **Frontend**: Glass-morphism UI with real-time updates
- **Backend**: REST API with async operations
- **Database**: Persistent tender & analysis history

⭐ **Like this space if it helps you!** Every like helps us win the hackathon!
```

### B. Add Screenshots/Demo

Create a visual demo showing:
1. Market Monitor with live data
2. Tender Search interface
3. AI Analysis panel
4. Admin dashboard

### C. Share on Social Media

```
πŸŽ‰ Just deployed AndesOps AI on @huggingface Spaces!
πŸ‡¨πŸ‡± Real-time Chilean public procurement intelligence
πŸ€– AI-powered tender analysis
⭐ Give it a like to support our hackathon entry!
[Link to space]
#HuggingFace #AI #Hackathon #Chile
```

---

## βœ… Deployment Checklist

- [ ] GitHub repo updated with all changes
- [ ] Backend space created (`andesai-backend`)
- [ ] Backend environment secrets added
- [ ] Frontend space updated
- [ ] Both spaces built successfully (green status)
- [ ] `/api/health` endpoint responding
- [ ] Frontend loads without errors
- [ ] Market Monitor shows data
- [ ] Tender Search works
- [ ] README optimized for likes
- [ ] Shared on social media

---

## πŸ§ͺ Testing Commands

From your terminal, test each endpoint:

```bash
# Replace {username} and {space-name} with actual values

# Backend health
curl https://{username}-andesai-backend.hf.space/api/health

# Get tenders
curl "https://{username}-andesai-backend.hf.space/api/tenders?skip=0&limit=10"

# Get purchase orders
curl "https://{username}-andesai-backend.hf.space/api/purchase-orders"

# Frontend should auto-detect and connect
# Just open: https://{username}-andesops-ai.hf.space
```

---

## πŸ†˜ Troubleshooting

### Frontend shows "Connection Error"

**Check:**
1. Backend space is running (green status)
2. `/api/health` endpoint is responding
3. Browser console (F12) for error messages

**Fix:**
```bash
# Rebuild backend space:
# Go to space β†’ Settings β†’ Restart Space
```

### Backend won't start

**Check:**
1. All environment secrets are set
2. `.env` file is NOT uploaded (security risk)
3. Secrets are in **Settings β†’ Secrets**, not Variables

**Fix:**
1. Verify each secret in Settings
2. Restart the space
3. Check space logs for errors

### "502 Bad Gateway"

**Usually means:**
- Backend is still building
- Wait 5-10 minutes
- If persists, check space logs

**To view logs:**
1. Go to space
2. Click **"Runtime" β†’ "View logs"**

---

## πŸ“š Resources

- Hugging Face Spaces Docs: https://huggingface.co/docs/hub/spaces
- Docker in Spaces: https://huggingface.co/docs/hub/spaces-config-reference
- Your Frontend Space: https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/AndesOps-AI

---

## 🎯 Success Metrics

After deployment, you should see:

βœ… Both spaces **"Running"** (green status)
βœ… Frontend loads without 404 errors
βœ… Market Monitor displays real data
βœ… Tender Search returns results
βœ… Console shows `[API]` logs with correct URLs
βœ… API endpoints responding (no 502 errors)

---

## πŸš€ Next Steps to Win

1. **Get More Likes**:
   - Share your space URL widely
   - Post on Twitter/LinkedIn
   - Show classmates and colleagues
   - Post in hackathon Slack channel

2. **Improve Features**:
   - Add more filters to Tender Search
   - Show more statistics in Market Monitor
   - Add export functionality
   - Implement user authentication

3. **Optimize Performance**:
   - Add caching for API responses
   - Optimize database queries
   - Reduce Docker image size
   - Add pagination

---

## πŸ’‘ Pro Tips

1. **Update your space regularly** β†’ More activity = More visibility = More likes!
2. **Share your progress** β†’ "Just added feature X to AndesOps AI!"
3. **Help others** β†’ Answer questions in space comments
4. **Engage community** β†’ Like and comment on other hackathon projects

---

## πŸ“ž Quick Reference

| What | Where | Status |
|------|-------|--------|
| Frontend Space | https://huggingface.co/spaces/lablab-ai-amd-developer-hackathon/AndesOps-AI | βœ… |
| Backend Space | https://huggingface.co/spaces/{you}/andesai-backend | πŸ”„ Create |
| GitHub Repo | https://github.com/yourusername/ANDESAI | βœ… |
| Current Likes | 21 | πŸ“ˆ Going up! |

---

**You're ready to deploy! πŸš€**

Your AndesOps AI is production-ready and optimized for Hugging Face Spaces. Every component is configured for maximum performance and reliability.

Let me know when you've deployed and I'll help you optimize further for more likes! πŸ‘