JanadaSroor commited on
Commit
1f671ba
Β·
1 Parent(s): 36d9438

Demo version

Browse files
Files changed (1) hide show
  1. app.py +791 -4
app.py CHANGED
@@ -1,7 +1,794 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import zipfile
3
+ import io
4
+ import os
5
+ from datetime import datetime
6
 
7
+ def generate_flutter_code(description):
8
+ """
9
+ Generate Flutter code files based on user description.
10
+ This is a placeholder implementation that creates sample Dart files.
11
+ In production, this would call an AI model (Claude, GPT, etc.) via API.
12
+
13
+ Args:
14
+ description: User's description of the Flutter app/widget
15
+
16
+ Returns:
17
+ Path to generated ZIP file or None if error
18
+ """
19
+
20
+ if not description or len(description.strip()) < 10:
21
+ return None, "❌ Please provide a more detailed description (at least 10 characters)."
22
+
23
+ try:
24
+ # Create timestamp for unique filenames
25
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
26
+
27
+ # Create an in-memory ZIP file
28
+ zip_buffer = io.BytesIO()
29
+
30
+ with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
31
+
32
+ # Generate main.dart
33
+ main_dart = generate_main_dart(description)
34
+ zip_file.writestr('flutter_app/lib/main.dart', main_dart)
35
+
36
+ # Generate widgets.dart
37
+ widgets_dart = generate_widgets_dart(description)
38
+ zip_file.writestr('flutter_app/lib/widgets.dart', widgets_dart)
39
+
40
+ # Generate models.dart
41
+ models_dart = generate_models_dart(description)
42
+ zip_file.writestr('flutter_app/lib/models.dart', models_dart)
43
+
44
+ # Generate services.dart
45
+ services_dart = generate_services_dart(description)
46
+ zip_file.writestr('flutter_app/lib/services.dart', services_dart)
47
+
48
+ # Generate pubspec.yaml
49
+ pubspec = generate_pubspec(description)
50
+ zip_file.writestr('flutter_app/pubspec.yaml', pubspec)
51
+
52
+ # Generate README.md
53
+ readme = generate_readme(description)
54
+ zip_file.writestr('flutter_app/README.md', readme)
55
+
56
+ # Save the ZIP to a temporary file
57
+ zip_buffer.seek(0)
58
+ output_path = f"flutter_app_{timestamp}.zip"
59
+
60
+ with open(output_path, 'wb') as f:
61
+ f.write(zip_buffer.getvalue())
62
+
63
+ success_message = f"""
64
+ βœ… **Flutter code generated successfully!**
65
 
66
+ πŸ“ **Your description:** {description[:100]}{'...' if len(description) > 100 else ''}
67
+
68
+ πŸ“¦ **Generated files:**
69
+ - `lib/main.dart` - Main application entry point
70
+ - `lib/widgets.dart` - Custom widgets
71
+ - `lib/models.dart` - Data models
72
+ - `lib/services.dart` - Business logic and services
73
+ - `pubspec.yaml` - Project dependencies
74
+ - `README.md` - Project documentation
75
+
76
+ πŸ’‘ **Next steps:**
77
+ 1. Download the ZIP file below
78
+ 2. Extract it to your desired location
79
+ 3. Run `flutter pub get` in the project directory
80
+ 4. Run `flutter run` to launch the app
81
+
82
+ ⚠️ **Note:** This is AI-generated placeholder code. Review and customize it for your needs.
83
+ """
84
+
85
+ return output_path, success_message
86
+
87
+ except Exception as e:
88
+ return None, f"❌ Error generating Flutter code: {str(e)}"
89
+
90
+
91
+ def generate_main_dart(description):
92
+ """Generate the main.dart file content."""
93
+ return f"""// AI-Generated Flutter Application
94
+ // Description: {description}
95
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
96
+
97
+ import 'package:flutter/material.dart';
98
+ import 'widgets.dart';
99
+
100
+ void main() {{
101
+ runApp(const MyApp());
102
+ }}
103
+
104
+ /// Main application widget
105
+ /// This is the root of your Flutter application
106
+ class MyApp extends StatelessWidget {{
107
+ const MyApp({{super.key}});
108
+
109
+ @override
110
+ Widget build(BuildContext context) {{
111
+ return MaterialApp(
112
+ title: 'Flutter App',
113
+ debugShowCheckedModeBanner: false,
114
+ theme: ThemeData(
115
+ colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
116
+ useMaterial3: true,
117
+ appBarTheme: const AppBarTheme(
118
+ centerTitle: true,
119
+ elevation: 2,
120
+ ),
121
+ ),
122
+ home: const HomePage(),
123
+ );
124
+ }}
125
+ }}
126
+
127
+ /// Home page widget
128
+ /// Main screen of the application
129
+ class HomePage extends StatefulWidget {{
130
+ const HomePage({{super.key}});
131
+
132
+ @override
133
+ State<HomePage> createState() => _HomePageState();
134
+ }}
135
+
136
+ class _HomePageState extends State<HomePage> {{
137
+ int _counter = 0;
138
+
139
+ void _incrementCounter() {{
140
+ setState(() {{
141
+ _counter++;
142
+ }});
143
+ }}
144
+
145
+ @override
146
+ Widget build(BuildContext context) {{
147
+ return Scaffold(
148
+ appBar: AppBar(
149
+ backgroundColor: Theme.of(context).colorScheme.inversePrimary,
150
+ title: const Text('Flutter App'),
151
+ ),
152
+ body: Center(
153
+ child: Column(
154
+ mainAxisAlignment: MainAxisAlignment.center,
155
+ children: <Widget>[
156
+ // Custom widget from widgets.dart
157
+ const CustomInfoCard(
158
+ title: 'Welcome',
159
+ description: '{description[:50]}...',
160
+ ),
161
+ const SizedBox(height: 24),
162
+ const Text(
163
+ 'You have pushed the button this many times:',
164
+ style: TextStyle(fontSize: 16),
165
+ ),
166
+ Text(
167
+ '$_counter',
168
+ style: Theme.of(context).textTheme.headlineMedium?.copyWith(
169
+ fontWeight: FontWeight.bold,
170
+ color: Theme.of(context).colorScheme.primary,
171
+ ),
172
+ ),
173
+ ],
174
+ ),
175
+ ),
176
+ floatingActionButton: FloatingActionButton(
177
+ onPressed: _incrementCounter,
178
+ tooltip: 'Increment',
179
+ child: const Icon(Icons.add),
180
+ ),
181
+ );
182
+ }}
183
+ }}
184
+ """
185
+
186
+
187
+ def generate_widgets_dart(description):
188
+ """Generate the widgets.dart file content."""
189
+ return f"""// Custom Widgets for the Flutter Application
190
+ // Description: {description}
191
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
192
+
193
+ import 'package:flutter/material.dart';
194
+
195
+ /// Custom info card widget
196
+ /// Displays a title and description in a styled card
197
+ class CustomInfoCard extends StatelessWidget {{
198
+ final String title;
199
+ final String description;
200
+ final IconData? icon;
201
+
202
+ const CustomInfoCard({{
203
+ super.key,
204
+ required this.title,
205
+ required this.description,
206
+ this.icon,
207
+ }});
208
+
209
+ @override
210
+ Widget build(BuildContext context) {{
211
+ return Card(
212
+ elevation: 4,
213
+ margin: const EdgeInsets.all(16),
214
+ child: Padding(
215
+ padding: const EdgeInsets.all(20),
216
+ child: Column(
217
+ mainAxisSize: MainAxisSize.min,
218
+ children: [
219
+ if (icon != null)
220
+ Icon(
221
+ icon,
222
+ size: 48,
223
+ color: Theme.of(context).colorScheme.primary,
224
+ ),
225
+ if (icon != null) const SizedBox(height: 12),
226
+ Text(
227
+ title,
228
+ style: Theme.of(context).textTheme.headlineSmall?.copyWith(
229
+ fontWeight: FontWeight.bold,
230
+ ),
231
+ textAlign: TextAlign.center,
232
+ ),
233
+ const SizedBox(height: 8),
234
+ Text(
235
+ description,
236
+ style: Theme.of(context).textTheme.bodyMedium,
237
+ textAlign: TextAlign.center,
238
+ ),
239
+ ],
240
+ ),
241
+ ),
242
+ );
243
+ }}
244
+ }}
245
+
246
+ /// Custom button widget with loading state
247
+ class CustomButton extends StatelessWidget {{
248
+ final String text;
249
+ final VoidCallback? onPressed;
250
+ final bool isLoading;
251
+ final IconData? icon;
252
+
253
+ const CustomButton({{
254
+ super.key,
255
+ required this.text,
256
+ this.onPressed,
257
+ this.isLoading = false,
258
+ this.icon,
259
+ }});
260
+
261
+ @override
262
+ Widget build(BuildContext context) {{
263
+ return ElevatedButton(
264
+ onPressed: isLoading ? null : onPressed,
265
+ style: ElevatedButton.styleFrom(
266
+ padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
267
+ shape: RoundedRectangleBorder(
268
+ borderRadius: BorderRadius.circular(8),
269
+ ),
270
+ ),
271
+ child: isLoading
272
+ ? const SizedBox(
273
+ width: 20,
274
+ height: 20,
275
+ child: CircularProgressIndicator(strokeWidth: 2),
276
+ )
277
+ : Row(
278
+ mainAxisSize: MainAxisSize.min,
279
+ children: [
280
+ if (icon != null) ...[
281
+ Icon(icon, size: 20),
282
+ const SizedBox(width: 8),
283
+ ],
284
+ Text(text),
285
+ ],
286
+ ),
287
+ );
288
+ }}
289
+ }}
290
+
291
+ /// Custom text input field widget
292
+ class CustomTextField extends StatelessWidget {{
293
+ final String label;
294
+ final String? hint;
295
+ final TextEditingController? controller;
296
+ final int maxLines;
297
+ final TextInputType? keyboardType;
298
+
299
+ const CustomTextField({{
300
+ super.key,
301
+ required this.label,
302
+ this.hint,
303
+ this.controller,
304
+ this.maxLines = 1,
305
+ this.keyboardType,
306
+ }});
307
+
308
+ @override
309
+ Widget build(BuildContext context) {{
310
+ return TextField(
311
+ controller: controller,
312
+ maxLines: maxLines,
313
+ keyboardType: keyboardType,
314
+ decoration: InputDecoration(
315
+ labelText: label,
316
+ hintText: hint,
317
+ border: OutlineInputBorder(
318
+ borderRadius: BorderRadius.circular(8),
319
+ ),
320
+ filled: true,
321
+ fillColor: Theme.of(context).colorScheme.surface,
322
+ ),
323
+ );
324
+ }}
325
+ }}
326
+ """
327
+
328
+
329
+ def generate_models_dart(description):
330
+ """Generate the models.dart file content."""
331
+ return f"""// Data Models for the Flutter Application
332
+ // Description: {description}
333
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
334
+
335
+ /// Base item model
336
+ /// Represents a generic item in the application
337
+ class Item {{
338
+ final String id;
339
+ final String title;
340
+ final String description;
341
+ final DateTime createdAt;
342
+ bool isCompleted;
343
+
344
+ Item({{
345
+ required this.id,
346
+ required this.title,
347
+ required this.description,
348
+ required this.createdAt,
349
+ this.isCompleted = false,
350
+ }});
351
+
352
+ /// Convert item to JSON
353
+ Map<String, dynamic> toJson() {{
354
+ return {{
355
+ 'id': id,
356
+ 'title': title,
357
+ 'description': description,
358
+ 'createdAt': createdAt.toIso8601String(),
359
+ 'isCompleted': isCompleted,
360
+ }};
361
+ }}
362
+
363
+ /// Create item from JSON
364
+ factory Item.fromJson(Map<String, dynamic> json) {{
365
+ return Item(
366
+ id: json['id'] as String,
367
+ title: json['title'] as String,
368
+ description: json['description'] as String,
369
+ createdAt: DateTime.parse(json['createdAt'] as String),
370
+ isCompleted: json['isCompleted'] as bool? ?? false,
371
+ );
372
+ }}
373
+
374
+ /// Create a copy with updated fields
375
+ Item copyWith({{
376
+ String? id,
377
+ String? title,
378
+ String? description,
379
+ DateTime? createdAt,
380
+ bool? isCompleted,
381
+ }}) {{
382
+ return Item(
383
+ id: id ?? this.id,
384
+ title: title ?? this.title,
385
+ description: description ?? this.description,
386
+ createdAt: createdAt ?? this.createdAt,
387
+ isCompleted: isCompleted ?? this.isCompleted,
388
+ );
389
+ }}
390
+ }}
391
+
392
+ /// User model
393
+ /// Represents a user in the application
394
+ class User {{
395
+ final String id;
396
+ final String name;
397
+ final String email;
398
+ final String? avatarUrl;
399
+
400
+ const User({{
401
+ required this.id,
402
+ required this.name,
403
+ required this.email,
404
+ this.avatarUrl,
405
+ }});
406
+
407
+ /// Convert user to JSON
408
+ Map<String, dynamic> toJson() {{
409
+ return {{
410
+ 'id': id,
411
+ 'name': name,
412
+ 'email': email,
413
+ 'avatarUrl': avatarUrl,
414
+ }};
415
+ }}
416
+
417
+ /// Create user from JSON
418
+ factory User.fromJson(Map<String, dynamic> json) {{
419
+ return User(
420
+ id: json['id'] as String,
421
+ name: json['name'] as String,
422
+ email: json['email'] as String,
423
+ avatarUrl: json['avatarUrl'] as String?,
424
+ );
425
+ }}
426
+ }}
427
+ """
428
+
429
+
430
+ def generate_services_dart(description):
431
+ """Generate the services.dart file content."""
432
+ return f"""// Business Logic and Services
433
+ // Description: {description}
434
+ // Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
435
+
436
+ import 'models.dart';
437
+
438
+ /// Data service for managing items
439
+ /// This service handles CRUD operations for items
440
+ class ItemService {{
441
+ final List<Item> _items = [];
442
+
443
+ /// Get all items
444
+ List<Item> getAllItems() {{
445
+ return List.unmodifiable(_items);
446
+ }}
447
+
448
+ /// Add a new item
449
+ void addItem(Item item) {{
450
+ _items.add(item);
451
+ }}
452
+
453
+ /// Update an existing item
454
+ bool updateItem(String id, Item updatedItem) {{
455
+ final index = _items.indexWhere((item) => item.id == id);
456
+ if (index != -1) {{
457
+ _items[index] = updatedItem;
458
+ return true;
459
+ }}
460
+ return false;
461
+ }}
462
+
463
+ /// Delete an item
464
+ bool deleteItem(String id) {{
465
+ final index = _items.indexWhere((item) => item.id == id);
466
+ if (index != -1) {{
467
+ _items.removeAt(index);
468
+ return true;
469
+ }}
470
+ return false;
471
+ }}
472
+
473
+ /// Toggle item completion status
474
+ bool toggleItemCompletion(String id) {{
475
+ final index = _items.indexWhere((item) => item.id == id);
476
+ if (index != -1) {{
477
+ _items[index].isCompleted = !_items[index].isCompleted;
478
+ return true;
479
+ }}
480
+ return false;
481
+ }}
482
+
483
+ /// Get completed items
484
+ List<Item> getCompletedItems() {{
485
+ return _items.where((item) => item.isCompleted).toList();
486
+ }}
487
+
488
+ /// Get pending items
489
+ List<Item> getPendingItems() {{
490
+ return _items.where((item) => !item.isCompleted).toList();
491
+ }}
492
+ }}
493
+
494
+ /// Validation service
495
+ /// Provides validation utilities
496
+ class ValidationService {{
497
+ /// Validate email format
498
+ static bool isValidEmail(String email) {{
499
+ final emailRegex = RegExp(
500
+ r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{{2,}}$',
501
+ );
502
+ return emailRegex.hasMatch(email);
503
+ }}
504
+
505
+ /// Validate string is not empty
506
+ static bool isNotEmpty(String? value) {{
507
+ return value != null && value.trim().isNotEmpty;
508
+ }}
509
+
510
+ /// Validate minimum length
511
+ static bool hasMinLength(String value, int minLength) {{
512
+ return value.length >= minLength;
513
+ }}
514
+ }}
515
+ """
516
+
517
+
518
+ def generate_pubspec(description):
519
+ """Generate the pubspec.yaml file content."""
520
+ return f"""# Flutter Project Configuration
521
+ # Description: {description}
522
+ # Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
523
+
524
+ name: flutter_app
525
+ description: AI-generated Flutter application
526
+ publish_to: 'none'
527
+
528
+ version: 1.0.0+1
529
+
530
+ environment:
531
+ sdk: '>=3.0.0 <4.0.0'
532
+
533
+ dependencies:
534
+ flutter:
535
+ sdk: flutter
536
+
537
+ # UI Components
538
+ cupertino_icons: ^1.0.6
539
+
540
+ # State Management (uncomment as needed)
541
+ # provider: ^6.1.1
542
+ # riverpod: ^2.4.9
543
+
544
+ # Networking (uncomment as needed)
545
+ # http: ^1.1.0
546
+ # dio: ^5.4.0
547
+
548
+ # Local Storage (uncomment as needed)
549
+ # shared_preferences: ^2.2.2
550
+ # hive: ^2.2.3
551
+
552
+ dev_dependencies:
553
+ flutter_test:
554
+ sdk: flutter
555
+ flutter_lints: ^3.0.1
556
+
557
+ flutter:
558
+ uses-material-design: true
559
+
560
+ # Assets (uncomment and configure as needed)
561
+ # assets:
562
+ # - assets/images/
563
+ # - assets/icons/
564
+
565
+ # Fonts (uncomment and configure as needed)
566
+ # fonts:
567
+ # - family: CustomFont
568
+ # fonts:
569
+ # - asset: fonts/CustomFont-Regular.ttf
570
+ # - asset: fonts/CustomFont-Bold.ttf
571
+ # weight: 700
572
+ """
573
+
574
+
575
+ def generate_readme(description):
576
+ """Generate the README.md file content."""
577
+ return f"""# Flutter Application
578
+
579
+ πŸ€– **AI-Generated Flutter Project**
580
+
581
+ ## Description
582
+
583
+ {description}
584
+
585
+ ---
586
+
587
+ ## πŸ“‹ Project Structure
588
+
589
+ ```
590
+ flutter_app/
591
+ β”œβ”€β”€ lib/
592
+ β”‚ β”œβ”€β”€ main.dart # Application entry point
593
+ β”‚ β”œβ”€β”€ widgets.dart # Custom UI widgets
594
+ β”‚ β”œβ”€β”€ models.dart # Data models
595
+ β”‚ └── services.dart # Business logic and services
596
+ β”œβ”€β”€ pubspec.yaml # Project dependencies
597
+ └── README.md # This file
598
+ ```
599
+
600
+ ## πŸš€ Getting Started
601
+
602
+ ### Prerequisites
603
+
604
+ - Flutter SDK (>=3.0.0)
605
+ - Dart SDK
606
+ - IDE (VS Code, Android Studio, or IntelliJ)
607
+
608
+ ### Installation
609
+
610
+ 1. **Extract the ZIP file** to your desired location
611
+
612
+ 2. **Navigate to the project directory**
613
+ ```bash
614
+ cd flutter_app
615
+ ```
616
+
617
+ 3. **Install dependencies**
618
+ ```bash
619
+ flutter pub get
620
+ ```
621
+
622
+ 4. **Run the app**
623
+ ```bash
624
+ flutter run
625
+ ```
626
+
627
+ ## πŸ› οΈ Customization
628
+
629
+ This is a generated starter project. You may want to:
630
+
631
+ - ✏️ Modify the UI in `lib/widgets.dart`
632
+ - πŸ“Š Add more data models in `lib/models.dart`
633
+ - βš™οΈ Extend business logic in `lib/services.dart`
634
+ - πŸ“¦ Add dependencies in `pubspec.yaml`
635
+
636
+ ## πŸ“± Building for Production
637
+
638
+ ### Android
639
+ ```bash
640
+ flutter build apk --release
641
+ ```
642
+
643
+ ### iOS
644
+ ```bash
645
+ flutter build ios --release
646
+ ```
647
+
648
+ ### Web
649
+ ```bash
650
+ flutter build web --release
651
+ ```
652
+
653
+ ## πŸ§ͺ Testing
654
+
655
+ Run tests with:
656
+ ```bash
657
+ flutter test
658
+ ```
659
+
660
+ ## πŸ“š Resources
661
+
662
+ - [Flutter Documentation](https://docs.flutter.dev/)
663
+ - [Dart Documentation](https://dart.dev/guides)
664
+ - [Flutter Cookbook](https://docs.flutter.dev/cookbook)
665
+
666
+ ## ⚠️ Important Notes
667
+
668
+ - This code was AI-generated and serves as a starting point
669
+ - Review and test all code before production use
670
+ - Customize the app according to your specific requirements
671
+ - Add proper error handling and validation
672
+
673
+ ## πŸ“„ License
674
+
675
+ This project is generated for educational and development purposes.
676
+
677
+ ---
678
+
679
+ Generated on: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
680
+ """
681
+
682
+
683
+ # Create the Gradio interface
684
+ def create_interface():
685
+ """Create and configure the Gradio interface."""
686
+
687
+ with gr.Blocks(theme=gr.themes.Soft(), title="Flutter Code Generator") as demo:
688
+ gr.Markdown(
689
+ """
690
+ # πŸš€ AI Flutter Code Generator
691
+
692
+ Generate complete Flutter applications from natural language descriptions!
693
+
694
+ ### How to use:
695
+ 1. Describe the Flutter app or widget you want to build
696
+ 2. Click "Generate Flutter Code"
697
+ 3. Download the ZIP file containing your Flutter project
698
+ 4. Extract and run with `flutter pub get` then `flutter run`
699
+ """
700
+ )
701
+
702
+ with gr.Row():
703
+ with gr.Column(scale=2):
704
+ description_input = gr.Textbox(
705
+ label="Describe your Flutter app",
706
+ placeholder="Example: Create a todo list app with Material Design, featuring add/delete/edit functionality, local storage, and a clean modern UI with animations...",
707
+ lines=6,
708
+ max_lines=10
709
+ )
710
+
711
+ gr.Markdown(
712
+ """
713
+ **πŸ’‘ Tips for better results:**
714
+ - Be specific about features and functionality
715
+ - Mention UI/UX preferences (Material Design, Cupertino, etc.)
716
+ - Include details about data storage needs
717
+ - Describe any animations or interactions
718
+ """
719
+ )
720
+
721
+ generate_btn = gr.Button(
722
+ "🎨 Generate Flutter Code",
723
+ variant="primary",
724
+ size="lg"
725
+ )
726
+
727
+ with gr.Column(scale=1):
728
+ status_output = gr.Markdown(
729
+ label="Status",
730
+ value="πŸ‘‹ Ready to generate your Flutter app!"
731
+ )
732
+
733
+ file_output = gr.File(
734
+ label="πŸ“¦ Download Flutter Project",
735
+ type="filepath"
736
+ )
737
+
738
+ gr.Markdown(
739
+ """
740
+ ---
741
+
742
+ ### πŸ“ What's included in the generated ZIP:
743
+ - **main.dart** - Application entry point with basic structure
744
+ - **widgets.dart** - Reusable custom widgets
745
+ - **models.dart** - Data models and structures
746
+ - **services.dart** - Business logic and services
747
+ - **pubspec.yaml** - Flutter dependencies configuration
748
+ - **README.md** - Setup and usage instructions
749
+
750
+ ### ⚠️ Important Notes:
751
+ - This is a **placeholder implementation** for demonstration
752
+ - In production, this would integrate with an AI model API (Claude, GPT, etc.)
753
+ - Always review and test generated code before production use
754
+ - Customize the code to match your specific requirements
755
+
756
+ ### πŸ”§ Next Steps After Download:
757
+ 1. Extract the ZIP file
758
+ 2. Open terminal in the project directory
759
+ 3. Run `flutter pub get` to install dependencies
760
+ 4. Run `flutter run` to launch the app
761
+ 5. Customize and extend the generated code
762
+ """
763
+ )
764
+
765
+ # Connect the button to the generation function
766
+ generate_btn.click(
767
+ fn=generate_flutter_code,
768
+ inputs=[description_input],
769
+ outputs=[file_output, status_output]
770
+ )
771
+
772
+ # Add example buttons
773
+ gr.Examples(
774
+ examples=[
775
+ ["Create a weather app with current conditions, 5-day forecast, and location search using Material Design"],
776
+ ["Build a chat application with real-time messaging, user authentication, and a modern gradient UI"],
777
+ ["Design a fitness tracker with workout logging, progress charts, and goal setting features"],
778
+ ["Make a recipe app with search, favorites, step-by-step instructions, and shopping list generation"],
779
+ ],
780
+ inputs=[description_input],
781
+ label="πŸ“š Example Prompts"
782
+ )
783
+
784
+ return demo
785
+
786
+
787
+ # Launch the app
788
+ if __name__ == "__main__":
789
+ demo = create_interface()
790
+ demo.launch(
791
+ server_name="0.0.0.0", # Required for Hugging Face Spaces
792
+ server_port=7860, # Default port for Hugging Face Spaces
793
+ share=False
794
+ )