faizee07 commited on
Commit
f5f4bbd
Β·
verified Β·
1 Parent(s): 213f0b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +814 -814
app.py CHANGED
@@ -1,814 +1,814 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
- import os
4
- from datetime import datetime
5
-
6
- # Import all prompts and constants from prompts.py
7
- from prompts import (
8
- SEARCH_START, DIVIDER, REPLACE_END,
9
- TITLE_PAGE_START, TITLE_PAGE_END,
10
- NEW_PAGE_START, NEW_PAGE_END,
11
- UPDATE_PAGE_START, UPDATE_PAGE_END,
12
- WEB_DEV_QUESTIONS, PROMPT_FOR_IMAGE_GENERATION,
13
- INITIAL_SYSTEM_PROMPT, FOLLOW_UP_SYSTEM_PROMPT,
14
- PROMPT_ENGINEER_SYSTEM_PROMPT, SUGGESTED_ANSWERS,
15
- HTML_TEMPLATE_EXAMPLE, CDN_LINKS,
16
- AVAILABLE_MODELS, DEFAULT_MODEL
17
- )
18
-
19
- # Initialize the Hugging Face Inference Client
20
- client = InferenceClient(token=os.getenv("HF_TOKEN"))
21
-
22
- class WebsitePromptEnhancer:
23
- def __init__(self):
24
- self.context = []
25
- self.current_question_idx = 0
26
- self.user_responses = {}
27
- self.initial_prompt = ""
28
- self.is_update = False
29
-
30
- def reset(self):
31
- self.context = []
32
- self.current_question_idx = 0
33
- self.user_responses = {}
34
- self.initial_prompt = ""
35
- self.is_update = False
36
-
37
- def start_enhancement(self, initial_prompt):
38
- self.reset()
39
- self.initial_prompt = initial_prompt
40
- self.current_question_idx = 0
41
- return self.get_next_question()
42
-
43
- def get_next_question(self):
44
- if self.current_question_idx < len(WEB_DEV_QUESTIONS):
45
- return WEB_DEV_QUESTIONS[self.current_question_idx]
46
- return None
47
-
48
- def get_suggested_answer(self):
49
- """Generate suggested answer based on context"""
50
- if self.current_question_idx < len(WEB_DEV_QUESTIONS):
51
- return SUGGESTED_ANSWERS.get(self.current_question_idx, "")
52
- return ""
53
-
54
- def process_answer(self, answer):
55
- if self.current_question_idx < len(WEB_DEV_QUESTIONS):
56
- question = WEB_DEV_QUESTIONS[self.current_question_idx]
57
- self.user_responses[question] = answer
58
- self.context.append(f"Q: {question}\nA: {answer}")
59
-
60
- # Check if it's an update request
61
- if self.current_question_idx == len(WEB_DEV_QUESTIONS) - 1:
62
- if "update" in answer.lower() or "modify" in answer.lower() or "change" in answer.lower():
63
- self.is_update = True
64
-
65
- self.current_question_idx += 1
66
-
67
- next_q = self.get_next_question()
68
- return next_q
69
-
70
- def generate_enhanced_prompt(self, model_name=DEFAULT_MODEL):
71
- # Extract structured information from responses
72
- website_type = self.user_responses.get(WEB_DEV_QUESTIONS[0], "website")
73
- purpose = self.user_responses.get(WEB_DEV_QUESTIONS[1], "general purpose")
74
- audience = self.user_responses.get(WEB_DEV_QUESTIONS[2], "general audience")
75
- sections = self.user_responses.get(WEB_DEV_QUESTIONS[3], "Home, About, Contact")
76
- color_scheme = self.user_responses.get(WEB_DEV_QUESTIONS[4], "modern and professional")
77
- features = self.user_responses.get(WEB_DEV_QUESTIONS[5], "responsive design")
78
- update_type = self.user_responses.get(WEB_DEV_QUESTIONS[6], "new website")
79
-
80
- # Determine if it's an update or new website
81
- is_update = "update" in update_type.lower() or "modify" in update_type.lower()
82
-
83
- enhancement_prompt = f"""Create a detailed prompt for an AI code agent to build a professional website based on these requirements:
84
-
85
- Project: {self.initial_prompt}
86
- Type: {website_type}
87
- Purpose: {purpose}
88
- Target Audience: {audience}
89
- Required Sections/Pages: {sections}
90
- Design Theme: {color_scheme}
91
- Features: {features}
92
- Request Type: {"Update existing website" if is_update else "Create new website"}
93
-
94
- Generate a comprehensive, production-ready specification following the AI code agent format.
95
- The output should be a clean prompt (no Q&A) that includes:
96
- 1. Clear project description
97
- 2. Required pages/sections with specific details
98
- 3. Design specifications (colors, layout, typography)
99
- 4. Feature requirements with implementation details
100
- 5. Technical stack specifications (TailwindCSS, Feather Icons, AOS, Vanta.js)
101
- 6. Responsive design requirements
102
- 7. Accessibility guidelines
103
- 8. Image placeholder usage (static.photos)
104
-
105
- The prompt should be ready to paste directly into an AI code agent system."""
106
-
107
- try:
108
- messages = [
109
- {"role": "system", "content": PROMPT_ENGINEER_SYSTEM_PROMPT},
110
- {"role": "user", "content": enhancement_prompt}
111
- ]
112
-
113
- response = client.chat_completion(
114
- messages=messages,
115
- model=model_name,
116
- max_tokens=3000,
117
- temperature=0.7,
118
- stream=False
119
- )
120
-
121
- enhanced_prompt = response.choices[0].message.content
122
- return self._format_for_code_agent(enhanced_prompt, is_update)
123
-
124
- except Exception as e:
125
- try:
126
- full_prompt = f"{PROMPT_ENGINEER_SYSTEM_PROMPT}\n\n{enhancement_prompt}"
127
- response = client.text_generation(
128
- full_prompt,
129
- model=model_name,
130
- max_new_tokens=3000,
131
- temperature=0.7,
132
- return_full_text=False
133
- )
134
- return self._format_for_code_agent(response, is_update)
135
- except Exception as e2:
136
- return self._create_fallback_prompt(
137
- website_type, purpose, audience, sections,
138
- color_scheme, features, is_update
139
- )
140
-
141
- def _format_for_code_agent(self, prompt, is_update=False):
142
- """Format the prompt to work with the AI code agent system"""
143
-
144
- formatted_prompt = f"""# AI Code Agent Prompt - Website Generation
145
-
146
- {prompt}
147
-
148
- ---
149
-
150
- ## Technical Requirements for AI Code Agent
151
-
152
- ### Technology Stack
153
- - **CSS Framework:** TailwindCSS (CDN: {CDN_LINKS['tailwind']})
154
- - **Icons:** Feather Icons ({CDN_LINKS['feather_icons']})
155
- - **Scroll Animations:** AOS.js ({CDN_LINKS['aos_css']})
156
- - **Interactive Animations:** Vanta.js ({CDN_LINKS['vanta_globe']})
157
- - **Additional:** Anime.js for advanced animations
158
-
159
- ### Image Placeholders
160
- {PROMPT_FOR_IMAGE_GENERATION}
161
-
162
- ### Output Format Instructions
163
- {"**For Updates/Modifications:**" if is_update else "**For New Website:**"}
164
-
165
- {'Use the UPDATE_PAGE format:' if is_update else 'Use the TITLE_PAGE format:'}"""
166
-
167
- if is_update:
168
- formatted_prompt += f"""
169
- 1. Start with: {UPDATE_PAGE_START}
170
- 2. Specify the page name (e.g., index.html)
171
- 3. Close with: {UPDATE_PAGE_END}
172
- 4. Use SEARCH/REPLACE blocks:
173
- - {SEARCH_START}
174
- - (exact code to replace)
175
- - {DIVIDER}
176
- - (new code)
177
- - {REPLACE_END}
178
-
179
- For new pages during update:
180
- 1. Start with: {NEW_PAGE_START}
181
- 2. Specify page name (e.g., about.html)
182
- 3. Close with: {NEW_PAGE_END}
183
- 4. Provide complete HTML in ```html``` blocks
184
- 5. Update navigation links in all existing pages"""
185
- else:
186
- formatted_prompt += f"""
187
- 1. Start with: {TITLE_PAGE_START}
188
- 2. Add page name (e.g., index.html)
189
- 3. Close with: {TITLE_PAGE_END}
190
- 4. Provide complete HTML in ```html``` blocks
191
- 5. First file must be index.html
192
- 6. Include all required CDN links in <head>
193
- 7. Initialize all libraries in <body>"""
194
-
195
- formatted_prompt += f"""
196
-
197
- ### Required Code Structure
198
-
199
- **Every HTML file must include:**
200
-
201
- ```html
202
- {HTML_TEMPLATE_EXAMPLE}
203
- ```
204
-
205
- ### Design Guidelines
206
- - Mobile-first responsive design using TailwindCSS
207
- - Use semantic HTML5 elements
208
- - Implement smooth scroll animations with AOS
209
- - Add interactive animations where appropriate (Vanta.js)
210
- - Use Feather icons for all icons: <i data-feather="icon-name"></i>
211
- - Ensure accessibility (ARIA labels, semantic tags)
212
- - Cross-browser compatibility
213
- - Performance optimized
214
-
215
- ### Navigation
216
- - For multi-page websites: Use <a href="page.html"> (no onclick)
217
- - Ensure all pages have consistent navigation
218
- - Mobile-responsive hamburger menu
219
-
220
- ### Ready for AI Code Agent
221
- This prompt is formatted for direct use with AI code agents.
222
- Simply paste it into your AI coding assistant to generate the website."""
223
- return formatted_prompt
224
-
225
- def _create_fallback_prompt(self, website_type, purpose, audience, sections, color_scheme, features, is_update=False):
226
- """Create a detailed fallback prompt in code agent format"""
227
-
228
- sections_list = [s.strip() for s in sections.split(',')]
229
-
230
- fallback = f"""# AI Code Agent Prompt - Professional Website Project Overview
231
- Create a professional {website_type} website optimized for {audience}.
232
-
233
- Primary Goal: {purpose}
234
-
235
- Design Theme: {color_scheme} with modern UI/UX
236
-
237
- Required Pages/Sections
238
- """
239
- for i, section in enumerate(sections_list, 1):
240
- fallback += f"{i}. **{section.strip()}** - Complete page with relevant content\n"
241
-
242
- fallback += f"""Feature Requirements
243
- {features}
244
-
245
- Core Features:
246
- βœ… Fully responsive design (mobile, tablet, desktop)
247
- βœ… Smooth scroll animations using AOS.js
248
- βœ… Modern icons using Feather Icons
249
- βœ… Interactive animations with Vanta.js (hero section)
250
- βœ… TailwindCSS for all styling
251
- βœ… Contact forms with validation (if applicable)
252
- βœ… Image galleries with lightbox effect
253
- βœ… Smooth navigation with active states
254
- βœ… Loading animations and transitions
255
- βœ… Accessibility compliant (WCAG 2.1)
256
-
257
- ## Technology Stack
258
- ### Required Libraries (CDN)
259
- <!-- TailwindCSS -->
260
- <script src="{CDN_LINKS['tailwind']}"></script>
261
-
262
- <!-- AOS Scroll Animations -->
263
- <link href="{CDN_LINKS['aos_css']}" rel="stylesheet">
264
- <script src="{CDN_LINKS['aos_js']}"></script>
265
-
266
- <!-- Feather Icons -->
267
- <script src="{CDN_LINKS['feather_icons_min']}"></script>
268
- <script src="{CDN_LINKS['feather_icons']}"></script>
269
-
270
- <!-- Anime.js -->
271
- <script src="{CDN_LINKS['anime_js']}"></script>
272
-
273
- <!-- Vanta.js (for hero backgrounds) -->
274
- <script src="{CDN_LINKS['vanta_globe']}"></script>
275
-
276
- ## Design Specifications
277
- ### Color Scheme
278
- Primary theme: {color_scheme}
279
-
280
- Suggested TailwindCSS Colors:
281
- - Primary: bg-blue-600, text-blue-600
282
- - Secondary: bg-gray-800, text-gray-800
283
- - Accent: bg-purple-500, text-purple-500
284
- - Background: bg-white, bg-gray-50
285
- - Text: text-gray-900, text-gray-600
286
-
287
- ### Typography
288
- - Headings: Bold, large (text-4xl, text-5xl, font-bold)
289
- - Body: Readable size (text-base, text-lg)
290
- - Use TailwindCSS typography utilities
291
-
292
- ### Layout Structure
293
- - Header: Fixed/sticky navigation with logo and menu
294
- - Hero Section: Full-screen with Vanta.js background animation
295
- - Content Sections: Alternating layouts with AOS animations
296
- - Footer: Links, social media, copyright
297
-
298
- ### Responsive Breakpoints
299
- - Mobile: sm: (640px)
300
- - Tablet: md: (768px)
301
- - Desktop: lg: (1024px)
302
- - Large: xl: (1280px)
303
-
304
- ### Image Guidelines
305
- Use Static.Photos for Placeholders
306
- {PROMPT_FOR_IMAGE_GENERATION}
307
-
308
- Recommended Usage:
309
- - Hero images: http://static.photos/abstract/1200x630/1
310
- - Portfolio/Gallery: http://static.photos/technology/640x360/[1-10]
311
- - Team photos: http://static.photos/people/320x240/[1-5]
312
- - Background images: http://static.photos/minimal/1024x576/42
313
-
314
- ### Animation Requirements
315
- #### AOS Scroll Animations
316
- Use on all major sections:
317
- <div data-aos="fade-up" data-aos-duration="1000">
318
- Content here
319
- </div>
320
- Available Effects: fade-up, fade-down, fade-left, fade-right, zoom-in, flip-up
321
-
322
- #### Vanta.js Hero Background
323
- Implement on hero section:
324
- <script>
325
- VANTA.GLOBE({{
326
- el: "#hero",
327
- mouseControls: true,
328
- touchControls: true,
329
- gyroControls: false,
330
- minHeight: 200.00,
331
- minWidth: 200.00,
332
- scale: 1.00,
333
- scaleMobile: 1.00,
334
- color: 0x3b82f6,
335
- backgroundColor: 0x0f172a
336
- }})
337
- </script>
338
-
339
- #### Feather Icons Usage
340
- <i data-feather="menu"></i>
341
- <i data-feather="mail"></i>
342
- <i data-feather="phone"></i>
343
- <i data-feather="github"></i>
344
-
345
- ### Code Structure Format
346
- {"Update Format (Modifying Existing Pages)" if is_update else "New Website Format"}
347
- {"Use UPDATE_PAGE blocks:" if is_update else "Use TITLE_PAGE blocks:"}"""
348
-
349
- if is_update:
350
- fallback += f"""
351
- {UPDATE_PAGE_START}index.html{UPDATE_PAGE_END}
352
-
353
- {SEARCH_START}
354
- <h1>Old Title</h1>
355
- {DIVIDER}
356
- <h1 class="text-4xl font-bold text-blue-600">New Title</h1>
357
- {REPLACE_END}
358
-
359
- For adding new pages:
360
- {NEW_PAGE_START}about.html{NEW_PAGE_END}
361
- ```html
362
- {HTML_TEMPLATE_EXAMPLE}
363
- ```"""
364
- else:
365
- fallback += f"""
366
- {TITLE_PAGE_START}index.html{TITLE_PAGE_END}
367
- ```html
368
- {HTML_TEMPLATE_EXAMPLE}
369
- ```"""
370
-
371
- fallback += """
372
- ## Quality Standards
373
- ### Code Quality
374
- - Clean, well-commented code
375
- - Proper indentation and formatting
376
- - Semantic HTML5 elements
377
- - Modular CSS with TailwindCSS utilities
378
- - Efficient JavaScript
379
-
380
- ### Accessibility
381
- - ARIA labels on interactive elements
382
- - Alt text on all images
383
- - Proper heading hierarchy (h1-h6)
384
- - Keyboard navigation support
385
- - Sufficient color contrast
386
-
387
- ### Performance
388
- - Optimized images
389
- - Minified assets where possible
390
- - Efficient animations
391
- - Fast loading times (<3 seconds)
392
- - Mobile-optimized
393
-
394
- ### Browser Compatibility
395
- - Chrome, Firefox, Safari, Edge (latest 2 versions)
396
- - iOS Safari and Chrome Mobile
397
- - Graceful degradation for older browsers
398
-
399
- ## Deliverable
400
- Create a complete, production-ready website that:
401
- βœ… Follows all format requirements for the AI code agent
402
- βœ… Includes all specified pages/sections
403
- βœ… Uses TailwindCSS for ALL styling
404
- βœ… Implements animations (AOS, Vanta.js)
405
- βœ… Uses Feather Icons for all icons
406
- βœ… Uses static.photos for all images
407
- βœ… Is fully responsive (mobile-first)
408
- βœ… Is accessible (WCAG 2.1 AA)
409
- βœ… Has clean, professional code
410
- βœ… Is ready for immediate deployment
411
-
412
- Generate the complete website code now following the format specified above."""
413
- return fallback
414
-
415
- # Initialize enhancer
416
- enhancer = WebsitePromptEnhancer()
417
-
418
- # Gradio Interface Functions
419
- def submit_answer(answer):
420
- if not answer.strip():
421
- return (
422
- "",
423
- "",
424
- "",
425
- gr.update(interactive=False),
426
- gr.update(interactive=False),
427
- gr.update(visible=False),
428
- "⚠️ Please enter your initial website idea first!",
429
- "",
430
- gr.update(visible=False)
431
- )
432
-
433
- next_question = enhancer.process_answer(answer)
434
-
435
- if next_question:
436
- suggestion = enhancer.get_suggested_answer()
437
- return (
438
- next_question,
439
- suggestion,
440
- "",
441
- gr.update(interactive=True),
442
- gr.update(interactive=True),
443
- gr.update(visible=False),
444
- f"οΏ½οΏ½οΏ½ Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
445
- "",
446
- gr.update(visible=False)
447
- )
448
- else:
449
- return (
450
- "πŸŽ‰ All questions completed! Click 'Generate Enhanced Prompt' below.",
451
- "",
452
- "",
453
- gr.update(interactive=False),
454
- gr.update(interactive=False),
455
- gr.update(visible=True),
456
- "βœ… All questions answered! Ready to generate your AI Code Agent prompt.",
457
- "",
458
- gr.update(visible=False)
459
- )
460
-
461
- def start_process(initial_prompt):
462
- if not initial_prompt.strip():
463
- return (
464
- "",
465
- "",
466
- "",
467
- gr.update(interactive=False),
468
- gr.update(interactive=False),
469
- gr.update(visible=False),
470
- "⚠️ Please enter your initial website idea first!",
471
- "",
472
- gr.update(visible=False)
473
- )
474
-
475
- next_question = enhancer.start_enhancement(initial_prompt)
476
- suggestion = enhancer.get_suggested_answer()
477
-
478
- return (
479
- next_question,
480
- suggestion,
481
- "",
482
- gr.update(interactive=True),
483
- gr.update(interactive=True),
484
- gr.update(visible=False),
485
- f"βœ… Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
486
- "",
487
- gr.update(visible=False)
488
- )
489
-
490
- def generate_final_prompt(model_choice):
491
- try:
492
- status_msg = "πŸ”„ Generating AI Code Agent prompt... Please wait."
493
- yield "", status_msg, gr.update(visible=False)
494
- enhanced = enhancer.generate_enhanced_prompt(model_choice)
495
-
496
- yield enhanced, "βœ… AI Code Agent prompt generated! Copy and paste into your AI code agent to generate the website.", gr.update(visible=True)
497
- except Exception as e:
498
- yield f"Error: {str(e)}", "❌ Generation failed. Please try again or use a different model.", gr.update(visible=False)
499
-
500
- def save_prompt_to_file(prompt_text):
501
- """Save the prompt to a text file and return the file path"""
502
- if not prompt_text or prompt_text.strip() == "":
503
- return None
504
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
505
- filename = f"ai_code_agent_prompt_{timestamp}.txt"
506
-
507
- with open(filename, "w", encoding="utf-8") as f:
508
- f.write("=" * 80 + "\n")
509
- f.write("AI CODE AGENT - WEBSITE DEVELOPMENT PROMPT\n")
510
- f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
511
- f.write("=" * 80 + "\n\n")
512
- f.write(prompt_text)
513
- f.write("\n\n" + "=" * 80 + "\n")
514
- f.write("Paste this prompt into your AI Code Agent to generate the website\n")
515
- f.write("Compatible with: Custom AI Code Agents, Cursor, Bolt.new, v0.dev, etc.\n")
516
- f.write("=" * 80 + "\n")
517
-
518
- return filename
519
-
520
- # Custom CSS
521
- custom_css = """
522
- .container {max-width: 1200px; margin: auto; padding: 20px;}
523
- .header {
524
- text-align: center;
525
- margin-bottom: 30px;
526
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
527
- padding: 30px;
528
- border-radius: 15px;
529
- color: white;
530
- }
531
- .question-box {
532
- background: #f0f7ff;
533
- padding: 20px;
534
- border-radius: 10px;
535
- margin: 10px 0;
536
- border-left: 4px solid #667eea;
537
- }
538
- .status-box {
539
- background: #e8f5e9;
540
- padding: 15px;
541
- border-radius: 8px;
542
- margin: 10px 0;
543
- font-weight: 500;
544
- }
545
- .suggestion-box {
546
- background: #fff3e0;
547
- padding: 10px;
548
- border-radius: 5px;
549
- font-size: 0.9em;
550
- color: #e65100;
551
- }
552
- .download-btn {
553
- background: #4CAF50 !important;
554
- }
555
- .code-agent-badge {
556
- background: #667eea;
557
- color: white;
558
- padding: 5px 15px;
559
- border-radius: 20px;
560
- font-size: 0.85em;
561
- display: inline-block;
562
- margin: 5px;
563
- }
564
- """
565
-
566
- # Build Interface
567
- with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Code Agent Prompt Enhancer") as demo:
568
- gr.Markdown("""
569
- # πŸš€ AI Code Agent Prompt Enhancer
570
- ### Transform Ideas into Professional AI Code Agent Prompts
571
- Generate detailed, production-ready prompts optimized for AI code agent systems.
572
-
573
- <div style="text-align: center; margin: 10px 0;">
574
- <span class="code-agent-badge">✨ TailwindCSS</span>
575
- <span class="code-agent-badge">🎨 Feather Icons</span>
576
- <span class="code-agent-badge">πŸ“± AOS Animations</span>
577
- <span class="code-agent-badge">🌟 Vanta.js</span>
578
- <span class="code-agent-badge">πŸ–ΌοΈ Static.photos</span>
579
- </div>
580
- """, elem_classes="header")
581
-
582
- with gr.Row():
583
- with gr.Column(scale=2):
584
- initial_prompt = gr.Textbox(
585
- label="πŸ’‘ Your Website Idea",
586
- placeholder="Example: 'Create a modern portfolio website for a photographer with gallery and contact form'",
587
- lines=3,
588
- info="Describe what kind of website you want to create"
589
- )
590
- with gr.Column(scale=1):
591
- start_btn = gr.Button(
592
- "🎯 Start Enhancement",
593
- variant="primary",
594
- size="lg"
595
- )
596
-
597
- status_text = gr.Markdown("πŸ‘† Enter your idea above and click 'Start Enhancement'", elem_classes="status-box")
598
-
599
- gr.Markdown("---")
600
-
601
- with gr.Row():
602
- with gr.Column():
603
- current_question = gr.Textbox(
604
- label="❓ Current Question",
605
- interactive=False,
606
- lines=2,
607
- elem_classes="question-box"
608
- )
609
-
610
- suggestion_text = gr.Textbox(
611
- label="πŸ’­ Suggestion",
612
- interactive=False,
613
- lines=2,
614
- elem_classes="suggestion-box"
615
- )
616
-
617
- answer_input = gr.Textbox(
618
- label="✍️ Your Answer",
619
- placeholder="Type your answer here...",
620
- lines=4,
621
- interactive=False
622
- )
623
-
624
- submit_btn = gr.Button(
625
- "Submit Answer ➑️",
626
- interactive=False,
627
- variant="primary"
628
- )
629
-
630
- gr.Markdown("---")
631
-
632
- with gr.Row():
633
- model_choice = gr.Dropdown(
634
- choices=AVAILABLE_MODELS,
635
- value=DEFAULT_MODEL,
636
- label="πŸ€– Select AI Model",
637
- info="Choose the model for prompt generation"
638
- )
639
-
640
- generate_btn = gr.Button(
641
- "✨ Generate AI Code Agent Prompt",
642
- variant="primary",
643
- size="lg",
644
- visible=False
645
- )
646
-
647
- enhanced_output = gr.Textbox(
648
- label="🎨 AI Code Agent Prompt (Ready to Use)",
649
- lines=30,
650
- show_copy_button=True,
651
- placeholder="Your AI code agent prompt will appear here...",
652
- info="Copy this prompt and paste it into your AI code agent system"
653
- )
654
-
655
- download_btn = gr.File(
656
- label="πŸ“₯ Download Prompt as Text File",
657
- visible=False
658
- )
659
-
660
- gr.Markdown("""
661
- ---
662
- ## πŸ“‹ How to Use
663
-
664
- ### Step 1: Create Your Prompt
665
- 1. **Enter Your Idea** - Describe your website concept
666
- 2. **Answer Questions** - Respond to guided questions (7 total)
667
- 3. **Generate Prompt** - Click to create your AI code agent prompt
668
- 4. **Download/Copy** - Save or copy the generated prompt
669
-
670
- ### Step 2: Use with AI Code Agent
671
- 1. **Copy the generated prompt**
672
- 2. **Paste into your AI code agent** (Cursor, Bolt.new, v0.dev, custom agents)
673
- 3. **Get production-ready code** with proper formatting
674
-
675
- ---
676
-
677
- ## 🎯 What You Get
678
-
679
- βœ… **Clean, Professional Prompt** - No Q&A clutter, just specifications
680
- βœ… **AI Code Agent Format** - Uses TITLE_PAGE, UPDATE_PAGE, SEARCH/REPLACE blocks
681
- βœ… **TailwindCSS Integration** - Modern, responsive styling
682
- βœ… **Animation Ready** - AOS scroll animations + Vanta.js backgrounds
683
- βœ… **Icon System** - Feather Icons integrated
684
- βœ… **Image Placeholders** - Static.photos for all images
685
- βœ… **Production Ready** - Complete technical specifications
686
- βœ… **Downloadable** - Save for future use
687
-
688
- ---
689
-
690
- ## πŸ”§ Compatible Systems
691
-
692
- This tool generates prompts compatible with:
693
- - ✨ **Custom AI Code Agents** (using the TITLE_PAGE/UPDATE_PAGE format)
694
- - ✨ **Cursor AI** - Paste and generate
695
- - ✨ **Bolt.new** - Direct integration
696
- - ✨ **v0.dev** - Component generation
697
- - ✨ **GitHub Copilot** - Enhanced context
698
- - ✨ **Any LLM** - ChatGPT, Claude, Gemini
699
-
700
- ---
701
-
702
- ## πŸ“š Output Format
703
-
704
- The generated prompts use a specific format for AI code agents:
705
-
706
- ### For New Websites:
707
- ```
708
- <<<<<<< START_TITLE index.html >>>>>>> END_TITLE
709
- ```html
710
- <!DOCTYPE html>
711
- ...complete HTML code...
712
- ```
713
- ```
714
-
715
- ### For Updates:
716
- ```
717
- <<<<<<< UPDATE_PAGE_START index.html >>>>>>> UPDATE_PAGE_END
718
- <<<<<<< SEARCH
719
- <h1>Old Content</h1>
720
- =======
721
- <h1 class="text-4xl font-bold">New Content</h1>
722
- >>>>>>> REPLACE
723
- ```
724
-
725
- ---
726
-
727
- ## πŸ’‘ Pro Tips
728
-
729
- - πŸ“ Be specific in your answers for better results
730
- - 🎨 Mention preferred colors, styles, and layouts
731
- - πŸ“± Specify if you need mobile-first design
732
- - πŸ”„ Indicate if updating existing code or creating new
733
- - ⚑ The more detail you provide, the better the output
734
-
735
- ---
736
-
737
- ## πŸ› οΈ Technical Stack Included
738
-
739
- Every generated prompt includes:
740
- - **TailwindCSS** - Utility-first CSS framework
741
- - **Feather Icons** - Beautiful icon set
742
- - **AOS.js** - Scroll animation library
743
- - **Vanta.js** - Animated backgrounds
744
- - **Anime.js** - Advanced animations
745
- - **Static.photos** - Professional placeholder images
746
-
747
- ---
748
-
749
- Made with ❀️ for developers | Optimized for AI Code Agents
750
- """)
751
-
752
- # Event Handlers
753
- start_btn.click(
754
- fn=start_process,
755
- inputs=[initial_prompt],
756
- outputs=[
757
- current_question,
758
- suggestion_text,
759
- answer_input,
760
- answer_input,
761
- submit_btn,
762
- generate_btn,
763
- status_text,
764
- enhanced_output,
765
- download_btn
766
- ]
767
- )
768
-
769
- submit_btn.click(
770
- fn=submit_answer,
771
- inputs=[answer_input],
772
- outputs=[
773
- current_question,
774
- suggestion_text,
775
- answer_input,
776
- answer_input,
777
- submit_btn,
778
- generate_btn,
779
- status_text,
780
- enhanced_output,
781
- download_btn
782
- ]
783
- )
784
-
785
- answer_input.submit(
786
- fn=submit_answer,
787
- inputs=[answer_input],
788
- outputs=[
789
- current_question,
790
- suggestion_text,
791
- answer_input,
792
- answer_input,
793
- submit_btn,
794
- generate_btn,
795
- status_text,
796
- enhanced_output,
797
- download_btn
798
- ]
799
- )
800
-
801
- generate_btn.click(
802
- fn=generate_final_prompt,
803
- inputs=[model_choice],
804
- outputs=[enhanced_output, status_text, download_btn]
805
- )
806
-
807
- enhanced_output.change(
808
- fn=save_prompt_to_file,
809
- inputs=[enhanced_output],
810
- outputs=[download_btn]
811
- )
812
-
813
- if __name__ == "__main__":
814
- demo.launch()
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+ from datetime import datetime
5
+
6
+ # Import all prompts and constants from prompts.py
7
+ from prompts import (
8
+ SEARCH_START, DIVIDER, REPLACE_END,
9
+ TITLE_PAGE_START, TITLE_PAGE_END,
10
+ NEW_PAGE_START, NEW_PAGE_END,
11
+ UPDATE_PAGE_START, UPDATE_PAGE_END,
12
+ WEB_DEV_QUESTIONS, PROMPT_FOR_IMAGE_GENERATION,
13
+ INITIAL_SYSTEM_PROMPT, FOLLOW_UP_SYSTEM_PROMPT,
14
+ PROMPT_ENGINEER_SYSTEM_PROMPT, SUGGESTED_ANSWERS,
15
+ HTML_TEMPLATE_EXAMPLE, CDN_LINKS,
16
+ AVAILABLE_MODELS, DEFAULT_MODEL
17
+ )
18
+
19
+ # Initialize the Hugging Face Inference Client
20
+ client = InferenceClient(token=os.getenv("HF_TOKEN"))
21
+
22
+ class WebsitePromptEnhancer:
23
+ def __init__(self):
24
+ self.context = []
25
+ self.current_question_idx = 0
26
+ self.user_responses = {}
27
+ self.initial_prompt = ""
28
+ self.is_update = False
29
+
30
+ def reset(self):
31
+ self.context = []
32
+ self.current_question_idx = 0
33
+ self.user_responses = {}
34
+ self.initial_prompt = ""
35
+ self.is_update = False
36
+
37
+ def start_enhancement(self, initial_prompt):
38
+ self.reset()
39
+ self.initial_prompt = initial_prompt
40
+ self.current_question_idx = 0
41
+ return self.get_next_question()
42
+
43
+ def get_next_question(self):
44
+ if self.current_question_idx < len(WEB_DEV_QUESTIONS):
45
+ return WEB_DEV_QUESTIONS[self.current_question_idx]
46
+ return None
47
+
48
+ def get_suggested_answer(self):
49
+ """Generate suggested answer based on context"""
50
+ if self.current_question_idx < len(WEB_DEV_QUESTIONS):
51
+ return SUGGESTED_ANSWERS.get(self.current_question_idx, "")
52
+ return ""
53
+
54
+ def process_answer(self, answer):
55
+ if self.current_question_idx < len(WEB_DEV_QUESTIONS):
56
+ question = WEB_DEV_QUESTIONS[self.current_question_idx]
57
+ self.user_responses[question] = answer
58
+ self.context.append(f"Q: {question}\nA: {answer}")
59
+
60
+ # Check if it's an update request
61
+ if self.current_question_idx == len(WEB_DEV_QUESTIONS) - 1:
62
+ if "update" in answer.lower() or "modify" in answer.lower() or "change" in answer.lower():
63
+ self.is_update = True
64
+
65
+ self.current_question_idx += 1
66
+
67
+ next_q = self.get_next_question()
68
+ return next_q
69
+
70
+ def generate_enhanced_prompt(self, model_name=DEFAULT_MODEL):
71
+ # Extract structured information from responses
72
+ website_type = self.user_responses.get(WEB_DEV_QUESTIONS[0], "website")
73
+ purpose = self.user_responses.get(WEB_DEV_QUESTIONS[1], "general purpose")
74
+ audience = self.user_responses.get(WEB_DEV_QUESTIONS[2], "general audience")
75
+ sections = self.user_responses.get(WEB_DEV_QUESTIONS[3], "Home, About, Contact")
76
+ color_scheme = self.user_responses.get(WEB_DEV_QUESTIONS[4], "modern and professional")
77
+ features = self.user_responses.get(WEB_DEV_QUESTIONS[5], "responsive design")
78
+ update_type = self.user_responses.get(WEB_DEV_QUESTIONS[6], "new website")
79
+
80
+ # Determine if it's an update or new website
81
+ is_update = "update" in update_type.lower() or "modify" in update_type.lower()
82
+
83
+ enhancement_prompt = f"""Create a detailed prompt for an AI code agent to build a professional website based on these requirements:
84
+
85
+ Project: {self.initial_prompt}
86
+ Type: {website_type}
87
+ Purpose: {purpose}
88
+ Target Audience: {audience}
89
+ Required Sections/Pages: {sections}
90
+ Design Theme: {color_scheme}
91
+ Features: {features}
92
+ Request Type: {"Update existing website" if is_update else "Create new website"}
93
+
94
+ Generate a comprehensive, production-ready specification following the AI code agent format.
95
+ The output should be a clean prompt (no Q&A) that includes:
96
+ 1. Clear project description
97
+ 2. Required pages/sections with specific details
98
+ 3. Design specifications (colors, layout, typography)
99
+ 4. Feature requirements with implementation details
100
+ 5. Technical stack specifications (TailwindCSS, Feather Icons, AOS, Vanta.js)
101
+ 6. Responsive design requirements
102
+ 7. Accessibility guidelines
103
+ 8. Image placeholder usage (static.photos)
104
+
105
+ The prompt should be ready to paste directly into an AI code agent system."""
106
+
107
+ try:
108
+ messages = [
109
+ {"role": "system", "content": PROMPT_ENGINEER_SYSTEM_PROMPT},
110
+ {"role": "user", "content": enhancement_prompt}
111
+ ]
112
+
113
+ response = client.chat_completion(
114
+ messages=messages,
115
+ model=model_name,
116
+ max_tokens=3000,
117
+ temperature=0.7,
118
+ stream=False
119
+ )
120
+
121
+ enhanced_prompt = response.choices[0].message.content
122
+ return self._format_for_code_agent(enhanced_prompt, is_update)
123
+
124
+ except Exception as e:
125
+ try:
126
+ full_prompt = f"{PROMPT_ENGINEER_SYSTEM_PROMPT}\n\n{enhancement_prompt}"
127
+ response = client.text_generation(
128
+ full_prompt,
129
+ model=model_name,
130
+ max_new_tokens=3000,
131
+ temperature=0.7,
132
+ return_full_text=False
133
+ )
134
+ return self._format_for_code_agent(response, is_update)
135
+ except Exception as e2:
136
+ return self._create_fallback_prompt(
137
+ website_type, purpose, audience, sections,
138
+ color_scheme, features, is_update
139
+ )
140
+
141
+ def _format_for_code_agent(self, prompt, is_update=False):
142
+ """Format the prompt to work with the AI code agent system"""
143
+
144
+ formatted_prompt = f"""# AI Code Agent Prompt - Website Generation
145
+
146
+ {prompt}
147
+
148
+ ---
149
+
150
+ ## Technical Requirements for AI Code Agent
151
+
152
+ ### Technology Stack
153
+ - **CSS Framework:** TailwindCSS (CDN: {CDN_LINKS['tailwind']})
154
+ - **Icons:** Feather Icons ({CDN_LINKS['feather_icons']})
155
+ - **Scroll Animations:** AOS.js ({CDN_LINKS['aos_css']})
156
+ - **Interactive Animations:** Vanta.js ({CDN_LINKS['vanta_globe']})
157
+ - **Additional:** Anime.js for advanced animations
158
+
159
+ ### Image Placeholders
160
+ {PROMPT_FOR_IMAGE_GENERATION}
161
+
162
+ ### Output Format Instructions
163
+ {"**For Updates/Modifications:**" if is_update else "**For New Website:**"}
164
+
165
+ {'Use the UPDATE_PAGE format:' if is_update else 'Use the TITLE_PAGE format:'}"""
166
+
167
+ if is_update:
168
+ formatted_prompt += f"""
169
+ 1. Start with: {UPDATE_PAGE_START}
170
+ 2. Specify the page name (e.g., index.html)
171
+ 3. Close with: {UPDATE_PAGE_END}
172
+ 4. Use SEARCH/REPLACE blocks:
173
+ - {SEARCH_START}
174
+ - (exact code to replace)
175
+ - {DIVIDER}
176
+ - (new code)
177
+ - {REPLACE_END}
178
+
179
+ For new pages during update:
180
+ 1. Start with: {NEW_PAGE_START}
181
+ 2. Specify page name (e.g., about.html)
182
+ 3. Close with: {NEW_PAGE_END}
183
+ 4. Provide complete HTML in ```html``` blocks
184
+ 5. Update navigation links in all existing pages"""
185
+ else:
186
+ formatted_prompt += f"""
187
+ 1. Start with: {TITLE_PAGE_START}
188
+ 2. Add page name (e.g., index.html)
189
+ 3. Close with: {TITLE_PAGE_END}
190
+ 4. Provide complete HTML in ```html``` blocks
191
+ 5. First file must be index.html
192
+ 6. Include all required CDN links in <head>
193
+ 7. Initialize all libraries in <body>"""
194
+
195
+ formatted_prompt += f"""
196
+
197
+ ### Required Code Structure
198
+
199
+ **Every HTML file must include:**
200
+
201
+ ```html
202
+ {HTML_TEMPLATE_EXAMPLE}
203
+ ```
204
+
205
+ ### Design Guidelines
206
+ - Mobile-first responsive design using TailwindCSS
207
+ - Use semantic HTML5 elements
208
+ - Implement smooth scroll animations with AOS
209
+ - Add interactive animations where appropriate (Vanta.js)
210
+ - Use Feather icons for all icons: <i data-feather="icon-name"></i>
211
+ - Ensure accessibility (ARIA labels, semantic tags)
212
+ - Cross-browser compatibility
213
+ - Performance optimized
214
+
215
+ ### Navigation
216
+ - For multi-page websites: Use <a href="page.html"> (no onclick)
217
+ - Ensure all pages have consistent navigation
218
+ - Mobile-responsive hamburger menu
219
+
220
+ ### Ready for AI Code Agent
221
+ This prompt is formatted for direct use with AI code agents.
222
+ Simply paste it into your AI coding assistant to generate the website."""
223
+ return formatted_prompt
224
+
225
+ def _create_fallback_prompt(self, website_type, purpose, audience, sections, color_scheme, features, is_update=False):
226
+ """Create a detailed fallback prompt in code agent format"""
227
+
228
+ sections_list = [s.strip() for s in sections.split(',')]
229
+
230
+ fallback = f"""# AI Code Agent Prompt - Professional Website Project Overview
231
+ Create a professional {website_type} website optimized for {audience}.
232
+
233
+ Primary Goal: {purpose}
234
+
235
+ Design Theme: {color_scheme} with modern UI/UX
236
+
237
+ Required Pages/Sections
238
+ """
239
+ for i, section in enumerate(sections_list, 1):
240
+ fallback += f"{i}. **{section.strip()}** - Complete page with relevant content\n"
241
+
242
+ fallback += f"""Feature Requirements
243
+ {features}
244
+
245
+ Core Features:
246
+ βœ… Fully responsive design (mobile, tablet, desktop)
247
+ βœ… Smooth scroll animations using AOS.js
248
+ βœ… Modern icons using Feather Icons
249
+ βœ… Interactive animations with Vanta.js (hero section)
250
+ βœ… TailwindCSS for all styling
251
+ βœ… Contact forms with validation (if applicable)
252
+ βœ… Image galleries with lightbox effect
253
+ βœ… Smooth navigation with active states
254
+ βœ… Loading animations and transitions
255
+ βœ… Accessibility compliant (WCAG 2.1)
256
+
257
+ ## Technology Stack
258
+ ### Required Libraries (CDN)
259
+ <!-- TailwindCSS -->
260
+ <script src="{CDN_LINKS['tailwind']}"></script>
261
+
262
+ <!-- AOS Scroll Animations -->
263
+ <link href="{CDN_LINKS['aos_css']}" rel="stylesheet">
264
+ <script src="{CDN_LINKS['aos_js']}"></script>
265
+
266
+ <!-- Feather Icons -->
267
+ <script src="{CDN_LINKS['feather_icons_min']}"></script>
268
+ <script src="{CDN_LINKS['feather_icons']}"></script>
269
+
270
+ <!-- Anime.js -->
271
+ <script src="{CDN_LINKS['anime_js']}"></script>
272
+
273
+ <!-- Vanta.js (for hero backgrounds) -->
274
+ <script src="{CDN_LINKS['vanta_globe']}"></script>
275
+
276
+ ## Design Specifications
277
+ ### Color Scheme
278
+ Primary theme: {color_scheme}
279
+
280
+ Suggested TailwindCSS Colors:
281
+ - Primary: bg-blue-600, text-blue-600
282
+ - Secondary: bg-gray-800, text-gray-800
283
+ - Accent: bg-purple-500, text-purple-500
284
+ - Background: bg-white, bg-gray-50
285
+ - Text: text-gray-900, text-gray-600
286
+
287
+ ### Typography
288
+ - Headings: Bold, large (text-4xl, text-5xl, font-bold)
289
+ - Body: Readable size (text-base, text-lg)
290
+ - Use TailwindCSS typography utilities
291
+
292
+ ### Layout Structure
293
+ - Header: Fixed/sticky navigation with logo and menu
294
+ - Hero Section: Full-screen with Vanta.js background animation
295
+ - Content Sections: Alternating layouts with AOS animations
296
+ - Footer: Links, social media, copyright
297
+
298
+ ### Responsive Breakpoints
299
+ - Mobile: sm: (640px)
300
+ - Tablet: md: (768px)
301
+ - Desktop: lg: (1024px)
302
+ - Large: xl: (1280px)
303
+
304
+ ### Image Guidelines
305
+ Use Static.Photos for Placeholders
306
+ {PROMPT_FOR_IMAGE_GENERATION}
307
+
308
+ Recommended Usage:
309
+ - Hero images: http://static.photos/abstract/1200x630/1
310
+ - Portfolio/Gallery: http://static.photos/technology/640x360/[1-10]
311
+ - Team photos: http://static.photos/people/320x240/[1-5]
312
+ - Background images: http://static.photos/minimal/1024x576/42
313
+
314
+ ### Animation Requirements
315
+ #### AOS Scroll Animations
316
+ Use on all major sections:
317
+ <div data-aos="fade-up" data-aos-duration="1000">
318
+ Content here
319
+ </div>
320
+ Available Effects: fade-up, fade-down, fade-left, fade-right, zoom-in, flip-up
321
+
322
+ #### Vanta.js Hero Background
323
+ Implement on hero section:
324
+ <script>
325
+ VANTA.GLOBE({{
326
+ el: "#hero",
327
+ mouseControls: true,
328
+ touchControls: true,
329
+ gyroControls: false,
330
+ minHeight: 200.00,
331
+ minWidth: 200.00,
332
+ scale: 1.00,
333
+ scaleMobile: 1.00,
334
+ color: 0x3b82f6,
335
+ backgroundColor: 0x0f172a
336
+ }})
337
+ </script>
338
+
339
+ #### Feather Icons Usage
340
+ <i data-feather="menu"></i>
341
+ <i data-feather="mail"></i>
342
+ <i data-feather="phone"></i>
343
+ <i data-feather="github"></i>
344
+
345
+ ### Code Structure Format
346
+ {"Update Format (Modifying Existing Pages)" if is_update else "New Website Format"}
347
+ {"Use UPDATE_PAGE blocks:" if is_update else "Use TITLE_PAGE blocks:"}"""
348
+
349
+ if is_update:
350
+ fallback += f"""
351
+ {UPDATE_PAGE_START}index.html{UPDATE_PAGE_END}
352
+
353
+ {SEARCH_START}
354
+ <h1>Old Title</h1>
355
+ {DIVIDER}
356
+ <h1 class="text-4xl font-bold text-blue-600">New Title</h1>
357
+ {REPLACE_END}
358
+
359
+ For adding new pages:
360
+ {NEW_PAGE_START}about.html{NEW_PAGE_END}
361
+ ```html
362
+ {HTML_TEMPLATE_EXAMPLE}
363
+ ```"""
364
+ else:
365
+ fallback += f"""
366
+ {TITLE_PAGE_START}index.html{TITLE_PAGE_END}
367
+ ```html
368
+ {HTML_TEMPLATE_EXAMPLE}
369
+ ```"""
370
+
371
+ fallback += """
372
+ ## Quality Standards
373
+ ### Code Quality
374
+ - Clean, well-commented code
375
+ - Proper indentation and formatting
376
+ - Semantic HTML5 elements
377
+ - Modular CSS with TailwindCSS utilities
378
+ - Efficient JavaScript
379
+
380
+ ### Accessibility
381
+ - ARIA labels on interactive elements
382
+ - Alt text on all images
383
+ - Proper heading hierarchy (h1-h6)
384
+ - Keyboard navigation support
385
+ - Sufficient color contrast
386
+
387
+ ### Performance
388
+ - Optimized images
389
+ - Minified assets where possible
390
+ - Efficient animations
391
+ - Fast loading times (<3 seconds)
392
+ - Mobile-optimized
393
+
394
+ ### Browser Compatibility
395
+ - Chrome, Firefox, Safari, Edge (latest 2 versions)
396
+ - iOS Safari and Chrome Mobile
397
+ - Graceful degradation for older browsers
398
+
399
+ ## Deliverable
400
+ Create a complete, production-ready website that:
401
+ βœ… Follows all format requirements for the AI code agent
402
+ βœ… Includes all specified pages/sections
403
+ βœ… Uses TailwindCSS for ALL styling
404
+ βœ… Implements animations (AOS, Vanta.js)
405
+ βœ… Uses Feather Icons for all icons
406
+ βœ… Uses static.photos for all images
407
+ βœ… Is fully responsive (mobile-first)
408
+ βœ… Is accessible (WCAG 2.1 AA)
409
+ βœ… Has clean, professional code
410
+ βœ… Is ready for immediate deployment
411
+
412
+ Generate the complete website code now following the format specified above."""
413
+ return fallback
414
+
415
+ # Initialize enhancer
416
+ enhancer = WebsitePromptEnhancer()
417
+
418
+ # Gradio Interface Functions
419
+ def submit_answer(answer):
420
+ if not answer.strip():
421
+ return (
422
+ "",
423
+ "",
424
+ "",
425
+ gr.update(interactive=False),
426
+ gr.update(interactive=False),
427
+ gr.update(visible=False),
428
+ "⚠️ Please enter your initial website idea first!",
429
+ "",
430
+ gr.update(visible=False)
431
+ )
432
+
433
+ next_question = enhancer.process_answer(answer)
434
+
435
+ if next_question:
436
+ suggestion = enhancer.get_suggested_answer()
437
+ return (
438
+ next_question,
439
+ suggestion,
440
+ "",
441
+ gr.update(interactive=True),
442
+ gr.update(interactive=True),
443
+ gr.update(visible=False),
444
+ f"βœ… Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
445
+ "",
446
+ gr.update(visible=False)
447
+ )
448
+ else:
449
+ return (
450
+ "πŸŽ‰ All questions completed! Click 'Generate Enhanced Prompt' below.",
451
+ "",
452
+ "",
453
+ gr.update(interactive=False),
454
+ gr.update(interactive=False),
455
+ gr.update(visible=True),
456
+ "βœ… All questions answered! Ready to generate your AI Code Agent prompt.",
457
+ "",
458
+ gr.update(visible=False)
459
+ )
460
+
461
+ def start_process(initial_prompt):
462
+ if not initial_prompt.strip():
463
+ return (
464
+ "",
465
+ "",
466
+ "",
467
+ gr.update(interactive=False),
468
+ gr.update(interactive=False),
469
+ gr.update(visible=False),
470
+ "⚠️ Please enter your initial website idea first!",
471
+ "",
472
+ gr.update(visible=False)
473
+ )
474
+
475
+ next_question = enhancer.start_enhancement(initial_prompt)
476
+ suggestion = enhancer.get_suggested_answer()
477
+
478
+ return (
479
+ next_question,
480
+ suggestion,
481
+ "",
482
+ gr.update(interactive=True),
483
+ gr.update(interactive=True),
484
+ gr.update(visible=False),
485
+ f"βœ… Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
486
+ "",
487
+ gr.update(visible=False)
488
+ )
489
+
490
+ def generate_final_prompt(model_choice):
491
+ try:
492
+ status_msg = "πŸ”„ Generating AI Code Agent prompt... Please wait."
493
+ yield "", status_msg, gr.update(visible=False)
494
+ enhanced = enhancer.generate_enhanced_prompt(model_choice)
495
+
496
+ yield enhanced, "βœ… AI Code Agent prompt generated! Copy and paste into your AI code agent to generate the website.", gr.update(visible=True)
497
+ except Exception as e:
498
+ yield f"Error: {str(e)}", "❌ Generation failed. Please try again or use a different model.", gr.update(visible=False)
499
+
500
+ def save_prompt_to_file(prompt_text):
501
+ """Save the prompt to a text file and return the file path"""
502
+ if not prompt_text or prompt_text.strip() == "":
503
+ return None
504
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
505
+ filename = f"ai_code_agent_prompt_{timestamp}.txt"
506
+
507
+ with open(filename, "w", encoding="utf-8") as f:
508
+ f.write("=" * 80 + "\n")
509
+ f.write("AI CODE AGENT - WEBSITE DEVELOPMENT PROMPT\n")
510
+ f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
511
+ f.write("=" * 80 + "\n\n")
512
+ f.write(prompt_text)
513
+ f.write("\n\n" + "=" * 80 + "\n")
514
+ f.write("Paste this prompt into your AI Code Agent to generate the website\n")
515
+ f.write("Compatible with: Custom AI Code Agents, Cursor, Bolt.new, v0.dev, etc.\n")
516
+ f.write("=" * 80 + "\n")
517
+
518
+ return filename
519
+
520
+ # Custom CSS
521
+ custom_css = """
522
+ .container {max-width: 1200px; margin: auto; padding: 20px;}
523
+ .header {
524
+ text-align: center;
525
+ margin-bottom: 30px;
526
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
527
+ padding: 30px;
528
+ border-radius: 15px;
529
+ color: white;
530
+ }
531
+ .question-box {
532
+ background: #f0f7ff;
533
+ padding: 20px;
534
+ border-radius: 10px;
535
+ margin: 10px 0;
536
+ border-left: 4px solid #667eea;
537
+ }
538
+ .status-box {
539
+ background: #e8f5e9;
540
+ padding: 15px;
541
+ border-radius: 8px;
542
+ margin: 10px 0;
543
+ font-weight: 500;
544
+ }
545
+ .suggestion-box {
546
+ background: #fff3e0;
547
+ padding: 10px;
548
+ border-radius: 5px;
549
+ font-size: 0.9em;
550
+ color: #e65100;
551
+ }
552
+ .download-btn {
553
+ background: #4CAF50 !important;
554
+ }
555
+ .code-agent-badge {
556
+ background: #667eea;
557
+ color: white;
558
+ padding: 5px 15px;
559
+ border-radius: 20px;
560
+ font-size: 0.85em;
561
+ display: inline-block;
562
+ margin: 5px;
563
+ }
564
+ """
565
+
566
+ # Build Interface
567
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Code Agent Prompt Enhancer") as demo:
568
+ gr.Markdown("""
569
+ # πŸš€ AI Code Agent Prompt Enhancer
570
+ ### Transform Ideas into Professional AI Code Agent Prompts
571
+ Generate detailed, production-ready prompts optimized for AI code agent systems.
572
+
573
+ <div style="text-align: center; margin: 10px 0;">
574
+ <span class="code-agent-badge">✨ TailwindCSS</span>
575
+ <span class="code-agent-badge">🎨 Feather Icons</span>
576
+ <span class="code-agent-badge">πŸ“± AOS Animations</span>
577
+ <span class="code-agent-badge">🌟 Vanta.js</span>
578
+ <span class="code-agent-badge">πŸ–ΌοΈ Static.photos</span>
579
+ </div>
580
+ """, elem_classes="header")
581
+
582
+ with gr.Row():
583
+ with gr.Column(scale=2):
584
+ initial_prompt = gr.Textbox(
585
+ label="πŸ’‘ Your Website Idea",
586
+ placeholder="Example: 'Create a modern portfolio website for a photographer with gallery and contact form'",
587
+ lines=3,
588
+ info="Describe what kind of website you want to create"
589
+ )
590
+ with gr.Column(scale=1):
591
+ start_btn = gr.Button(
592
+ "🎯 Start Enhancement",
593
+ variant="primary",
594
+ size="lg"
595
+ )
596
+
597
+ status_text = gr.Markdown("πŸ‘† Enter your idea above and click 'Start Enhancement'", elem_classes="status-box")
598
+
599
+ gr.Markdown("---")
600
+
601
+ with gr.Row():
602
+ with gr.Column():
603
+ current_question = gr.Textbox(
604
+ label="❓ Current Question",
605
+ interactive=False,
606
+ lines=2,
607
+ elem_classes="question-box"
608
+ )
609
+
610
+ suggestion_text = gr.Textbox(
611
+ label="πŸ’­ Suggestion",
612
+ interactive=False,
613
+ lines=2,
614
+ elem_classes="suggestion-box"
615
+ )
616
+
617
+ answer_input = gr.Textbox(
618
+ label="✍️ Your Answer",
619
+ placeholder="Type your answer here...",
620
+ lines=4,
621
+ interactive=False
622
+ )
623
+
624
+ submit_btn = gr.Button(
625
+ "Submit Answer ➑️",
626
+ interactive=False,
627
+ variant="primary"
628
+ )
629
+
630
+ gr.Markdown("---")
631
+
632
+ with gr.Row():
633
+ model_choice = gr.Dropdown(
634
+ choices=AVAILABLE_MODELS,
635
+ value=DEFAULT_MODEL,
636
+ label="πŸ€– Select AI Model",
637
+ info="Choose the model for prompt generation"
638
+ )
639
+
640
+ generate_btn = gr.Button(
641
+ "✨ Generate AI Code Agent Prompt",
642
+ variant="primary",
643
+ size="lg",
644
+ visible=False
645
+ )
646
+
647
+ enhanced_output = gr.Textbox(
648
+ label="🎨 AI Code Agent Prompt (Ready to Use)",
649
+ lines=30,
650
+ show_copy_button=True,
651
+ placeholder="Your AI code agent prompt will appear here...",
652
+ info="Copy this prompt and paste it into your AI code agent system"
653
+ )
654
+
655
+ download_btn = gr.File(
656
+ label="πŸ“₯ Download Prompt as Text File",
657
+ visible=False
658
+ )
659
+
660
+ gr.Markdown("""
661
+ ---
662
+ ## πŸ“‹ How to Use
663
+
664
+ ### Step 1: Create Your Prompt
665
+ 1. **Enter Your Idea** - Describe your website concept
666
+ 2. **Answer Questions** - Respond to guided questions (7 total)
667
+ 3. **Generate Prompt** - Click to create your AI code agent prompt
668
+ 4. **Download/Copy** - Save or copy the generated prompt
669
+
670
+ ### Step 2: Use with AI Code Agent
671
+ 1. **Copy the generated prompt**
672
+ 2. **Paste into your AI code agent** (Cursor, Bolt.new, v0.dev, custom agents)
673
+ 3. **Get production-ready code** with proper formatting
674
+
675
+ ---
676
+
677
+ ## 🎯 What You Get
678
+
679
+ βœ… **Clean, Professional Prompt** - No Q&A clutter, just specifications
680
+ βœ… **AI Code Agent Format** - Uses TITLE_PAGE, UPDATE_PAGE, SEARCH/REPLACE blocks
681
+ βœ… **TailwindCSS Integration** - Modern, responsive styling
682
+ βœ… **Animation Ready** - AOS scroll animations + Vanta.js backgrounds
683
+ βœ… **Icon System** - Feather Icons integrated
684
+ βœ… **Image Placeholders** - Static.photos for all images
685
+ βœ… **Production Ready** - Complete technical specifications
686
+ βœ… **Downloadable** - Save for future use
687
+
688
+ ---
689
+
690
+ ## πŸ”§ Compatible Systems
691
+
692
+ This tool generates prompts compatible with:
693
+ - ✨ **Custom AI Code Agents** (using the TITLE_PAGE/UPDATE_PAGE format)
694
+ - ✨ **Cursor AI** - Paste and generate
695
+ - ✨ **Bolt.new** - Direct integration
696
+ - ✨ **v0.dev** - Component generation
697
+ - ✨ **GitHub Copilot** - Enhanced context
698
+ - ✨ **Any LLM** - ChatGPT, Claude, Gemini
699
+
700
+ ---
701
+
702
+ ## πŸ“š Output Format
703
+
704
+ The generated prompts use a specific format for AI code agents:
705
+
706
+ ### For New Websites:
707
+ ```
708
+ <<<<<<< START_TITLE index.html >>>>>>> END_TITLE
709
+ ```html
710
+ <!DOCTYPE html>
711
+ ...complete HTML code...
712
+ ```
713
+ ```
714
+
715
+ ### For Updates:
716
+ ```
717
+ <<<<<<< UPDATE_PAGE_START index.html >>>>>>> UPDATE_PAGE_END
718
+ <<<<<<< SEARCH
719
+ <h1>Old Content</h1>
720
+ =======
721
+ <h1 class="text-4xl font-bold">New Content</h1>
722
+ >>>>>>> REPLACE
723
+ ```
724
+
725
+ ---
726
+
727
+ ## πŸ’‘ Pro Tips
728
+
729
+ - πŸ“ Be specific in your answers for better results
730
+ - 🎨 Mention preferred colors, styles, and layouts
731
+ - πŸ“± Specify if you need mobile-first design
732
+ - πŸ”„ Indicate if updating existing code or creating new
733
+ - ⚑ The more detail you provide, the better the output
734
+
735
+ ---
736
+
737
+ ## πŸ› οΈ Technical Stack Included
738
+
739
+ Every generated prompt includes:
740
+ - **TailwindCSS** - Utility-first CSS framework
741
+ - **Feather Icons** - Beautiful icon set
742
+ - **AOS.js** - Scroll animation library
743
+ - **Vanta.js** - Animated backgrounds
744
+ - **Anime.js** - Advanced animations
745
+ - **Static.photos** - Professional placeholder images
746
+
747
+ ---
748
+
749
+ Made with ❀️ for developers | Optimized for AI Code Agents
750
+ """)
751
+
752
+ # Event Handlers
753
+ start_btn.click(
754
+ fn=start_process,
755
+ inputs=[initial_prompt],
756
+ outputs=[
757
+ current_question,
758
+ suggestion_text,
759
+ answer_input,
760
+ answer_input,
761
+ submit_btn,
762
+ generate_btn,
763
+ status_text,
764
+ enhanced_output,
765
+ download_btn
766
+ ]
767
+ )
768
+
769
+ submit_btn.click(
770
+ fn=submit_answer,
771
+ inputs=[answer_input],
772
+ outputs=[
773
+ current_question,
774
+ suggestion_text,
775
+ answer_input,
776
+ answer_input,
777
+ submit_btn,
778
+ generate_btn,
779
+ status_text,
780
+ enhanced_output,
781
+ download_btn
782
+ ]
783
+ )
784
+
785
+ answer_input.submit(
786
+ fn=submit_answer,
787
+ inputs=[answer_input],
788
+ outputs=[
789
+ current_question,
790
+ suggestion_text,
791
+ answer_input,
792
+ answer_input,
793
+ submit_btn,
794
+ generate_btn,
795
+ status_text,
796
+ enhanced_output,
797
+ download_btn
798
+ ]
799
+ )
800
+
801
+ generate_btn.click(
802
+ fn=generate_final_prompt,
803
+ inputs=[model_choice],
804
+ outputs=[enhanced_output, status_text, download_btn]
805
+ )
806
+
807
+ enhanced_output.change(
808
+ fn=save_prompt_to_file,
809
+ inputs=[enhanced_output],
810
+ outputs=[download_btn]
811
+ )
812
+
813
+ if __name__ == "__main__":
814
+ demo.launch()