Claude commited on
Commit
71f2499
Β·
1 Parent(s): 6dff68d

Add Simple Flutter Generator: direct prompt to DeepSeek, no presets

Browse files
Files changed (2) hide show
  1. agents/simple_flutter_generator.py +125 -0
  2. app.py +105 -0
agents/simple_flutter_generator.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Simple Flutter Generator - Direct prompt to DeepSeek
3
+ No presets, no themes, just raw AI code generation
4
+ """
5
+
6
+ import os
7
+ import requests
8
+ from typing import Dict, Any
9
+
10
+
11
+ class SimpleFlutterGenerator:
12
+ """
13
+ Ultra-simple Flutter code generator
14
+ Takes a prompt, calls DeepSeek, returns Flutter code
15
+ """
16
+
17
+ def __init__(self):
18
+ self.deepseek_api_key = os.getenv("DEEPSEEK_API_KEY", "")
19
+ self.deepseek_base_url = "https://api.deepseek.com/v1/chat/completions"
20
+ self.model = "deepseek-coder"
21
+
22
+ def generate(self, prompt: str) -> Dict[str, Any]:
23
+ """
24
+ Generate Flutter code from user prompt
25
+
26
+ Args:
27
+ prompt: User description (e.g., "Create a login screen with email and password")
28
+
29
+ Returns:
30
+ {
31
+ "code": "complete Flutter/Dart code",
32
+ "prompt": "original user prompt",
33
+ "success": True/False,
34
+ "error": "error message if failed"
35
+ }
36
+ """
37
+
38
+ if not self.deepseek_api_key:
39
+ return {
40
+ "success": False,
41
+ "error": "DEEPSEEK_API_KEY not configured",
42
+ "code": "",
43
+ "prompt": prompt
44
+ }
45
+
46
+ if not prompt or not prompt.strip():
47
+ return {
48
+ "success": False,
49
+ "error": "Empty prompt",
50
+ "code": "",
51
+ "prompt": prompt
52
+ }
53
+
54
+ try:
55
+ # Simple, direct prompt to DeepSeek
56
+ system_prompt = """You are an expert Flutter/Dart developer.
57
+ Generate complete, runnable Flutter code that can be pasted directly into DartPad.
58
+
59
+ REQUIREMENTS:
60
+ 1. Complete code with imports, main(), MaterialApp, and all widgets
61
+ 2. Use Material 3 design (useMaterial3: true)
62
+ 3. Include realistic mock data
63
+ 4. Make it visually appealing with proper colors, spacing, shadows
64
+ 5. Code must be between 200-1000 lines
65
+ 6. No external packages - only flutter/material.dart
66
+ 7. Format code properly with indentation
67
+
68
+ Output ONLY the Dart code, no explanations."""
69
+
70
+ user_message = f"Generate Flutter code for: {prompt}"
71
+
72
+ print(f"πŸ“ Prompt: {prompt}")
73
+ print(f"πŸ€– Calling DeepSeek API...")
74
+
75
+ headers = {
76
+ "Authorization": f"Bearer {self.deepseek_api_key}",
77
+ "Content-Type": "application/json"
78
+ }
79
+
80
+ payload = {
81
+ "model": self.model,
82
+ "messages": [
83
+ {"role": "system", "content": system_prompt},
84
+ {"role": "user", "content": user_message}
85
+ ],
86
+ "max_tokens": 4000, # Enough for ~1000 lines of code
87
+ "temperature": 0.7
88
+ }
89
+
90
+ response = requests.post(
91
+ self.deepseek_base_url,
92
+ headers=headers,
93
+ json=payload,
94
+ timeout=60
95
+ )
96
+
97
+ response.raise_for_status()
98
+ result = response.json()
99
+
100
+ generated_code = result["choices"][0]["message"]["content"]
101
+
102
+ # Clean up code (remove markdown fences if present)
103
+ if "```dart" in generated_code:
104
+ generated_code = generated_code.split("```dart")[1].split("```")[0].strip()
105
+ elif "```" in generated_code:
106
+ generated_code = generated_code.split("```")[1].split("```")[0].strip()
107
+
108
+ print(f"βœ… Generated {len(generated_code)} characters of code")
109
+
110
+ return {
111
+ "success": True,
112
+ "code": generated_code,
113
+ "prompt": prompt,
114
+ "error": None,
115
+ "lines": len(generated_code.split('\n'))
116
+ }
117
+
118
+ except Exception as e:
119
+ print(f"❌ Error: {e}")
120
+ return {
121
+ "success": False,
122
+ "error": str(e),
123
+ "code": "",
124
+ "prompt": prompt
125
+ }
app.py CHANGED
@@ -8,6 +8,7 @@ from fastapi import FastAPI
8
  from agents.moodboard_analyzer import MoodboardAnalyzer
9
  from agents.design_variation_generator import DesignVariationGenerator
10
  from agents.flutter_screen_generator import FlutterScreenGenerator
 
11
  import json
12
  import os
13
  from dotenv import load_dotenv
@@ -19,6 +20,7 @@ load_dotenv()
19
  moodboard_analyzer = MoodboardAnalyzer()
20
  design_variation_generator = DesignVariationGenerator()
21
  flutter_screen_generator = FlutterScreenGenerator()
 
22
 
23
  # FastAPI app for orchestrator
24
  app = FastAPI(
@@ -771,6 +773,35 @@ def generate_design_themes(
771
  )
772
 
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  def generate_flutter_screens(
775
  theme_json: str,
776
  app_type: str,
@@ -4199,6 +4230,80 @@ with gr.Blocks(
4199
 
4200
  with gr.Tabs():
4201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4202
  # Tab 1: Moodboard Analyzer
4203
  with gr.Tab("πŸ–ΌοΈ AC1: Moodboard Analyzer"):
4204
  gr.Markdown("""
 
8
  from agents.moodboard_analyzer import MoodboardAnalyzer
9
  from agents.design_variation_generator import DesignVariationGenerator
10
  from agents.flutter_screen_generator import FlutterScreenGenerator
11
+ from agents.simple_flutter_generator import SimpleFlutterGenerator
12
  import json
13
  import os
14
  from dotenv import load_dotenv
 
20
  moodboard_analyzer = MoodboardAnalyzer()
21
  design_variation_generator = DesignVariationGenerator()
22
  flutter_screen_generator = FlutterScreenGenerator()
23
+ simple_flutter_generator = SimpleFlutterGenerator()
24
 
25
  # FastAPI app for orchestrator
26
  app = FastAPI(
 
773
  )
774
 
775
 
776
+ def generate_simple_flutter(prompt: str):
777
+ """
778
+ Simple Flutter generation: prompt -> DeepSeek -> code
779
+ No themes, no presets, just pure AI generation
780
+ """
781
+ if not prompt or not prompt.strip():
782
+ return ("", "<p style='color: red;'>Please enter a prompt</p>")
783
+
784
+ result = simple_flutter_generator.generate(prompt)
785
+
786
+ if not result["success"]:
787
+ error_msg = result.get("error", "Unknown error")
788
+ return ("", f"<p style='color: red;'>❌ Error: {error_msg}</p>")
789
+
790
+ code = result["code"]
791
+ lines = result["lines"]
792
+
793
+ summary_html = f"""
794
+ <div style='padding: 20px; background: #f0f9ff; border-radius: 8px; border-left: 4px solid #3b82f6;'>
795
+ <h3 style='margin: 0 0 10px 0; color: #1e40af;'>βœ… Code Generated Successfully</h3>
796
+ <p style='margin: 5px 0;'><strong>Prompt:</strong> {prompt}</p>
797
+ <p style='margin: 5px 0;'><strong>Lines:</strong> {lines}</p>
798
+ <p style='margin: 5px 0; color: #059669;'><strong>Status:</strong> Ready to copy and paste into <a href='https://dartpad.dev' target='_blank' style='color: #2563eb;'>DartPad</a></p>
799
+ </div>
800
+ """
801
+
802
+ return (code, summary_html)
803
+
804
+
805
  def generate_flutter_screens(
806
  theme_json: str,
807
  app_type: str,
 
4230
 
4231
  with gr.Tabs():
4232
 
4233
+ # Tab 0: Simple Flutter Generator (NEW!)
4234
+ with gr.Tab("⚑ Simple Generator"):
4235
+ gr.Markdown("""
4236
+ # ⚑ Simple Flutter Generator
4237
+
4238
+ **Prompt β†’ DeepSeek β†’ Flutter Code**
4239
+
4240
+ Niente preset, niente theme, niente complicazioni.
4241
+ Scrivi cosa vuoi, l'AI genera il codice Flutter completo.
4242
+ """)
4243
+
4244
+ with gr.Row():
4245
+ with gr.Column(scale=1):
4246
+ simple_prompt = gr.Textbox(
4247
+ label="πŸ“ Cosa vuoi generare?",
4248
+ placeholder="Esempio:\n- Crea una schermata di login con email e password\n- Genera una home page per app fitness con statistiche\n- Fai una todo list app con checkbox e delete button",
4249
+ lines=5,
4250
+ value="Crea una schermata di login moderna con email, password e bottone login"
4251
+ )
4252
+
4253
+ generate_simple_btn = gr.Button(
4254
+ "πŸš€ Genera Codice Flutter",
4255
+ variant="primary",
4256
+ size="lg"
4257
+ )
4258
+
4259
+ # Results
4260
+ gr.Markdown("### πŸ“± Codice Generato")
4261
+
4262
+ simple_summary = gr.HTML(
4263
+ value="<p style='text-align: center; color: #999; padding: 20px;'>Clicca 'Genera Codice Flutter' per iniziare...</p>"
4264
+ )
4265
+
4266
+ simple_code_output = gr.Code(
4267
+ label="Flutter/Dart Code (copia e incolla su dartpad.dev)",
4268
+ language="javascript",
4269
+ lines=30,
4270
+ value=""
4271
+ )
4272
+
4273
+ gr.Markdown("""
4274
+ ### πŸ’‘ Come Usare
4275
+
4276
+ 1. Scrivi cosa vuoi generare nel campo sopra
4277
+ 2. Clicca "Genera Codice Flutter"
4278
+ 3. Copia il codice generato
4279
+ 4. Vai su [dartpad.dev](https://dartpad.dev)
4280
+ 5. Incolla e clicca "Run"
4281
+ 6. Vedi la tua app! πŸŽ‰
4282
+
4283
+ **L'AI genera tutto da zero** - nessun preset o template.
4284
+ Ogni generazione Γ¨ unica basata sul tuo prompt.
4285
+ """)
4286
+
4287
+ # Examples
4288
+ gr.Examples(
4289
+ examples=[
4290
+ ["Crea una schermata di login con email, password e social login buttons"],
4291
+ ["Genera una home page per app fitness con cards di statistiche giornaliere"],
4292
+ ["Fai una todo list con checkbox, testo e bottone delete per ogni item"],
4293
+ ["Crea un profilo utente con avatar, nome, bio e bottoni follow/message"],
4294
+ ["Genera una schermata settings con switch, slider e dropdown"],
4295
+ ],
4296
+ inputs=[simple_prompt],
4297
+ label="Prova questi esempi"
4298
+ )
4299
+
4300
+ # Connect button
4301
+ generate_simple_btn.click(
4302
+ fn=generate_simple_flutter,
4303
+ inputs=[simple_prompt],
4304
+ outputs=[simple_code_output, simple_summary]
4305
+ )
4306
+
4307
  # Tab 1: Moodboard Analyzer
4308
  with gr.Tab("πŸ–ΌοΈ AC1: Moodboard Analyzer"):
4309
  gr.Markdown("""