Spaces:
Build error
Build error
File size: 11,730 Bytes
93c19dc | 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 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | # π Domify Academy Super Bot - Complete Setup & Deployment Guide
## π¦ What You're Getting
A **production-ready, full-stack AI chatbot** with:
β
**Backend** (FastAPI + NVIDIA API)
- Llama-3 70B LLM with smart fallback chain
- SDXL/Flux image generation
- DuckDuckGo search integration
- DeepSeek-style reasoning
- Rate limiting & monitoring
- Google Sheets feedback logging
β
**Frontend** (React 19 + TypeScript)
- Dark glassmorphism UI (21dev theme)
- Ask | Imagine mode switcher
- Chat sidebar with local storage
- Advanced prompt input (Search/Think toggles)
- Collapsible reasoning panel
- Rich markdown rendering
- Image gallery with download
- File upload & OCR ready
β
**Deployment**
- Dockerfile for Hugging Face Spaces
- Environment configuration
- Complete documentation
---
## π₯ Step 1: Download & Extract Code
**Download the complete code:**
```bash
wget https://files.manuscdn.com/user_upload_by_module/session_file/310519663512731124/eepQdzwGxcStVZQg.gz -O complete-code.tar.gz
tar -xzf complete-code.tar.gz
cd domify-academy-bot
```
---
## π§ Step 2: Setup Backend (Local Testing)
### Install Dependencies
```bash
pnpm install
```
### Create Environment File
Create `.env` file in project root:
```env
# Database
DATABASE_URL=mysql://user:password@localhost:3306/domify_bot
# NVIDIA API
NVIDIA_API_KEY=your_nvidia_api_key_here
# JWT & OAuth
JWT_SECRET=your_jwt_secret_here
OAUTH_SERVER_URL=https://api.manus.im
VITE_OAUTH_PORTAL_URL=https://manus.im
# App Config
VITE_APP_ID=your_app_id
VITE_APP_TITLE=Domify Academy Bot
VITE_APP_LOGO=https://your-logo-url.png
# Frontend API
REACT_APP_API_URL=http://localhost:3000
```
### Run Backend Locally
```bash
pnpm run dev
```
Server will run on `http://localhost:3000`
---
## π¨ Step 3: Setup Frontend (Local Testing)
### Frontend is included in the same project
The frontend automatically starts with the backend. Access it at:
```
http://localhost:3000/chat
```
### Update API Endpoint (if needed)
Edit `client/src/pages/Chat.tsx`:
```typescript
const API_BASE_URL = process.env.REACT_APP_API_URL || "http://localhost:3000";
```
---
## π Step 4: Deploy to Hugging Face Spaces
### 4.1 Create Hugging Face Space
1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
2. Click **"Create new Space"**
3. Select **"Docker"** SDK
4. Name: `domify-academy-bot`
5. Choose **"Public"** (or Private)
6. Click **"Create Space"**
### 4.2 Push Code to Hugging Face
```bash
# Initialize git (if not already done)
git init
git add .
git commit -m "Initial Domify Academy Bot deployment"
# Add Hugging Face remote
git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/domify-academy-bot
# Push to Hugging Face
git push -u origin main
```
**Note:** Replace `YOUR_USERNAME` with your Hugging Face username.
### 4.3 Set Environment Variables in Space
1. Go to your Space settings
2. Find **"Variables and secrets"** section
3. Add these secrets:
| Key | Value | Description |
|-----|-------|-------------|
| `DATABASE_URL` | `mysql://...` | Your MySQL connection string |
| `NVIDIA_API_KEY` | `your_key_here` | NVIDIA API key |
| `JWT_SECRET` | `generate_with_openssl` | `openssl rand -base64 32` |
| `OAUTH_SERVER_URL` | `https://api.manus.im` | OAuth server URL |
| `VITE_OAUTH_PORTAL_URL` | `https://manus.im` | OAuth portal URL |
| `VITE_APP_ID` | `your_app_id` | Application ID |
| `VITE_APP_TITLE` | `Domify Academy Bot` | App title |
| `REACT_APP_API_URL` | `https://YOUR_SPACE_URL` | Your Space URL |
### 4.4 Wait for Build
Hugging Face will automatically:
1. Detect the Dockerfile
2. Build the Docker image
3. Deploy the application
This takes **5-10 minutes**. You'll see a "Building" status.
### 4.5 Access Your Bot
Once deployed, your bot will be available at:
```
https://YOUR_USERNAME-domify-academy-bot.hf.space
```
---
## π File Structure
```
domify-academy-bot/
βββ client/ # Frontend (React)
β βββ src/
β β βββ pages/
β β β βββ Chat.tsx # Main chat interface (Ask/Imagine)
β β β βββ Home.tsx # Landing page
β β β βββ NotFound.tsx # 404 page
β β βββ components/
β β β βββ ChatSidebar.tsx # Sidebar with chat history
β β βββ App.tsx # Routes & layout
β β βββ main.tsx # React entry
β β βββ index.css # Global styles (glassmorphism)
β βββ index.html # HTML template
β βββ public/ # Static assets
βββ server/ # Backend (Express + tRPC)
β βββ llm.ts # NVIDIA LLM integration
β βββ search.ts # DuckDuckGo search
β βββ rateLimit.ts # Rate limiting
β βββ db.ts # Database helpers
β βββ googleSheets.ts # Google Sheets integration
β βββ middleware.ts # Logging, caching, monitoring
β βββ routers.ts # tRPC procedures
β βββ _core/ # Framework internals
βββ drizzle/ # Database schema & migrations
β βββ schema.ts # Table definitions
β βββ migrations/ # SQL migrations
βββ Dockerfile # Docker build config
βββ DEPLOYMENT.md # Deployment guide
βββ BACKEND_README.md # Backend documentation
βββ FRONTEND_SETUP.md # Frontend documentation
βββ QUICKSTART.md # 5-minute setup
βββ package.json # Dependencies
```
---
## π Environment Variables Explained
### Backend Variables
| Variable | Purpose | Example |
|----------|---------|---------|
| `DATABASE_URL` | MySQL connection | `mysql://user:pass@host/db` |
| `NVIDIA_API_KEY` | NVIDIA API key | `nvapi-...` |
| `JWT_SECRET` | Session signing | `base64_random_string` |
| `OAUTH_SERVER_URL` | OAuth provider | `https://api.manus.im` |
### Frontend Variables
| Variable | Purpose | Example |
|----------|---------|---------|
| `REACT_APP_API_URL` | Backend API URL | `https://your-space.hf.space` |
| `VITE_APP_TITLE` | App title | `Domify Academy Bot` |
| `VITE_APP_LOGO` | Logo URL | `https://...logo.png` |
---
## π§ͺ Testing Locally
### Test Backend API
```bash
# Start dev server
pnpm run dev
# In another terminal, test chat endpoint
curl -X POST http://localhost:3000/api/trpc/chat.send \
-H "Content-Type: application/json" \
-d '{
"prompt": "Hello, how are you?",
"enableSearch": false,
"enableThinking": false,
"history": []
}'
```
### Test Frontend
1. Open `http://localhost:3000/chat`
2. Try Ask mode:
- Type a message
- Click Send
- See response appear
3. Try Imagine mode:
- Switch to Imagine
- Type image description
- Click "Generate Image"
4. Test sidebar:
- Create multiple chats
- Switch between them
- Delete a chat
- Verify local storage persistence
---
## π Troubleshooting
### Backend Won't Start
**Error:** `Cannot find module 'express'`
**Solution:**
```bash
pnpm install
pnpm run dev
```
### Database Connection Failed
**Error:** `ECONNREFUSED 127.0.0.1:3306`
**Solution:**
1. Ensure MySQL is running
2. Check `DATABASE_URL` is correct
3. Verify credentials
### Frontend Not Loading
**Error:** `404 Not Found` or blank page
**Solution:**
1. Check dev server is running: `pnpm run dev`
2. Clear browser cache
3. Check browser console for errors
### API Endpoint Not Working
**Error:** `Failed to fetch` or `CORS error`
**Solution:**
1. Verify `REACT_APP_API_URL` is correct
2. Check backend is running
3. Ensure CORS is enabled on backend
4. Check network tab in browser DevTools
### Hugging Face Build Failed
**Error:** Docker build error
**Solution:**
1. Check Dockerfile syntax
2. Verify all environment variables are set
3. Check Space logs for detailed error
4. Try rebuilding the Space
---
## π± Features Walkthrough
### Ask Mode
1. **Send Message**
- Type question
- Press Enter or click Send
- View response with markdown rendering
2. **Search Online**
- Click "Search Online" toggle
- Send message
- Bot will search web for context
3. **Think Longer**
- Click "Think Longer" toggle
- Send message
- View reasoning process in collapsible panel
4. **Upload Files**
- Click "Upload" button
- Select image or document
- Send message with file context
5. **Chat History**
- View all chats in sidebar
- Click to switch between chats
- Delete chats with trash icon
- All stored in browser local storage
### Imagine Mode
1. **Generate Image**
- Type image description
- Click "Generate Image"
- Wait for generation
2. **View Gallery**
- Generated images appear in gallery
- Scroll horizontally to see all
- Click "Download" to save image
- "Video" button coming soon
---
## π¨ Customization
### Change Colors
Edit `client/src/index.css`:
```css
.dark {
--primary: oklch(0.623 0.214 259.815); /* Violet */
--secondary: oklch(0.55 0.15 264); /* Indigo */
--accent: oklch(0.65 0.18 280); /* Light indigo */
--background: oklch(0.07 0.002 0); /* Deep black */
--foreground: oklch(0.95 0.002 0); /* Near white */
}
```
### Change Fonts
Edit `client/index.html`:
```html
<link href="https://fonts.googleapis.com/css2?family=YOUR_FONT&display=swap" rel="stylesheet">
```
### Change App Title
Set `VITE_APP_TITLE` environment variable
---
## π Database Schema
### Tables
1. **users** - User accounts
2. **conversations** - Chat sessions
3. **messages** - Individual messages
4. **generated_images** - Generated images
5. **feedback** - User feedback (logged to Google Sheets)
---
## π Security Best Practices
1. **Never commit `.env` file** - Use environment variables in deployment
2. **Keep API keys secret** - Use Hugging Face Spaces secrets
3. **Enable HTTPS** - Hugging Face provides SSL automatically
4. **Rate limiting** - Enabled by default (30 req/min per user)
5. **Input validation** - All inputs sanitized on backend
---
## π Performance Tips
1. **Cache search results** - 5-minute TTL for DuckDuckGo searches
2. **Lazy load images** - Images load on demand in gallery
3. **Compress responses** - Gzip enabled on all API responses
4. **Browser caching** - Chat history stored locally
5. **Monitor usage** - Check logs for slow endpoints
---
## π Next Steps
1. β
Download and extract code
2. β
Test locally with `pnpm run dev`
3. β
Create Hugging Face Space
4. β
Set environment variables
5. β
Push code to Hugging Face
6. β
Wait for build completion
7. β
Access your bot at Space URL
8. β
Start using!
---
## π Support
### Common Issues
- **Build fails**: Check Dockerfile and environment variables
- **API errors**: Check backend logs in Space
- **Frontend blank**: Check browser console for errors
- **Slow responses**: Check NVIDIA API quota
### Documentation
- `BACKEND_README.md` - Backend API reference
- `FRONTEND_SETUP.md` - Frontend customization
- `DEPLOYMENT.md` - Detailed deployment guide
- `QUICKSTART.md` - 5-minute setup
---
## π You're Ready!
Your Domify Academy Super Bot is ready to deploy. Follow the steps above and you'll have a production-ready AI chatbot running on Hugging Face Spaces in minutes!
**Questions?** Check the documentation files or review the code comments.
**Happy coding! π**
|