File size: 9,778 Bytes
f5b2d87
 
95dc4b4
f5b2d87
 
95dc4b4
f5b2d87
95dc4b4
f5b2d87
95dc4b4
f5b2d87
95dc4b4
 
 
 
 
f5b2d87
 
 
 
 
 
 
95dc4b4
f5b2d87
 
95dc4b4
 
f5b2d87
 
 
 
 
95dc4b4
 
 
 
 
 
 
f5b2d87
 
 
 
95dc4b4
f5b2d87
95dc4b4
 
f5b2d87
95dc4b4
 
f5b2d87
95dc4b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5b2d87
 
 
95dc4b4
 
 
f5b2d87
95dc4b4
f5b2d87
 
95dc4b4
f5b2d87
95dc4b4
 
 
 
 
 
 
 
 
 
 
 
 
 
f5b2d87
95dc4b4
 
f5b2d87
 
95dc4b4
f5b2d87
 
 
95dc4b4
f5b2d87
 
 
 
95dc4b4
 
f5b2d87
 
 
 
 
95dc4b4
 
 
 
 
f5b2d87
 
95dc4b4
f5b2d87
 
 
95dc4b4
f5b2d87
95dc4b4
f5b2d87
 
 
 
 
 
 
 
95dc4b4
 
 
 
f5b2d87
 
 
95dc4b4
f5b2d87
 
95dc4b4
f5b2d87
 
 
95dc4b4
f5b2d87
95dc4b4
 
f5b2d87
 
95dc4b4
 
 
f5b2d87
95dc4b4
 
 
 
 
f5b2d87
95dc4b4
 
 
 
 
 
 
 
 
 
 
 
 
f5b2d87
95dc4b4
 
f5b2d87
95dc4b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5b2d87
 
 
95dc4b4
 
 
f5b2d87
 
 
 
95dc4b4
 
 
 
f5b2d87
 
 
95dc4b4
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
import gradio as gr
import json
from datetime import datetime
import base64
import tempfile
import os
from fpdf import FPDF
from PIL import Image

# Simple template presets
TEMPLATE_PRESETS = {
    "Weekly Planner": "A4 weekly planner, portrait orientation, Monday start, 7 columns, notes section",
    "Monthly Calendar": "A4 monthly calendar, landscape orientation, large date boxes, clean design", 
    "Daily Schedule": "A4 daily planner, hourly time slots, priority tasks section",
    "Habit Tracker": "A4 habit tracker, 30-day grid, progress tracking",
    "Study Planner": "A4 study schedule, subject blocks, assignment tracker"
}

# Color schemes
COLOR_SCHEMES = {
    "Professional Blue": {"primary": "#2563EB", "secondary": "#1E40AF", "accent": "#3B82F6"},
    "Forest Green": {"primary": "#059669", "secondary": "#047857", "accent": "#10B981"},
    "Sunset Orange": {"primary": "#EA580C", "secondary": "#C2410C", "accent": "#FB923C"},
    "Royal Purple": {"primary": "#7C3AED", "secondary": "#5B21B6", "accent": "#8B5CF6"}
}

class SimplePDF(FPDF):
    def __init__(self, title="My Planner", colors=None):
        super().__init__()
        self.title_text = title
        self.colors = colors or COLOR_SCHEMES["Professional Blue"]
        
    def header(self):
        self.set_font('Arial', 'B', 16)
        # Convert hex to RGB
        primary_rgb = tuple(int(self.colors["primary"][1:][i:i+2], 16) for i in (0, 2, 4))
        self.set_text_color(*primary_rgb)
        self.cell(0, 10, self.title_text, 0, 1, 'C')
        self.ln(10)
        
    def footer(self):
        self.set_y(-15)
        self.set_font('Arial', 'I', 8)
        self.set_text_color(128, 128, 128)
        self.cell(0, 10, f'Generated on {datetime.now().strftime("%Y-%m-%d")}', 0, 0, 'C')

def create_simple_template(prompt, title, color_scheme):
    """Create a simple template based on user input"""
    try:
        # Get colors
        colors = COLOR_SCHEMES.get(color_scheme, COLOR_SCHEMES["Professional Blue"])
        
        # Create HTML preview
        html_content = f"""
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <title>{title}</title>
            <style>
                body {{
                    font-family: Arial, sans-serif;
                    margin: 20px;
                    color: #333;
                }}
                .header {{
                    text-align: center;
                    color: {colors['primary']};
                    border-bottom: 3px solid {colors['primary']};
                    padding-bottom: 15px;
                    margin-bottom: 30px;
                }}
                .title {{
                    font-size: 24px;
                    font-weight: bold;
                    margin: 0;
                }}
                .subtitle {{
                    font-size: 14px;
                    color: {colors['secondary']};
                    margin: 5px 0;
                }}
                .grid {{
                    display: grid;
                    grid-template-columns: repeat(7, 1fr);
                    gap: 2px;
                    border: 2px solid {colors['primary']};
                    margin: 20px 0;
                }}
                .grid-header {{
                    background: {colors['primary']};
                    color: white;
                    padding: 10px;
                    text-align: center;
                    font-weight: bold;
                }}
                .grid-cell {{
                    border: 1px solid {colors['accent']};
                    min-height: 80px;
                    padding: 8px;
                    background: #fafafa;
                }}
                .notes {{
                    margin-top: 30px;
                    padding: 20px;
                    background: #f8f9fa;
                    border-left: 5px solid {colors['accent']};
                }}
            </style>
        </head>
        <body>
            <div class="header">
                <h1 class="title">{title}</h1>
                <p class="subtitle">Generated on {datetime.now().strftime('%B %d, %Y')}</p>
            </div>
            
            <div class="grid">
        """
        
        # Add grid headers and cells
        days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
        for day in days:
            html_content += f'<div class="grid-header">{day}</div>'
        
        # Add grid cells (4 weeks)
        for i in range(28):
            html_content += f'<div class="grid-cell"><strong>{i+1}</strong></div>'
            
        html_content += f"""
            </div>
            
            <div class="notes">
                <h3 style="color: {colors['primary']}; margin-top: 0;">Notes & Reminders</h3>
                <div style="height: 100px; background: white; border: 1px solid #ddd; padding: 10px;"></div>
            </div>
        </body>
        </html>
        """
        
        # Create PDF
        pdf = SimplePDF(title=title, colors=colors)
        pdf.add_page()
        
        # Add content
        pdf.set_font('Arial', '', 12)
        pdf.set_text_color(0, 0, 0)
        
        # Simple grid for PDF
        y_start = 50
        cell_width = 25
        cell_height = 20
        
        # Draw weekly grid
        for row in range(5):
            for col in range(7):
                x = 10 + (col * cell_width)
                y = y_start + (row * cell_height)
                pdf.rect(x, y, cell_width, cell_height)
                
                if row == 0:  # Headers
                    pdf.set_xy(x + 1, y + 1)
                    pdf.set_font('Arial', 'B', 8)
                    pdf.cell(cell_width-2, cell_height-2, days[col][:3], 0, 0, 'C')
                    pdf.set_font('Arial', '', 8)
        
        # Add notes section
        pdf.set_xy(10, y_start + 120)
        pdf.set_font('Arial', 'B', 14)
        primary_rgb = tuple(int(colors["primary"][1:][i:i+2], 16) for i in (0, 2, 4))
        pdf.set_text_color(*primary_rgb)
        pdf.cell(0, 10, 'Notes & Important Reminders', 0, 1, 'L')
        
        # Save PDF
        temp_dir = "temp_outputs"
        os.makedirs(temp_dir, exist_ok=True)
        pdf_path = os.path.join(temp_dir, f"template_{datetime.now().strftime('%Y%m%d_%H%M%S')}.pdf")
        pdf.output(pdf_path)
        
        success_msg = f"""
        <div style='padding: 20px; background: #f0f9ff; border-left: 4px solid {colors['primary']};'>
            <h3 style='color: {colors['primary']}; margin-top: 0;'>✅ Template Generated Successfully!</h3>
            <p><strong>Title:</strong> {title}</p>
            <p><strong>Description:</strong> {prompt}</p>
            <p><strong>Color Scheme:</strong> {color_scheme}</p>
            <p><strong>Generated at:</strong> {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}</p>
        </div>
        """
        
        return html_content, pdf_path, success_msg
        
    except Exception as e:
        error_msg = f"<div style='color: red; padding: 20px;'>❌ Error: {str(e)}</div>"
        return error_msg, None, f"Error details: {str(e)}"

# Create Gradio interface
with gr.Blocks(title="🎨 AI Template Generator", theme=gr.themes.Default()) as demo:
    gr.Markdown("""
    # 🎨 AI Template Generator
    ### Create Beautiful Planners & Templates with AI
    """)
    
    with gr.Row():
        with gr.Column(scale=2):
            gr.Markdown("### 📝 Template Description")
            
            template_preset = gr.Dropdown(
                choices=["Custom"] + list(TEMPLATE_PRESETS.keys()),
                value="Weekly Planner",
                label="🔧 Quick Presets"
            )
            
            prompt_input = gr.Textbox(
                label="📋 Describe Your Template",
                placeholder="Describe what kind of planner you need...",
                lines=3,
                value=TEMPLATE_PRESETS["Weekly Planner"]
            )
            
            def update_prompt(preset):
                if preset and preset != "Custom":
                    return TEMPLATE_PRESETS[preset]
                return ""
            
            template_preset.change(update_prompt, template_preset, prompt_input)
        
        with gr.Column(scale=1):
            gr.Markdown("### 🎨 Customization")
            
            title_input = gr.Textbox(
                label="📌 Template Title",
                placeholder="My Planner",
                value="My Weekly Planner"
            )
            
            color_scheme = gr.Dropdown(
                choices=list(COLOR_SCHEMES.keys()),
                value="Professional Blue",
                label="🌈 Color Scheme"
            )
    
    generate_btn = gr.Button("🚀 Generate Template", variant="primary", size="lg")
    
    with gr.Row():
        with gr.Column(scale=2):
            preview_output = gr.HTML(label="📋 Template Preview")
        
        with gr.Column(scale=1):
            download_output = gr.File(label="📥 Download PDF")
            status_output = gr.HTML(label="📊 Generation Status")
    
    # Connect the generate button
    generate_btn.click(
        create_simple_template,
        inputs=[prompt_input, title_input, color_scheme],
        outputs=[preview_output, download_output, status_output]
    )
    
    gr.Markdown("""
    ---
    ### 💡 Tips:
    - **Be specific**: Mention size (A4), orientation (portrait/landscape)
    - **Include details**: Time ranges, number of columns, special sections
    - **Try presets**: Use quick presets as starting points
    """)

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