Spaces:
Sleeping
Sleeping
AI Software Factory
feat: Wrap Flutter apps in iPhone 15 Pro device frame for DartPad preview
d535ad0 Download agents/simple_flutter_generator.py from OneWeekApp/space-ac-design: direct link, hf CLI and curl.
- Browser
- Download file 5.32 kB
-
https://huggingface.co/spaces/OneWeekApp/space-ac-design/resolve/main/agents/simple_flutter_generator.py
- Command line
-
hf download hf://spaces/OneWeekApp/space-ac-design/agents/simple_flutter_generator.py
-
curl -L -o simple_flutter_generator.py https://huggingface.co/spaces/OneWeekApp/space-ac-design/resolve/main/agents/simple_flutter_generator.py
5.32 kB
| """ | |
| Simple Flutter Generator - Direct prompt to DeepSeek | |
| No presets, no themes, just raw AI code generation | |
| """ | |
| import os | |
| import requests | |
| from typing import Dict, Any | |
| class SimpleFlutterGenerator: | |
| """ | |
| Ultra-simple Flutter code generator | |
| Takes a prompt, calls DeepSeek, returns Flutter code | |
| """ | |
| def __init__(self): | |
| self.deepseek_api_key = os.getenv("DEEPSEEK_API_KEY", "") | |
| self.deepseek_base_url = "https://api.deepseek.com/v1/chat/completions" | |
| self.model = "deepseek-coder" | |
| def generate(self, prompt: str) -> Dict[str, Any]: | |
| """ | |
| Generate Flutter code from user prompt | |
| Args: | |
| prompt: User description (e.g., "Create a login screen with email and password") | |
| Returns: | |
| { | |
| "code": "complete Flutter/Dart code", | |
| "prompt": "original user prompt", | |
| "success": True/False, | |
| "error": "error message if failed" | |
| } | |
| """ | |
| if not self.deepseek_api_key: | |
| return { | |
| "success": False, | |
| "error": "DEEPSEEK_API_KEY not configured", | |
| "code": "", | |
| "prompt": prompt | |
| } | |
| if not prompt or not prompt.strip(): | |
| return { | |
| "success": False, | |
| "error": "Empty prompt", | |
| "code": "", | |
| "prompt": prompt | |
| } | |
| try: | |
| # Simple, direct prompt to DeepSeek | |
| system_prompt = """You are an expert Flutter/Dart developer. | |
| Generate complete, runnable Flutter code that can be pasted directly into DartPad. | |
| REQUIREMENTS: | |
| 1. Complete code with imports, main(), MaterialApp, and all widgets | |
| 2. Use Material 3 design (useMaterial3: true) | |
| 3. Include realistic mock data | |
| 4. Make it visually appealing with proper colors, spacing, shadows | |
| 5. Code must be between 200-1000 lines | |
| 6. No external packages - only flutter/material.dart | |
| 7. Format code properly with indentation | |
| IMPORTANT - IPHONE DEVICE FRAME: | |
| 8. Wrap the entire app in an iPhone device frame with these exact specifications: | |
| - Use a Container with width: 393, height: 852 (iPhone 15 Pro dimensions) | |
| - Add rounded corners (borderRadius: 50) | |
| - Add a subtle shadow and border to simulate device frame | |
| - Center the container on a light gray background | |
| - The user's requested app should render INSIDE this frame | |
| Example structure: | |
| ```dart | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| backgroundColor: Color(0xFFE5E5E5), | |
| body: Center( | |
| child: Container( | |
| width: 393, | |
| height: 852, | |
| decoration: BoxDecoration( | |
| color: Colors.black, | |
| borderRadius: BorderRadius.circular(50), | |
| boxShadow: [ | |
| BoxShadow( | |
| color: Colors.black26, | |
| blurRadius: 30, | |
| spreadRadius: 5, | |
| ) | |
| ], | |
| ), | |
| clipBehavior: Clip.antiAlias, | |
| child: MaterialApp( | |
| // User's actual app goes here | |
| home: [USER_REQUESTED_WIDGET], | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| ``` | |
| Output ONLY the Dart code, no explanations.""" | |
| user_message = f"Generate Flutter code for: {prompt}" | |
| print(f"📝 Prompt: {prompt}") | |
| print(f"🤖 Calling DeepSeek API...") | |
| headers = { | |
| "Authorization": f"Bearer {self.deepseek_api_key}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "model": self.model, | |
| "messages": [ | |
| {"role": "system", "content": system_prompt}, | |
| {"role": "user", "content": user_message} | |
| ], | |
| "max_tokens": 4000, # Enough for ~1000 lines of code | |
| "temperature": 0.7 | |
| } | |
| response = requests.post( | |
| self.deepseek_base_url, | |
| headers=headers, | |
| json=payload, | |
| timeout=60 | |
| ) | |
| response.raise_for_status() | |
| result = response.json() | |
| generated_code = result["choices"][0]["message"]["content"] | |
| # Clean up code (remove markdown fences if present) | |
| if "```dart" in generated_code: | |
| generated_code = generated_code.split("```dart")[1].split("```")[0].strip() | |
| elif "```" in generated_code: | |
| generated_code = generated_code.split("```")[1].split("```")[0].strip() | |
| print(f"✅ Generated {len(generated_code)} characters of code") | |
| return { | |
| "success": True, | |
| "code": generated_code, | |
| "prompt": prompt, | |
| "error": None, | |
| "lines": len(generated_code.split('\n')) | |
| } | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| return { | |
| "success": False, | |
| "error": str(e), | |
| "code": "", | |
| "prompt": prompt | |
| } | |