File size: 25,274 Bytes
f5f4bbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
import gradio as gr
from huggingface_hub import InferenceClient
import os
from datetime import datetime

# Import all prompts and constants from prompts.py
from prompts import (
    SEARCH_START, DIVIDER, REPLACE_END,
    TITLE_PAGE_START, TITLE_PAGE_END,
    NEW_PAGE_START, NEW_PAGE_END,
    UPDATE_PAGE_START, UPDATE_PAGE_END,
    WEB_DEV_QUESTIONS, PROMPT_FOR_IMAGE_GENERATION,
    INITIAL_SYSTEM_PROMPT, FOLLOW_UP_SYSTEM_PROMPT,
    PROMPT_ENGINEER_SYSTEM_PROMPT, SUGGESTED_ANSWERS,
    HTML_TEMPLATE_EXAMPLE, CDN_LINKS,
    AVAILABLE_MODELS, DEFAULT_MODEL
)

# Initialize the Hugging Face Inference Client
client = InferenceClient(token=os.getenv("HF_TOKEN"))

class WebsitePromptEnhancer:
    def __init__(self):
        self.context = []
        self.current_question_idx = 0
        self.user_responses = {}
        self.initial_prompt = ""
        self.is_update = False
    
    def reset(self):
        self.context = []
        self.current_question_idx = 0
        self.user_responses = {}
        self.initial_prompt = ""
        self.is_update = False
    
    def start_enhancement(self, initial_prompt):
        self.reset()
        self.initial_prompt = initial_prompt
        self.current_question_idx = 0
        return self.get_next_question()
    
    def get_next_question(self):
        if self.current_question_idx < len(WEB_DEV_QUESTIONS):
            return WEB_DEV_QUESTIONS[self.current_question_idx]
        return None
    
    def get_suggested_answer(self):
        """Generate suggested answer based on context"""
        if self.current_question_idx < len(WEB_DEV_QUESTIONS):
            return SUGGESTED_ANSWERS.get(self.current_question_idx, "")
        return ""
    
    def process_answer(self, answer):
        if self.current_question_idx < len(WEB_DEV_QUESTIONS):
            question = WEB_DEV_QUESTIONS[self.current_question_idx]
            self.user_responses[question] = answer
            self.context.append(f"Q: {question}\nA: {answer}")
            
            # Check if it's an update request
            if self.current_question_idx == len(WEB_DEV_QUESTIONS) - 1:
                if "update" in answer.lower() or "modify" in answer.lower() or "change" in answer.lower():
                    self.is_update = True
            
            self.current_question_idx += 1
        
        next_q = self.get_next_question()
        return next_q
    
    def generate_enhanced_prompt(self, model_name=DEFAULT_MODEL):
        # Extract structured information from responses
        website_type = self.user_responses.get(WEB_DEV_QUESTIONS[0], "website")
        purpose = self.user_responses.get(WEB_DEV_QUESTIONS[1], "general purpose")
        audience = self.user_responses.get(WEB_DEV_QUESTIONS[2], "general audience")
        sections = self.user_responses.get(WEB_DEV_QUESTIONS[3], "Home, About, Contact")
        color_scheme = self.user_responses.get(WEB_DEV_QUESTIONS[4], "modern and professional")
        features = self.user_responses.get(WEB_DEV_QUESTIONS[5], "responsive design")
        update_type = self.user_responses.get(WEB_DEV_QUESTIONS[6], "new website")
        
        # Determine if it's an update or new website
        is_update = "update" in update_type.lower() or "modify" in update_type.lower()
        
        enhancement_prompt = f"""Create a detailed prompt for an AI code agent to build a professional website based on these requirements:

Project: {self.initial_prompt}
Type: {website_type}
Purpose: {purpose}
Target Audience: {audience}
Required Sections/Pages: {sections}
Design Theme: {color_scheme}
Features: {features}
Request Type: {"Update existing website" if is_update else "Create new website"}

Generate a comprehensive, production-ready specification following the AI code agent format.
The output should be a clean prompt (no Q&A) that includes:
1. Clear project description
2. Required pages/sections with specific details
3. Design specifications (colors, layout, typography)
4. Feature requirements with implementation details
5. Technical stack specifications (TailwindCSS, Feather Icons, AOS, Vanta.js)
6. Responsive design requirements
7. Accessibility guidelines
8. Image placeholder usage (static.photos)

The prompt should be ready to paste directly into an AI code agent system."""

        try:
            messages = [
                {"role": "system", "content": PROMPT_ENGINEER_SYSTEM_PROMPT},
                {"role": "user", "content": enhancement_prompt}
            ]
            
            response = client.chat_completion(
                messages=messages,
                model=model_name,
                max_tokens=3000,
                temperature=0.7,
                stream=False
            )
            
            enhanced_prompt = response.choices[0].message.content
            return self._format_for_code_agent(enhanced_prompt, is_update)
            
        except Exception as e:
            try:
                full_prompt = f"{PROMPT_ENGINEER_SYSTEM_PROMPT}\n\n{enhancement_prompt}"
                response = client.text_generation(
                    full_prompt,
                    model=model_name,
                    max_new_tokens=3000,
                    temperature=0.7,
                    return_full_text=False
                )
                return self._format_for_code_agent(response, is_update)
            except Exception as e2:
                return self._create_fallback_prompt(
                    website_type, purpose, audience, sections, 
                    color_scheme, features, is_update
                )
    
    def _format_for_code_agent(self, prompt, is_update=False):
        """Format the prompt to work with the AI code agent system"""
        
        formatted_prompt = f"""# AI Code Agent Prompt - Website Generation

{prompt}

---

## Technical Requirements for AI Code Agent

### Technology Stack
- **CSS Framework:** TailwindCSS (CDN: {CDN_LINKS['tailwind']})
- **Icons:** Feather Icons ({CDN_LINKS['feather_icons']})
- **Scroll Animations:** AOS.js ({CDN_LINKS['aos_css']})
- **Interactive Animations:** Vanta.js ({CDN_LINKS['vanta_globe']})
- **Additional:** Anime.js for advanced animations

### Image Placeholders
{PROMPT_FOR_IMAGE_GENERATION}

### Output Format Instructions
{"**For Updates/Modifications:**" if is_update else "**For New Website:**"}

{'Use the UPDATE_PAGE format:' if is_update else 'Use the TITLE_PAGE format:'}"""

        if is_update:
            formatted_prompt += f"""
1. Start with: {UPDATE_PAGE_START}
2. Specify the page name (e.g., index.html)
3. Close with: {UPDATE_PAGE_END}
4. Use SEARCH/REPLACE blocks:
   - {SEARCH_START}
   - (exact code to replace)
   - {DIVIDER}
   - (new code)
   - {REPLACE_END}

For new pages during update:
1. Start with: {NEW_PAGE_START}
2. Specify page name (e.g., about.html)
3. Close with: {NEW_PAGE_END}
4. Provide complete HTML in ```html``` blocks
5. Update navigation links in all existing pages"""
        else:
            formatted_prompt += f"""
1. Start with: {TITLE_PAGE_START}
2. Add page name (e.g., index.html)
3. Close with: {TITLE_PAGE_END}
4. Provide complete HTML in ```html``` blocks
5. First file must be index.html
6. Include all required CDN links in <head>
7. Initialize all libraries in <body>"""

        formatted_prompt += f"""

### Required Code Structure

**Every HTML file must include:**

```html
{HTML_TEMPLATE_EXAMPLE}
```

### Design Guidelines
- Mobile-first responsive design using TailwindCSS
- Use semantic HTML5 elements
- Implement smooth scroll animations with AOS
- Add interactive animations where appropriate (Vanta.js)
- Use Feather icons for all icons: <i data-feather="icon-name"></i>
- Ensure accessibility (ARIA labels, semantic tags)
- Cross-browser compatibility
- Performance optimized

### Navigation
- For multi-page websites: Use <a href="page.html"> (no onclick)
- Ensure all pages have consistent navigation
- Mobile-responsive hamburger menu

### Ready for AI Code Agent
This prompt is formatted for direct use with AI code agents.
Simply paste it into your AI coding assistant to generate the website."""
        return formatted_prompt

    def _create_fallback_prompt(self, website_type, purpose, audience, sections, color_scheme, features, is_update=False):
        """Create a detailed fallback prompt in code agent format"""
        
        sections_list = [s.strip() for s in sections.split(',')]
        
        fallback = f"""# AI Code Agent Prompt - Professional Website Project Overview
Create a professional {website_type} website optimized for {audience}.

Primary Goal: {purpose}

Design Theme: {color_scheme} with modern UI/UX

Required Pages/Sections
"""
        for i, section in enumerate(sections_list, 1):
            fallback += f"{i}. **{section.strip()}** - Complete page with relevant content\n"
        
        fallback += f"""Feature Requirements
{features}

Core Features:
βœ… Fully responsive design (mobile, tablet, desktop)
βœ… Smooth scroll animations using AOS.js
βœ… Modern icons using Feather Icons
βœ… Interactive animations with Vanta.js (hero section)
βœ… TailwindCSS for all styling
βœ… Contact forms with validation (if applicable)
βœ… Image galleries with lightbox effect
βœ… Smooth navigation with active states
βœ… Loading animations and transitions
βœ… Accessibility compliant (WCAG 2.1)

## Technology Stack
### Required Libraries (CDN)
<!-- TailwindCSS -->
<script src="{CDN_LINKS['tailwind']}"></script>

<!-- AOS Scroll Animations -->
<link href="{CDN_LINKS['aos_css']}" rel="stylesheet">
<script src="{CDN_LINKS['aos_js']}"></script>

<!-- Feather Icons -->
<script src="{CDN_LINKS['feather_icons_min']}"></script>
<script src="{CDN_LINKS['feather_icons']}"></script>

<!-- Anime.js -->
<script src="{CDN_LINKS['anime_js']}"></script>

<!-- Vanta.js (for hero backgrounds) -->
<script src="{CDN_LINKS['vanta_globe']}"></script>

## Design Specifications
### Color Scheme
Primary theme: {color_scheme}

Suggested TailwindCSS Colors:
- Primary: bg-blue-600, text-blue-600
- Secondary: bg-gray-800, text-gray-800
- Accent: bg-purple-500, text-purple-500
- Background: bg-white, bg-gray-50
- Text: text-gray-900, text-gray-600

### Typography
- Headings: Bold, large (text-4xl, text-5xl, font-bold)
- Body: Readable size (text-base, text-lg)
- Use TailwindCSS typography utilities

### Layout Structure
- Header: Fixed/sticky navigation with logo and menu
- Hero Section: Full-screen with Vanta.js background animation
- Content Sections: Alternating layouts with AOS animations
- Footer: Links, social media, copyright

### Responsive Breakpoints
- Mobile: sm: (640px)
- Tablet: md: (768px)
- Desktop: lg: (1024px)
- Large: xl: (1280px)

### Image Guidelines
Use Static.Photos for Placeholders
{PROMPT_FOR_IMAGE_GENERATION}

Recommended Usage:
- Hero images: http://static.photos/abstract/1200x630/1
- Portfolio/Gallery: http://static.photos/technology/640x360/[1-10]
- Team photos: http://static.photos/people/320x240/[1-5]
- Background images: http://static.photos/minimal/1024x576/42

### Animation Requirements
#### AOS Scroll Animations
Use on all major sections:
<div data-aos="fade-up" data-aos-duration="1000">
    Content here
</div>
Available Effects: fade-up, fade-down, fade-left, fade-right, zoom-in, flip-up

#### Vanta.js Hero Background
Implement on hero section:
<script>
VANTA.GLOBE({{
  el: "#hero",
  mouseControls: true,
  touchControls: true,
  gyroControls: false,
  minHeight: 200.00,
  minWidth: 200.00,
  scale: 1.00,
  scaleMobile: 1.00,
  color: 0x3b82f6,
  backgroundColor: 0x0f172a
}})
</script>

#### Feather Icons Usage
<i data-feather="menu"></i>
<i data-feather="mail"></i>
<i data-feather="phone"></i>
<i data-feather="github"></i>

### Code Structure Format
{"Update Format (Modifying Existing Pages)" if is_update else "New Website Format"}
{"Use UPDATE_PAGE blocks:" if is_update else "Use TITLE_PAGE blocks:"}"""

        if is_update:
            fallback += f"""
{UPDATE_PAGE_START}index.html{UPDATE_PAGE_END}

{SEARCH_START}
    <h1>Old Title</h1>
{DIVIDER}
    <h1 class="text-4xl font-bold text-blue-600">New Title</h1>
{REPLACE_END}

For adding new pages:
{NEW_PAGE_START}about.html{NEW_PAGE_END}
```html
{HTML_TEMPLATE_EXAMPLE}
```"""
        else:
            fallback += f"""
{TITLE_PAGE_START}index.html{TITLE_PAGE_END}
```html
{HTML_TEMPLATE_EXAMPLE}
```"""
        
        fallback += """
## Quality Standards
### Code Quality
- Clean, well-commented code
- Proper indentation and formatting
- Semantic HTML5 elements
- Modular CSS with TailwindCSS utilities
- Efficient JavaScript

### Accessibility
- ARIA labels on interactive elements
- Alt text on all images
- Proper heading hierarchy (h1-h6)
- Keyboard navigation support
- Sufficient color contrast

### Performance
- Optimized images
- Minified assets where possible
- Efficient animations
- Fast loading times (<3 seconds)
- Mobile-optimized

### Browser Compatibility
- Chrome, Firefox, Safari, Edge (latest 2 versions)
- iOS Safari and Chrome Mobile
- Graceful degradation for older browsers

## Deliverable
Create a complete, production-ready website that:
βœ… Follows all format requirements for the AI code agent
βœ… Includes all specified pages/sections
βœ… Uses TailwindCSS for ALL styling
βœ… Implements animations (AOS, Vanta.js)
βœ… Uses Feather Icons for all icons
βœ… Uses static.photos for all images
βœ… Is fully responsive (mobile-first)
βœ… Is accessible (WCAG 2.1 AA)
βœ… Has clean, professional code
βœ… Is ready for immediate deployment

Generate the complete website code now following the format specified above."""
        return fallback

# Initialize enhancer
enhancer = WebsitePromptEnhancer()

# Gradio Interface Functions
def submit_answer(answer):
    if not answer.strip():
        return (
            "",
            "",
            "",
            gr.update(interactive=False),
            gr.update(interactive=False),
            gr.update(visible=False),
            "⚠️ Please enter your initial website idea first!",
            "",
            gr.update(visible=False)
        )
    
    next_question = enhancer.process_answer(answer)

    if next_question:
        suggestion = enhancer.get_suggested_answer()
        return (
            next_question,
            suggestion,
            "",
            gr.update(interactive=True),
            gr.update(interactive=True),
            gr.update(visible=False),
            f"βœ… Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
            "",
            gr.update(visible=False)
        )
    else:
        return (
            "πŸŽ‰ All questions completed! Click 'Generate Enhanced Prompt' below.",
            "",
            "",
            gr.update(interactive=False),
            gr.update(interactive=False),
            gr.update(visible=True),
            "βœ… All questions answered! Ready to generate your AI Code Agent prompt.",
            "",
            gr.update(visible=False)
        )

def start_process(initial_prompt):
    if not initial_prompt.strip():
        return (
            "",
            "",
            "",
            gr.update(interactive=False),
            gr.update(interactive=False),
            gr.update(visible=False),
            "⚠️ Please enter your initial website idea first!",
            "",
            gr.update(visible=False)
        )
    
    next_question = enhancer.start_enhancement(initial_prompt)
    suggestion = enhancer.get_suggested_answer()
    
    return (
        next_question,
        suggestion,
        "",
        gr.update(interactive=True),
        gr.update(interactive=True),
        gr.update(visible=False),
        f"βœ… Progress: {enhancer.current_question_idx}/{len(WEB_DEV_QUESTIONS)} questions answered",
        "",
        gr.update(visible=False)
    )

def generate_final_prompt(model_choice):
    try:
        status_msg = "πŸ”„ Generating AI Code Agent prompt... Please wait."
        yield "", status_msg, gr.update(visible=False)
        enhanced = enhancer.generate_enhanced_prompt(model_choice)
        
        yield enhanced, "βœ… AI Code Agent prompt generated! Copy and paste into your AI code agent to generate the website.", gr.update(visible=True)
    except Exception as e:
        yield f"Error: {str(e)}", "❌ Generation failed. Please try again or use a different model.", gr.update(visible=False)

def save_prompt_to_file(prompt_text):
    """Save the prompt to a text file and return the file path"""
    if not prompt_text or prompt_text.strip() == "":
        return None
    timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
    filename = f"ai_code_agent_prompt_{timestamp}.txt"

    with open(filename, "w", encoding="utf-8") as f:
        f.write("=" * 80 + "\n")
        f.write("AI CODE AGENT - WEBSITE DEVELOPMENT PROMPT\n")
        f.write(f"Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
        f.write("=" * 80 + "\n\n")
        f.write(prompt_text)
        f.write("\n\n" + "=" * 80 + "\n")
        f.write("Paste this prompt into your AI Code Agent to generate the website\n")
        f.write("Compatible with: Custom AI Code Agents, Cursor, Bolt.new, v0.dev, etc.\n")
        f.write("=" * 80 + "\n")

    return filename

# Custom CSS
custom_css = """
.container {max-width: 1200px; margin: auto; padding: 20px;}
.header {
    text-align: center;
    margin-bottom: 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 30px;
    border-radius: 15px;
    color: white;
}
.question-box {
    background: #f0f7ff;
    padding: 20px;
    border-radius: 10px;
    margin: 10px 0;
    border-left: 4px solid #667eea;
}
.status-box {
    background: #e8f5e9;
    padding: 15px;
    border-radius: 8px;
    margin: 10px 0;
    font-weight: 500;
}
.suggestion-box {
    background: #fff3e0;
    padding: 10px;
    border-radius: 5px;
    font-size: 0.9em;
    color: #e65100;
}
.download-btn {
    background: #4CAF50 !important;
}
.code-agent-badge {
    background: #667eea;
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.85em;
    display: inline-block;
    margin: 5px;
}
"""

# Build Interface
with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title="AI Code Agent Prompt Enhancer") as demo:
    gr.Markdown("""
# πŸš€ AI Code Agent Prompt Enhancer
### Transform Ideas into Professional AI Code Agent Prompts
Generate detailed, production-ready prompts optimized for AI code agent systems.

<div style="text-align: center; margin: 10px 0;">
    <span class="code-agent-badge">✨ TailwindCSS</span>
    <span class="code-agent-badge">🎨 Feather Icons</span>
    <span class="code-agent-badge">πŸ“± AOS Animations</span>
    <span class="code-agent-badge">🌟 Vanta.js</span>
    <span class="code-agent-badge">πŸ–ΌοΈ Static.photos</span>
</div>
""", elem_classes="header")

    with gr.Row():
        with gr.Column(scale=2):
            initial_prompt = gr.Textbox(
                label="πŸ’‘ Your Website Idea",
                placeholder="Example: 'Create a modern portfolio website for a photographer with gallery and contact form'",
                lines=3,
                info="Describe what kind of website you want to create"
            )
        with gr.Column(scale=1):
            start_btn = gr.Button(
                "🎯 Start Enhancement",
                variant="primary",
                size="lg"
            )

    status_text = gr.Markdown("πŸ‘† Enter your idea above and click 'Start Enhancement'", elem_classes="status-box")

    gr.Markdown("---")

    with gr.Row():
        with gr.Column():
            current_question = gr.Textbox(
                label="❓ Current Question",
                interactive=False,
                lines=2,
                elem_classes="question-box"
            )
            
            suggestion_text = gr.Textbox(
                label="πŸ’­ Suggestion",
                interactive=False,
                lines=2,
                elem_classes="suggestion-box"
            )
            
            answer_input = gr.Textbox(
                label="✍️ Your Answer",
                placeholder="Type your answer here...",
                lines=4,
                interactive=False
            )
            
            submit_btn = gr.Button(
                "Submit Answer ➑️",
                interactive=False,
                variant="primary"
            )

    gr.Markdown("---")

    with gr.Row():
        model_choice = gr.Dropdown(
            choices=AVAILABLE_MODELS,
            value=DEFAULT_MODEL,
            label="πŸ€– Select AI Model",
            info="Choose the model for prompt generation"
        )

    generate_btn = gr.Button(
        "✨ Generate AI Code Agent Prompt",
        variant="primary",
        size="lg",
        visible=False
    )

    enhanced_output = gr.Textbox(
        label="🎨 AI Code Agent Prompt (Ready to Use)",
        lines=30,
        show_copy_button=True,
        placeholder="Your AI code agent prompt will appear here...",
        info="Copy this prompt and paste it into your AI code agent system"
    )

    download_btn = gr.File(
        label="πŸ“₯ Download Prompt as Text File",
        visible=False
    )

    gr.Markdown("""
---
## πŸ“‹ How to Use

### Step 1: Create Your Prompt
1. **Enter Your Idea** - Describe your website concept
2. **Answer Questions** - Respond to guided questions (7 total)
3. **Generate Prompt** - Click to create your AI code agent prompt
4. **Download/Copy** - Save or copy the generated prompt

### Step 2: Use with AI Code Agent
1. **Copy the generated prompt**
2. **Paste into your AI code agent** (Cursor, Bolt.new, v0.dev, custom agents)
3. **Get production-ready code** with proper formatting

---

## 🎯 What You Get

βœ… **Clean, Professional Prompt** - No Q&A clutter, just specifications  
βœ… **AI Code Agent Format** - Uses TITLE_PAGE, UPDATE_PAGE, SEARCH/REPLACE blocks  
βœ… **TailwindCSS Integration** - Modern, responsive styling  
βœ… **Animation Ready** - AOS scroll animations + Vanta.js backgrounds  
βœ… **Icon System** - Feather Icons integrated  
βœ… **Image Placeholders** - Static.photos for all images  
βœ… **Production Ready** - Complete technical specifications  
βœ… **Downloadable** - Save for future use  

---

## πŸ”§ Compatible Systems

This tool generates prompts compatible with:
- ✨ **Custom AI Code Agents** (using the TITLE_PAGE/UPDATE_PAGE format)
- ✨ **Cursor AI** - Paste and generate
- ✨ **Bolt.new** - Direct integration
- ✨ **v0.dev** - Component generation
- ✨ **GitHub Copilot** - Enhanced context
- ✨ **Any LLM** - ChatGPT, Claude, Gemini

---

## πŸ“š Output Format

The generated prompts use a specific format for AI code agents:

### For New Websites:
```
<<<<<<< START_TITLE index.html >>>>>>> END_TITLE
```html
<!DOCTYPE html>
...complete HTML code...
```
```

### For Updates:
```
<<<<<<< UPDATE_PAGE_START index.html >>>>>>> UPDATE_PAGE_END
<<<<<<< SEARCH
    <h1>Old Content</h1>
=======
    <h1 class="text-4xl font-bold">New Content</h1>
>>>>>>> REPLACE
```

---

## πŸ’‘ Pro Tips

- πŸ“ Be specific in your answers for better results
- 🎨 Mention preferred colors, styles, and layouts
- πŸ“± Specify if you need mobile-first design
- πŸ”„ Indicate if updating existing code or creating new
- ⚑ The more detail you provide, the better the output

---

## πŸ› οΈ Technical Stack Included

Every generated prompt includes:
- **TailwindCSS** - Utility-first CSS framework
- **Feather Icons** - Beautiful icon set
- **AOS.js** - Scroll animation library
- **Vanta.js** - Animated backgrounds
- **Anime.js** - Advanced animations
- **Static.photos** - Professional placeholder images

---

Made with ❀️ for developers | Optimized for AI Code Agents
""")

    # Event Handlers
    start_btn.click(
        fn=start_process,
        inputs=[initial_prompt],
        outputs=[
            current_question,
            suggestion_text,
            answer_input,
            answer_input,
            submit_btn,
            generate_btn,
            status_text,
            enhanced_output,
            download_btn
        ]
    )

    submit_btn.click(
        fn=submit_answer,
        inputs=[answer_input],
        outputs=[
            current_question,
            suggestion_text,
            answer_input,
            answer_input,
            submit_btn,
            generate_btn,
            status_text,
            enhanced_output,
            download_btn
        ]
    )

    answer_input.submit(
        fn=submit_answer,
        inputs=[answer_input],
        outputs=[
            current_question,
            suggestion_text,
            answer_input,
            answer_input,
            submit_btn,
            generate_btn,
            status_text,
            enhanced_output,
            download_btn
        ]
    )

    generate_btn.click(
        fn=generate_final_prompt,
        inputs=[model_choice],
        outputs=[enhanced_output, status_text, download_btn]
    )

    enhanced_output.change(
        fn=save_prompt_to_file,
        inputs=[enhanced_output],
        outputs=[download_btn]
    )

if __name__ == "__main__":
    demo.launch()