File size: 3,530 Bytes
de4dcc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# πŸš€ HuggingFace Deployment - Complete Guide
## Phase 2 Backend Deployment

---

## Method 1: Web UI (Easiest) - RECOMMENDED

### Step 1: Create Space on HuggingFace

1. **Go to:** https://huggingface.co/spaces

2. **Click:** "Create new Space"

3. **Fill in:**
   - **Owner:** ammarakk (your username)
   - **Space name:** `todo-app-backend`
   - **SDK:** Docker
   - **License:** MIT
   - **Hardware:** CPU basic (free) ⚠️
   - **Visibility:** Public

4. **Click:** "Create Space"

### Step 2: Get Git URL

After creating, you'll see a section like:
```
Git clone
git clone https://huggingface.co/spaces/ammarakk/todo-app-backend
```

### Step 3: Push Code

Open terminal in project directory:
```bash
cd hf-space
git remote add space https://huggingface.co/spaces/ammarakk/todo-app-backend
git push space master
```

### Step 4: Configure Environment Variables

1. Go to your Space page
2. Click "Settings" β†’ "Repository secrets" or "Variables"
3. Add these secrets:

**Secret 1:**
- Name: `NEON_DATABASE_URL`
- Value: `postgresql://neondb_owner:npg_ChtFeYRd02nq@ep-lucky-meadow-abpkcyn6-pooler.eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require`

**Secret 2:**
- Name: `JWT_SECRET`
- Value: `your-jwt-secret-key-here`

4. Click "Save" / "Update"

### Step 5: Restart Space

After adding secrets:
- Click "Settings" β†’ "Factory restart"
- Space will rebuild with new environment variables

### Step 6: Access Your Backend!

Your backend will be live at:
```
https://huggingface.co/spaces/ammarakk/todo-app-backend
```

Or:
```
https://ammarakk-todo-app-backend.hf.space
```

**API Endpoints:**
- Health: `{space_url}/health`
- Auth: `{space_url}/api/auth/*`
- Todos: `{space_url}/api/todos/*`
- Docs: `{space_url}/docs`

---

## Method 2: CLI (If you have huggingface-cli)

### Step 1: Install CLI
```bash
pip install huggingface_hub
```

### Step 2: Login
```bash
huggingface-cli login
```
Enter token: `YOUR_HF_TOKEN_HERE`

### Step 3: Create Space
```bash
huggingface-cli space create \
  --name todo-app-backend \
  --sdk docker \
  --license mit
```

### Step 4: Push Code
```bash
cd hf-space
git remote add space https://huggingface.co/spaces/ammarakk/todo-app-backend
git push space master
```

### Step 5: Configure Secrets
Go to web UI and add environment variables (see Step 4 in Method 1)

---

## βœ… Verification Commands

After deployment, test these:

```bash
# Health check
curl https://huggingface.co/spaces/ammarakk/todo-app-backend/health

# API docs (open in browser)
# https://huggingface.co/spaces/ammarakk/todo-app-backend/docs
```

---

## πŸ”— Connecting Frontend

Once backend is live, update frontend:

**In Vercel Dashboard:**
1. Project β†’ Settings β†’ Environment Variables
2. Update `NEXT_PUBLIC_API_URL`:
   ```bash
   NEXT_PUBLIC_API_URL=https://ammarakk-todo-app-backend.hf.space
   ```
3. Redeploy frontend

**OR Locally:**
```bash
# frontend/.env.local
NEXT_PUBLIC_API_URL=https://ammarakk-todo-app-backend.hf.space
```

---

## 🎯 Summary

**What You Need:**
1. Create space on HuggingFace (web UI)
2. Push code (1 command)
3. Add environment variables (2 secrets)
4. Restart space

**Total Time:** 5 minutes

**Backend Live At:**
```
https://ammarakk-todo-app-backend.hf.space
```

---

## πŸŽ‰ Full-Stack Status

After completing this:

βœ… **Frontend:** Vercel (LIVE)
βœ… **Backend:** HuggingFace (LIVE after steps above)
βœ… **Database:** Neon (Connected)
βœ… **AI:** Qwen + HuggingFace (Ready)

**Your AI-Powered Todo Chatbot will be FULLY LIVE!** πŸš€