File size: 6,396 Bytes
6bc56a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# HuggingFace Spaces Configuration Guide

## Overview

HuggingFace Spaces are configured using **YAML frontmatter** at the top of your `README.md` file. This guide explains how to configure your Writing Studio Space.

## Current Configuration

The `README_HF_SPACES.md` file includes this configuration:

```yaml
---
title: AI Writing Studio
emoji: ✍️
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
pinned: false
license: mit
short_description: Production-grade AI writing assistant with real rubric scoring
tags:
  - education
  - writing
  - nlp
  - text-generation
  - analysis
suggested_hardware: cpu-basic
suggested_storage: small
---
```

## Configuration Parameters Explained

### Display Settings

**title**: `AI Writing Studio`
- The name shown in your Space

**emoji**: `✍️`
- Icon displayed with your Space

**colorFrom** / **colorTo**: `blue` → `purple`
- Gradient colors for thumbnail
- Options: red, yellow, green, blue, indigo, purple, pink, gray

**short_description**: Brief description for Space thumbnail

### SDK Configuration

**sdk**: `gradio`
- Must be `gradio` for this app
- Other options: `docker`, `static`

**sdk_version**: `4.0.0`
- Gradio version to use
- Can specify any Gradio version

**app_file**: `app.py`
- Entry point file (relative to repository root)

### Hardware Recommendations

**suggested_hardware**: `cpu-basic`
- Recommended tier for duplicators
- Does NOT automatically assign hardware
- Options:
  - CPU: `cpu-basic`, `cpu-upgrade`
  - GPU: `t4-small`, `t4-medium`, `l4x1`, `l4x4`, `a10g-small`, `a10g-large`, etc.
  - TPU: `v5e-1x1`, `v5e-2x2`, `v5e-2x4`

**suggested_storage**: `small`
- Recommended persistent storage
- Does NOT automatically assign storage
- Options: `small`, `medium`, `large`

### Metadata

**pinned**: `false`
- Whether Space stays on top of your profile

**license**: `mit`
- Software license

**tags**: List of descriptive tags
- `education`, `writing`, `nlp`, `text-generation`, `analysis`
- Helps with discoverability

## Hardware Tiers

### Free Tier (cpu-basic)
- Default for all Spaces
- 2 CPU cores
- 16GB RAM
- Works with distilgpt2
- **Recommended for Writing Studio**

### Paid Tiers

**cpu-upgrade** (~$0.10/hour)
- 4 CPU cores
- 32GB RAM
- Better for gpt2

**t4-small** (~$0.60/hour)
- NVIDIA T4 GPU
- 16GB GPU RAM
- Best performance
- Good for gpt2-medium/large

**Higher tiers available** for more demanding workloads

## Customizing Your Space

### Method 1: Edit YAML Frontmatter

1. Open your Space on HuggingFace
2. Click "Files" tab
3. Edit `README.md`
4. Modify YAML frontmatter
5. Commit changes

Example customizations:

```yaml
---
# Change display
title: My Custom Writing Studio
emoji: 📝
colorFrom: green
colorTo: blue

# Upgrade hardware suggestion
suggested_hardware: t4-small

# Pin to profile
pinned: true
---
```

### Method 2: Environment Variables

For application settings (not Space config), use Settings → Variables:

```
DEFAULT_MODEL=gpt2
MAX_TEXT_LENGTH=5000
LOG_LEVEL=DEBUG
ENABLE_CACHE=true
```

## Common Configurations

### Free Tier Optimized (Default)

```yaml
---
sdk: gradio
sdk_version: 4.0.0
suggested_hardware: cpu-basic
suggested_storage: small
---
```

With environment variables:
```
DEFAULT_MODEL=distilgpt2
ENABLE_CACHE=true
```

### GPU Accelerated

```yaml
---
sdk: gradio
sdk_version: 4.0.0
suggested_hardware: t4-small
suggested_storage: medium
---
```

With environment variables:
```
DEFAULT_MODEL=gpt2-medium
ENABLE_CACHE=true
CACHE_MAX_SIZE=200
```

### High Performance

```yaml
---
sdk: gradio
sdk_version: 4.0.0
suggested_hardware: a10g-small
suggested_storage: large
---
```

With environment variables:
```
DEFAULT_MODEL=gpt2-large
ENABLE_CACHE=true
CACHE_MAX_SIZE=500
```

## Advanced Options

### Full-Width Display

```yaml
---
fullWidth: true
---
```

### Mini Header

```yaml
---
header: mini
---
```

### Custom Models/Datasets

```yaml
---
models:
  - distilgpt2
  - gpt2
datasets:
  - your-dataset-name
---
```

### OAuth Integration

```yaml
---
hf_oauth: true
hf_oauth_scopes:
  - read-repos
  - write-repos
hf_oauth_expiration_minutes: 480
---
```

### Disable Embedding

```yaml
---
disable_embedding: true
---
```

## Environment Variables Reference

These go in Space Settings → Variables, NOT in YAML:

| Variable | Default | Description |
|----------|---------|-------------|
| `ENVIRONMENT` | `production` | Runtime environment |
| `DEBUG` | `false` | Debug mode |
| `LOG_LEVEL` | `INFO` | Logging level |
| `DEFAULT_MODEL` | `distilgpt2` | HuggingFace model ID |
| `MAX_TEXT_LENGTH` | `10000` | Max input characters |
| `ENABLE_CACHE` | `true` | Enable result caching |
| `CACHE_MAX_SIZE` | `100` | Cache entry limit |
| `ENABLE_METRICS` | `false` | Prometheus metrics |
| `LOG_FORMAT` | `text` | Log format (json/text) |

## Troubleshooting

### Configuration Not Applied

1. Check YAML syntax (spaces matter!)
2. Ensure YAML is at top of README.md
3. Must be between `---` delimiters
4. Commit changes and wait for rebuild

### Hardware Not Changed

- `suggested_hardware` is only a suggestion
- Doesn't automatically assign hardware
- Users must manually select tier in Settings
- Useful for Spaces meant to be duplicated

### Environment Variables Not Working

- Set in Settings → Variables (not in YAML)
- May need to restart Space
- Check logs for confirmation

## Best Practices

1. **Start with defaults** - They work well for most cases
2. **Test locally first** - `python app.py`
3. **Use free tier initially** - Upgrade only if needed
4. **Set suggested_hardware** - Helps duplicators
5. **Add descriptive tags** - Improves discoverability
6. **Write good short_description** - Shows in thumbnail
7. **Keep emoji relevant** - Helps users identify your Space

## Resources

- [Official Spaces Config Docs](https://huggingface.co/docs/hub/spaces-config-reference)
- [Gradio Spaces Guide](https://huggingface.co/docs/hub/spaces-sdks-gradio)
- [Hardware Pricing](https://huggingface.co/pricing#spaces)

## Quick Reference

**Minimal Configuration:**
```yaml
---
title: AI Writing Studio
sdk: gradio
app_file: app.py
---
```

**Recommended Configuration:**
```yaml
---
title: AI Writing Studio
emoji: ✍️
sdk: gradio
sdk_version: 4.0.0
app_file: app.py
suggested_hardware: cpu-basic
license: mit
---
```

**Full Configuration:**
See `README_HF_SPACES.md` for complete example.