File size: 8,858 Bytes
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be2dec1
 
 
 
 
 
 
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be2dec1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be2dec1
42f73ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Space AC Design Variations
emoji: 🎨
colorFrom: purple
colorTo: pink
sdk: gradio
sdk_version: 5.49.0
app_file: app.py
pinned: false
license: mit
---

# 🎨 Space AC: Design Variations

**AI-powered design system generation for Flutter apps**

Part of the **AI Software Factory** - a complete system that generates Flutter applications from Notion wireframes to GitHub PRs.

## πŸš€ Features

This space contains specialized AI agents for design system generation:

### ⚑ Simple Generator (NEW!) βœ… LIVE
- **Zero-configuration Flutter code generation**
- Prompt β†’ DeepSeek β†’ Flutter Code β†’ DartPad (auto-loaded!)
- Automatic GitHub Gist creation for instant DartPad embedding
- No themes, no presets - just describe what you want
- Code automatically loaded in DartPad - just click "Run"!
- Collapsible code viewer for clean UI

**Example prompts:**
- "Create a modern login screen with email and password"
- "Generate a fitness app home page with statistics cards"
- "Build a todo list with checkboxes and delete buttons"

### AC1: Moodboard Analyzer πŸ–ΌοΈ βœ… LIVE
- Analyzes reference app screenshots
- Extracts color palettes with visual previews
- Identifies UI patterns and components
- Detects typography trends
- Generates actionable design insights

### AC2: Design Variation Generator 🎨 βœ… LIVE
- Generates 4 complete design theme variations
- Defines design tokens (colors, typography, spacing)
- Creates comprehensive design system specifications
- Interactive theme cards with visual preview

### AC3: Flutter Screen Generator πŸ’» βœ… LIVE
- Generates runnable Flutter/Dart code for DartPad
- AI-powered planning with Llama 3.1 70B + Jinja2 templates
- Creates 3 screens per theme with realistic components
- Supports 10 app types (fitness, banking, rider, ecommerce, social, etc.)
- 400-500 lines of production-ready Dart code per screen

### Coming Soon:
- **AC4:** Theme Comparator (pros/cons analysis and recommendations)

## 🎯 Use Cases

- **Design System Creation:** Generate complete design systems from inspiration
- **Theme Development:** Create multiple design variations quickly
- **Competitor Analysis:** Analyze design patterns from reference apps
- **Design Documentation:** Auto-generate design tokens and guidelines

## πŸ”§ API Endpoints

### POST /api/moodboard-analyzer

Analyze a moodboard to extract design insights.

**Request:**
```json
{
  "reference_images": [
    {
      "url": "https://example.com/screenshot.png",
      "description": "Instagram home feed - dark mode"
    }
  ],
  "mood_keywords": ["energetic", "gaming", "modern"]
}
```

**Response:**
```json
{
  "success": true,
  "output": {
    "analysis": {
      "color_palettes": [...],
      "typography_trends": [...],
      "ui_patterns": [...],
      "insights": "..."
    }
  }
}
```

### POST /api/design-variation-generator

Generate 4 design theme variations from moodboard analysis.

**Request:**
```json
{
  "moodboard_analysis": {
    "color_palettes": [...],
    "typography_trends": [...],
    "ui_patterns": [...]
  },
  "wireframe": "E-commerce app with product grid and checkout",
  "app_context": {
    "type": "mobile_app"
  }
}
```

**Response:**
```json
{
  "success": true,
  "output": {
    "themes": [
      {
        "name": "Bold Energy",
        "style": "bold",
        "palette": {...},
        "typography": {...},
        "spacing": {...},
        "component_style": {...},
        "animations": {...}
      }
    ]
  }
}
```

### POST /api/flutter-screen-generator

Generate Flutter/Dart code from design themes (AC3).

**Request:**
```json
{
  "theme": {
    "name": "Bold Energy",
    "palette": {...},
    "typography": {...},
    "spacing": {...}
  },
  "app_type": "fitness",
  "screens": ["home", "profile", "settings"]
}
```

**Response:**
```json
{
  "success": true,
  "output": {
    "screens": [
      {
        "name": "home",
        "code": "import 'package:flutter/material.dart';\n\n// Full Dart code...",
        "lines": 487,
        "components": ["StatsCard", "HeroBanner"],
        "status": "generated"
      }
    ],
    "theme_name": "Bold Energy",
    "app_type": "fitness",
    "total_lines": 1420
  }
}
```

**Note:** Requires `HF_TOKEN` environment variable for Llama 3.1 access.

## πŸ”‘ Environment Variables

To enable all features, you need to configure the following environment variables:

### HuggingFace Token (Required for AC1, AC2, AC3)

All three agents use HuggingFace Inference API to access Llama models.

1. Get your token from [HuggingFace Settings](https://huggingface.co/settings/tokens)
2. Create a `.env` file in the project root:

```bash
cp .env.example .env
```

3. Add your token to `.env`:

```env
HF_TOKEN=your_huggingface_token_here
```

**On HuggingFace Spaces:**
- Go to Space Settings β†’ Variables
- Add `HF_TOKEN` as a secret

**Note:** Without the token, agents will use fallback/mock data.

### GitHub Token (Required for Simple Generator Auto-load DartPad)

The **Simple Generator** feature automatically loads generated Flutter code into DartPad by creating GitHub Gists.

**Required for:**
- ⚑ Simple Generator β†’ Auto-load code in DartPad

**Setup Instructions:**

1. Create a GitHub Personal Access Token (classic):
   - Go to [GitHub Settings β†’ Tokens](https://github.com/settings/tokens)
   - Click "Generate new token (classic)"
   - Give it a name like "HF Space Gist Creator"
   - Select scopes: **`gist`** (only this scope is needed)
   - Click "Generate token"
   - **Copy the token** (you won't see it again!)

2. Add to `.env` file:

```env
GITHUB_TOKEN=ghp_yourGitHubTokenHere
```

**On HuggingFace Spaces:**
- Go to Space Settings β†’ Variables
- Add `GITHUB_TOKEN` as a **secret** (not a public variable!)

**Note:** Without this token, the Simple Generator will still work, but users will need to manually copy-paste code into DartPad instead of automatic loading.

## πŸ’» Local Development

```bash
# Clone the repository
git clone https://huggingface.co/spaces/OneWeekApp/space-ac-design
cd space-ac-design

# Install dependencies
pip install -r requirements.txt

# Configure environment variables
cp .env.example .env
# Edit .env and add your HuggingFace token

# Run locally
python app.py
```

The Gradio interface will be available at `http://localhost:7860`

## 🧠 AI Models Used

- **DeepSeek Coder** - Direct Flutter code generation (Simple Generator)
- **Llama 3.2 Vision (11B)** - Image analysis (AC1)
- **Llama 3.1 (70B)** - Text generation and synthesis (AC2)
- **Llama 3.1 (70B)** - Flutter code planning (AC3)
- **Jinja2 Templates** - Dart code generation (AC3)

## πŸ“Š Example Usage

### Python

```python
import requests

response = requests.post(
    "https://OneWeekApp-space-ac-design.hf.space/api/moodboard-analyzer",
    json={
        "reference_images": [
            {"description": "Instagram dark mode", "url": ""}
        ],
        "mood_keywords": ["energetic", "gaming"]
    }
)

result = response.json()
palettes = result["output"]["analysis"]["color_palettes"]
print(palettes)
```

### cURL

```bash
curl -X POST https://OneWeekApp-space-ac-design.hf.space/api/moodboard-analyzer \
  -H "Content-Type: application/json" \
  -d '{
    "reference_images": [{"description": "Uber driver app", "url": ""}],
    "mood_keywords": ["professional", "modern"]
  }'
```

## πŸ—οΈ Architecture

This space is part of the **AI Software Factory** system:

```
Notion Wireframe
    ↓
Space AC (Design) ← You are here
    ↓
Space A (Architecture)
    ↓
Space B (Code Generation)
    ↓
Spaces C-N (Testing, DB, Platform, etc.)
    ↓
GitHub PR with complete Flutter app
```

## πŸ“ Input Examples

### Gaming/Energetic Theme
```
Reference Images:
- PUBG Mobile home screen - dark mode, neon accents
- Fortnite battle pass - vibrant colors, bold typography
- Uber driver stats - clean cards, green highlights

Mood: gaming, energetic, bold
```

### Professional Theme
```
Reference Images:
- LinkedIn feed - white cards, blue accents
- Banking app - clean layout, trust signals
- Notion workspace - minimal, organized

Mood: professional, trustworthy, modern
```

## πŸ”— Related Spaces

Part of the **AI Software Factory** ecosystem:

- **space-a-architecture** - System architecture design
- **space-b-codegen** - Flutter code generation
- **space-c-testing-white** - Unit & widget tests
- **space-d-testing-black** - E2E tests
- **space-e-database** - Database & backend

## πŸ“„ License

MIT License

## 🀝 Contributing

This space is part of a research project. Contributions welcome!

## πŸ“§ Contact

- **GitHub:** [AI Software Factory](https://github.com/sabatino81/AISoftwareFactory)
- **Space:** [OneWeekApp/space-ac-design](https://huggingface.co/spaces/OneWeekApp/space-ac-design)

---

**Built with ❀️ using Gradio, FastAPI, and HuggingFace Inference API**