Spaces:
Sleeping
Sleeping
Commit
Β·
31f6748
1
Parent(s):
f9485f1
Demo version
Browse files
app.py
CHANGED
|
@@ -63,7 +63,7 @@ The code should be complete, functional, and follow Flutter best practices.
|
|
| 63 |
# Additional cleanup for common issues
|
| 64 |
code = code.replace("dart\n", "").replace("Dart\n", "")
|
| 65 |
|
| 66 |
-
return code if code else "// AI
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
print(f"Error generating code with AI: {e}")
|
|
@@ -71,19 +71,18 @@ The code should be complete, functional, and follow Flutter best practices.
|
|
| 71 |
|
| 72 |
def generate_flutter_code(description):
|
| 73 |
"""
|
| 74 |
-
Generate Flutter code files based on user description.
|
| 75 |
-
|
| 76 |
-
In production, this would call an AI model (Claude, GPT, etc.) via API.
|
| 77 |
-
|
| 78 |
Args:
|
| 79 |
description: User's description of the Flutter app/widget
|
| 80 |
-
|
| 81 |
Returns:
|
| 82 |
-
|
| 83 |
"""
|
| 84 |
|
| 85 |
if not description or len(description.strip()) < 10:
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
try:
|
| 89 |
# Create timestamp for unique filenames
|
|
@@ -126,17 +125,18 @@ def generate_flutter_code(description):
|
|
| 126 |
f.write(zip_buffer.getvalue())
|
| 127 |
|
| 128 |
success_message = f"""
|
| 129 |
-
β
**Flutter code generated successfully!**
|
| 130 |
|
|
|
|
| 131 |
π **Your description:** {description[:100]}{'...' if len(description) > 100 else ''}
|
| 132 |
|
| 133 |
π¦ **Generated files:**
|
| 134 |
- `lib/main.dart` - Main application entry point
|
| 135 |
-
- `lib/widgets.dart` - Custom widgets
|
| 136 |
-
- `lib/models.dart` - Data models
|
| 137 |
-
- `lib/services.dart` - Business logic and services
|
| 138 |
- `pubspec.yaml` - Project dependencies
|
| 139 |
-
- `README.md` -
|
| 140 |
|
| 141 |
π‘ **Next steps:**
|
| 142 |
1. Download the ZIP file below
|
|
@@ -144,13 +144,14 @@ def generate_flutter_code(description):
|
|
| 144 |
3. Run `flutter pub get` in the project directory
|
| 145 |
4. Run `flutter run` to launch the app
|
| 146 |
|
| 147 |
-
β οΈ **
|
| 148 |
"""
|
| 149 |
-
|
| 150 |
-
return output_path, success_message
|
| 151 |
|
| 152 |
except Exception as e:
|
| 153 |
-
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
def generate_main_dart(description):
|
|
@@ -714,7 +715,7 @@ def create_interface():
|
|
| 714 |
lines=6,
|
| 715 |
max_lines=10
|
| 716 |
)
|
| 717 |
-
|
| 718 |
gr.Markdown(
|
| 719 |
"""
|
| 720 |
**π‘ Tips for better results:**
|
|
@@ -724,23 +725,57 @@ def create_interface():
|
|
| 724 |
- Describe any animations or interactions
|
| 725 |
"""
|
| 726 |
)
|
| 727 |
-
|
| 728 |
generate_btn = gr.Button(
|
| 729 |
-
"π¨ Generate Flutter Code",
|
| 730 |
variant="primary",
|
| 731 |
size="lg"
|
| 732 |
)
|
| 733 |
-
|
| 734 |
with gr.Column(scale=1):
|
| 735 |
status_output = gr.Markdown(
|
| 736 |
label="Status",
|
| 737 |
value="π Ready to generate your Flutter app!"
|
| 738 |
)
|
| 739 |
-
|
| 740 |
file_output = gr.File(
|
| 741 |
label="π¦ Download Flutter Project",
|
| 742 |
type="filepath"
|
| 743 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
gr.Markdown(
|
| 746 |
"""
|
|
@@ -774,7 +809,7 @@ def create_interface():
|
|
| 774 |
generate_btn.click(
|
| 775 |
fn=generate_flutter_code,
|
| 776 |
inputs=[description_input],
|
| 777 |
-
outputs=[file_output, status_output]
|
| 778 |
)
|
| 779 |
|
| 780 |
# Add example buttons
|
|
|
|
| 63 |
# Additional cleanup for common issues
|
| 64 |
code = code.replace("dart\n", "").replace("Dart\n", "")
|
| 65 |
|
| 66 |
+
return code if code else "// Generated using Qwen 3 0.6B AI model\n// Please try rephrasing your request"
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
print(f"Error generating code with AI: {e}")
|
|
|
|
| 71 |
|
| 72 |
def generate_flutter_code(description):
|
| 73 |
"""
|
| 74 |
+
Generate Flutter code files based on user description using Qwen 3 0.6B AI model.
|
| 75 |
+
|
|
|
|
|
|
|
| 76 |
Args:
|
| 77 |
description: User's description of the Flutter app/widget
|
| 78 |
+
|
| 79 |
Returns:
|
| 80 |
+
Tuple of (file_path, status_message, main_code, widgets_code, models_code, services_code)
|
| 81 |
"""
|
| 82 |
|
| 83 |
if not description or len(description.strip()) < 10:
|
| 84 |
+
error_message = "β Please provide a more detailed description (at least 10 characters)."
|
| 85 |
+
return None, error_message, "// Waiting for description", "// Waiting for description", "// Waiting for description", "// Waiting for description"
|
| 86 |
|
| 87 |
try:
|
| 88 |
# Create timestamp for unique filenames
|
|
|
|
| 125 |
f.write(zip_buffer.getvalue())
|
| 126 |
|
| 127 |
success_message = f"""
|
| 128 |
+
β
**Flutter code generated successfully using Qwen 3 0.6B!**
|
| 129 |
|
| 130 |
+
π€ **AI Model:** Qwen 3 0.6B (specialized for code generation)
|
| 131 |
π **Your description:** {description[:100]}{'...' if len(description) > 100 else ''}
|
| 132 |
|
| 133 |
π¦ **Generated files:**
|
| 134 |
- `lib/main.dart` - Main application entry point
|
| 135 |
+
- `lib/widgets.dart` - Custom widgets with Material Design
|
| 136 |
+
- `lib/models.dart` - Data models with JSON serialization
|
| 137 |
+
- `lib/services.dart` - Business logic and validation services
|
| 138 |
- `pubspec.yaml` - Project dependencies
|
| 139 |
+
- `README.md` - Setup and usage instructions
|
| 140 |
|
| 141 |
π‘ **Next steps:**
|
| 142 |
1. Download the ZIP file below
|
|
|
|
| 144 |
3. Run `flutter pub get` in the project directory
|
| 145 |
4. Run `flutter run` to launch the app
|
| 146 |
|
| 147 |
+
β οΈ **Important:** This is AI-generated code using Qwen 3 0.6B. While high-quality, always review and test before production use.
|
| 148 |
"""
|
| 149 |
+
|
| 150 |
+
return output_path, success_message, main_dart, widgets_dart, models_dart, services_dart
|
| 151 |
|
| 152 |
except Exception as e:
|
| 153 |
+
error_message = f"β Error generating Flutter code: {str(e)}"
|
| 154 |
+
return None, error_message, "// Error occurred", "// Error occurred", "// Error occurred", "// Error occurred"
|
| 155 |
|
| 156 |
|
| 157 |
def generate_main_dart(description):
|
|
|
|
| 715 |
lines=6,
|
| 716 |
max_lines=10
|
| 717 |
)
|
| 718 |
+
|
| 719 |
gr.Markdown(
|
| 720 |
"""
|
| 721 |
**π‘ Tips for better results:**
|
|
|
|
| 725 |
- Describe any animations or interactions
|
| 726 |
"""
|
| 727 |
)
|
| 728 |
+
|
| 729 |
generate_btn = gr.Button(
|
| 730 |
+
"π¨ Generate Flutter Code with Qwen 3 0.6B",
|
| 731 |
variant="primary",
|
| 732 |
size="lg"
|
| 733 |
)
|
| 734 |
+
|
| 735 |
with gr.Column(scale=1):
|
| 736 |
status_output = gr.Markdown(
|
| 737 |
label="Status",
|
| 738 |
value="π Ready to generate your Flutter app!"
|
| 739 |
)
|
| 740 |
+
|
| 741 |
file_output = gr.File(
|
| 742 |
label="π¦ Download Flutter Project",
|
| 743 |
type="filepath"
|
| 744 |
)
|
| 745 |
+
|
| 746 |
+
# Code preview tabs
|
| 747 |
+
with gr.Tabs():
|
| 748 |
+
with gr.TabItem("π± main.dart"):
|
| 749 |
+
main_code_output = gr.Code(
|
| 750 |
+
label="Main Application Code",
|
| 751 |
+
language="dart",
|
| 752 |
+
lines=20,
|
| 753 |
+
value="// Click 'Generate Flutter Code' to see your main.dart code here"
|
| 754 |
+
)
|
| 755 |
+
|
| 756 |
+
with gr.TabItem("π¨ widgets.dart"):
|
| 757 |
+
widgets_code_output = gr.Code(
|
| 758 |
+
label="Custom Widgets Code",
|
| 759 |
+
language="dart",
|
| 760 |
+
lines=20,
|
| 761 |
+
value="// Click 'Generate Flutter Code' to see your widgets.dart code here"
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
with gr.TabItem("π models.dart"):
|
| 765 |
+
models_code_output = gr.Code(
|
| 766 |
+
label="Data Models Code",
|
| 767 |
+
language="dart",
|
| 768 |
+
lines=20,
|
| 769 |
+
value="// Click 'Generate Flutter Code' to see your models.dart code here"
|
| 770 |
+
)
|
| 771 |
+
|
| 772 |
+
with gr.TabItem("βοΈ services.dart"):
|
| 773 |
+
services_code_output = gr.Code(
|
| 774 |
+
label="Business Logic Code",
|
| 775 |
+
language="dart",
|
| 776 |
+
lines=20,
|
| 777 |
+
value="// Click 'Generate Flutter Code' to see your services.dart code here"
|
| 778 |
+
)
|
| 779 |
|
| 780 |
gr.Markdown(
|
| 781 |
"""
|
|
|
|
| 809 |
generate_btn.click(
|
| 810 |
fn=generate_flutter_code,
|
| 811 |
inputs=[description_input],
|
| 812 |
+
outputs=[file_output, status_output, main_code_output, widgets_code_output, models_code_output, services_code_output]
|
| 813 |
)
|
| 814 |
|
| 815 |
# Add example buttons
|