File size: 10,148 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# AILIXIR Hugging Face Spaces Deployment Guide

## Overview

The AILIXIR platform is deployed across **5 Hugging Face Spaces**:

| Space | Purpose | URL |
|-------|---------|-----|
| `ailixir-api` | Backend API (Laravel + SQLite) | https://huggingface.co/spaces/Ailixir-AI-Team/ailixir-api |
| `ailixir-admet` | ADMET Prediction Service | https://huggingface.co/spaces/shdwRow/ailixir-admet |
| `ailixir-drug-repurposing` | Drug Repurposing Service | https://huggingface.co/spaces/RottenShadow/ailixir-drug-repurposing |
| `ailixir-chemical-rag` | Chemical RAG Service | https://huggingface.co/spaces/RottenShadow/ailixir-chemical-rag |
| `ailixir-generation` | Molecular Generation Service | https://huggingface.co/spaces/shdwRow/ailixir-generation |

---

## 1. Accessing the Spaces

Each Space builds a Docker container from its respective `Dockerfile`. Once built and running, the services are accessible at:

```
https://RottenShadow-{space-name}.hf.space
```

For example:
- **Backend API:** `https://Ailixir-AI-Team-ailixir-api.hf.space`
- **ADMET:** `https://shdwRow-ailixir-admet.hf.space`
- **Drug Repurposing:** `https://RottenShadow-ailixir-drug-repurposing.hf.space`
- **Chemical RAG:** `https://RottenShadow-ailixir-chemical-rag.hf.space`
- **Generation:** `https://shdwRow-ailixir-generation.hf.space`

---

## 2. Space Lifecycle

### Wake-up / Sleep
Spaces on the **free tier** (CPU Basic) go to sleep after **15 minutes of inactivity**. When you access a sleeping Space's URL, it will take **30–120 seconds** to wake up.

To keep a Space awake, you can:
- Use a **cron job** to ping the health endpoint every 10 minutes
- Upgrade to a **paid hardware tier** (CPU Upgrade or GPU)
- Set a **longer sleep timeout** in the Space settings

### Health Check
Each Space exposes a `/health` endpoint. You can check if a service is running:

  ```bash
  curl https://shdwRow-ailixir-admet.hf.space/health
  ```

Expected response: `{"status": "healthy", ...}`

---

## 3. Environment Variables (Secrets)

Each Space requires certain environment variables. These are set as **Space Secrets** in the Hugging Face Space settings.

### 3.1 Backend Space: `ailixir-api`

These are **required** secrets β€” set them in:  
https://huggingface.co/spaces/Ailixir-AI-Team/ailixir-api/settings

| Secret | Value | Description |
|--------|-------|-------------|
| `APP_KEY` | *(generate one)* | Laravel app key. Run: `php artisan key:generate --show` |
| `APP_ENV` | `production` | Application environment |
| `APP_DEBUG` | `false` | Debug mode (keep false in production) |
| `DB_CONNECTION` | `sqlite` | Database engine |
| `SESSION_DRIVER` | `database` | Session storage |
| `CACHE_STORE` | `database` | Cache storage |
| `QUEUE_CONNECTION` | `database` | Queue driver |
| `RUN_MODE` | `hf` | **Must be set to `hf`** to enable supervisor mode |
| `AI_INTEGRATION_ROUTES_ENABLED` | `true` | Enable AI proxy routes |
| `CHEMICAL_AI_URL` | `https://RottenShadow-ailixir-chemical-rag.hf.space` | Chemical RAG service URL |
| `ADMET_AI_URL` | `https://shdwRow-ailixir-admet.hf.space` | ADMET service URL |
| `AI_ADMET_SERVICE_URL` | `https://shdwRow-ailixir-admet.hf.space` | ADMET service URL (alias) |
| `DRUG_REPURPOSING_URL` | `https://RottenShadow-ailixir-drug-repurposing.hf.space` | Drug repurposing service URL |
| `AI_SERVICE_URL` | `https://RottenShadow-ailixir-drug-repurposing.hf.space` | Drug repurposing URL (alias) |
| `GENERATION_SERVICE_URL` | `https://shdwRow-ailixir-generation.hf.space` | Generation service URL |
| `MAIL_MAILER` | `log` | Mail driver (log to console) |
| `CLOUDINARY_URL` | `cloudinary://dummy_key:dummy_secret@dummy_cloud` | Cloudinary (can be dummy) |
| `CLOUDINARY_CLOUD_NAME` | `dummy_cloud` | Cloudinary cloud name |
| `CLOUDINARY_API_KEY` | `dummy_key` | Cloudinary API key |
| `CLOUDINARY_API_SECRET` | `dummy_secret` | Cloudinary API secret |
| `LOG_CHANNEL` | `stderr` | Log output channel |
| `LOG_LEVEL` | `info` | Log level |

**How to generate APP_KEY:**
```bash
# If you have PHP locally:
php artisan key:generate --show

# If not, use any online base64 generator to create a random 32-byte base64 string
# Format: base64:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

### 3.2 ADMET Space: `ailixir-admet` (owner: shdwRow)

**Space settings:** https://huggingface.co/spaces/shdwRow/ailixir-admet/settings

| Secret | Value | Description |
|--------|-------|-------------|
| `PYTHONUNBUFFERED` | `1` | Python unbuffered output |
| `LOG_LEVEL` | `INFO` | Logging level |

### 3.3 Drug Repurposing Space: `ailixir-drug-repurposing`

| Secret | Value | Description |
|--------|-------|-------------|
| `HOST` | `0.0.0.0` | Bind address |
| `PORT` | `7860` | Port (must match Dockerfile) |
| `DEBUG` | `False` | Debug mode |
| `LOG_LEVEL` | `INFO` | Log level |
| `USE_MOCK_MODEL` | `False` | Use mock model (for testing) |
| `USE_MOCK_DRUGS` | `False` | Use mock drug list (for testing) |

### 3.4 Chemical RAG Space: `ailixir-chemical-rag`

| Secret | Value | Description |
|--------|-------|-------------|
| `PYTHONUNBUFFERED` | `1` | Python unbuffered output |
| `API_PORT` | `7860` | API port |
| `API_HOST` | `0.0.0.0` | Bind address |

### 3.5 Generation Space: `ailixir-generation` (owner: shdwRow)

**Space settings:** https://huggingface.co/spaces/shdwRow/ailixir-generation/settings

| Secret | Value | Description |
|--------|-------|-------------|
| `PUBLIC_BASE_URL` | `https://shdwRow-ailixir-generation.hf.space` | Public URL of the service |
| `REINVENT_DEVICE` | `cpu` | Device for REINVENT (CPU-only on HF free tier) |
| `DEEPPURPOSE_URL` | *(leave empty)* | DeepPurpose service URL (CPU-only version) |
| `ADGPU_BIN` | *(leave empty)* | AutoDock-GPU binary (not available on CPU) |

---

## 4. Setting Secrets in HF Spaces

1. Go to the Space's settings page:  
   `https://huggingface.co/spaces/RottenShadow/{space-name}/settings`

2. Scroll down to **"Repository Secrets"** section

3. Click **"New secret"**

4. Enter the key-value pair and click **"Add"**

5. The Space will automatically **rebuild** with the new secrets

---

## 5. API Endpoints

Once all spaces are running, the backend API is available at:

```
https://Ailixir-AI-Team-ailixir-api.hf.space/api
```

### Authentication
```bash
# Register
curl -X POST https://Ailixir-AI-Team-ailixir-api.hf.space/api/user/register \
  -H "Content-Type: application/json" \
  -d '{"name":"User","email":"user@example.com","password":"password123"}'

# Login
curl -X POST https://Ailixir-AI-Team-ailixir-api.hf.space/api/user/login \
  -H "Content-Type: application/json" \
  -d '{"email":"user@example.com","password":"password123"}'

# Response includes Bearer token
```

### AI Service Proxies (via Backend)
All AI endpoints are proxied through the backend:

```bash
# ADMET prediction
curl -X POST https://Ailixir-AI-Team-ailixir-api.hf.space/api/admet/predict \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"smiles": "c1ccccc1"}'

# Chemical search
curl -X POST https://Ailixir-AI-Team-ailixir-api.hf.space/api/chemical-search \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"smiles": "CC(=O)O"}'

# Health check (no auth needed)
curl https://Ailixir-AI-Team-ailixir-api.hf.space/api/ai-services/health
```

---

## 6. Auto-Sync from GitHub

The repository has **5 GitHub Actions workflows** that automatically sync code pushes to HF Spaces:

| Workflow | Triggers On | Syncs To |
|----------|-------------|----------|
| `sync-hf-all.yml` | Push to `main` | All 5 spaces (matrix job) |

### ❗ PREREQUISITE: Set `HF_TOKEN` as a GitHub Secret

For the auto-sync to work, you **must** add both HF tokens as GitHub Actions secrets:

1. Go to: https://github.com/RottenShadow/AILIXIR_BackEnd/settings/secrets/actions
2. Click **"New repository secret"**
3. **Name:** `HF_TOKEN` β€” **Value:** RottenShadow account token (for `RottenShadow` spaces)
4. **Name:** `HF_TOKEN_SHDWROW` β€” **Value:** shdwRow account token (for `shdwRow` spaces)
5. **Name:** `HF_TOKEN_AILIXIR` β€” **Value:** Ailixir-AI-Team account token (for `ailixir-api`)

Without these, the auto-sync workflows will fail with an authentication error.

---

## 7. Troubleshooting

### Space stuck at `BUILDING`
- Large Docker images can take **15–45 minutes** to build on HF free tier
- Check the build logs: Space page β†’ **"Factory"** or **"Builder"** tab
- Common issues: missing files, Dockerfile errors, out of memory

### Space shows `NO_APP_FILE`
- The Dockerfile is missing from the root of the Space repo
- Ensure `Dockerfile` exists at the root (not in a subdirectory)

### Space shows `CONFIG_ERROR`
- Missing or invalid `README.md` YAML frontmatter
- Ensure the `README.md` has the correct format:
  ```yaml
  ---
  title: Space Name
  emoji: 🧬
  colorFrom: blue
  colorTo: green
  sdk: docker
  app_port: 7860
  ---
  ```

### API returns 500 errors
- Check the Space logs: Space page β†’ **"Factory"** tab
- Verify all required environment secrets are set
- For the backend, ensure `APP_KEY` is a valid Laravel key

### Service not reachable from backend
- Verify the AI service URL in the backend's secrets is correct
- The URLs should use the format: `https://RottenShadow-{name}.hf.space` (or `https://shdwRow-{name}.hf.space` for ADMET/Generation)
- Test the AI service directly first:
  ```bash
curl https://shdwRow-ailixir-admet.hf.space/health
  ```

### Space keeps going to sleep
- Free tier spaces sleep after 15 minutes of inactivity
- Use a cron job (e.g., GitHub Actions scheduled workflow) to ping every 10 minutes
- Or upgrade to a paid hardware tier (starting at $5/month)

---

## 8. Upgrading Hardware

To upgrade a Space from CPU Basic to a paid tier:

1. Go to the Space settings
2. Under **"Hardware"**, select a tier:
   - `cpu-upgrade` β€” 4 vCPU, 16GB RAM ($5/month)
   - `cpu-basic` β€” 2 vCPU, 16GB RAM (free)
   - `t4-small` β€” NVIDIA T4 GPU ($20/month, for generation service)
3. Save β€” the Space will rebuild

**Note:** The generation service (`ailixir-generation`) can benefit from a GPU upgrade for AutoDock-GPU docking.