GenscriptAI123 commited on
Commit
27e73c2
·
verified ·
1 Parent(s): 7bd68c2

Create html.py

Browse files
Files changed (1) hide show
  1. html.py +398 -0
html.py ADDED
@@ -0,0 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # html_generator.py
2
+ import random
3
+ from transformers import pipeline
4
+ import re
5
+
6
+ # Initialize the text generation pipeline
7
+ # Note: In a real implementation, you might want to use a specific model that's better suited for HTML generation
8
+ try:
9
+ generator = pipeline('text-generation', model='gpt2')
10
+ except:
11
+ # Fallback for environments where Hugging Face models might not be available
12
+ print("Warning: Using mock generator as fallback. Install transformers for full functionality.")
13
+ class MockGenerator:
14
+ def __call__(self, prompt, max_length=100, num_return_sequences=1):
15
+ return [{"generated_text": prompt + " (This is a mock generation)"}]
16
+ generator = MockGenerator()
17
+
18
+ # Basic HTML templates
19
+ def get_base_template(title, content, theme="light"):
20
+ """Basic HTML template with proper structure and responsive meta tags"""
21
+ css_theme = get_theme_css(theme)
22
+
23
+ return f"""<!DOCTYPE html>
24
+ <html lang="en">
25
+ <head>
26
+ <meta charset="UTF-8">
27
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
28
+ <title>{title}</title>
29
+ <style>
30
+ /* Reset and base styles */
31
+ * {{
32
+ margin: 0;
33
+ padding: 0;
34
+ box-sizing: border-box;
35
+ }}
36
+ body {{
37
+ font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
38
+ line-height: 1.6;
39
+ }}
40
+
41
+ /* Theme styles */
42
+ {css_theme}
43
+
44
+ /* Responsive styles */
45
+ .container {{
46
+ width: 90%;
47
+ max-width: 1200px;
48
+ margin: 0 auto;
49
+ padding: 0 20px;
50
+ }}
51
+
52
+ /* Navigation */
53
+ header {{
54
+ padding: 20px 0;
55
+ }}
56
+ .navbar {{
57
+ display: flex;
58
+ justify-content: space-between;
59
+ align-items: center;
60
+ }}
61
+ .logo {{
62
+ font-size: 1.5rem;
63
+ font-weight: 700;
64
+ }}
65
+ .nav-links {{
66
+ display: flex;
67
+ gap: 20px;
68
+ }}
69
+ .nav-links a {{
70
+ text-decoration: none;
71
+ transition: opacity 0.2s;
72
+ }}
73
+ .nav-links a:hover {{
74
+ opacity: 0.8;
75
+ }}
76
+
77
+ /* Responsive design */
78
+ @media (max-width: 768px) {{
79
+ .hero-content {{
80
+ flex-direction: column;
81
+ }}
82
+ .hero-text, .hero-image {{
83
+ width: 100%;
84
+ }}
85
+ .feature-grid {{
86
+ grid-template-columns: 1fr;
87
+ }}
88
+ .nav-links {{
89
+ display: none;
90
+ }}
91
+ .mobile-menu-btn {{
92
+ display: block;
93
+ }}
94
+ }}
95
+ </style>
96
+ </head>
97
+ <body>
98
+ {content}
99
+ </body>
100
+ </html>"""
101
+
102
+ def get_theme_css(theme):
103
+ """Generate CSS based on the selected theme"""
104
+ themes = {
105
+ "light": """
106
+ body {
107
+ background-color: #ffffff;
108
+ color: #333333;
109
+ }
110
+ a {
111
+ color: #3b82f6;
112
+ }
113
+ .btn-primary {
114
+ background-color: #3b82f6;
115
+ color: white;
116
+ border: none;
117
+ padding: 10px 20px;
118
+ border-radius: 4px;
119
+ cursor: pointer;
120
+ transition: all 0.2s ease;
121
+ }
122
+ .btn-primary:hover {
123
+ background-color: #2563eb;
124
+ }
125
+ .section {
126
+ padding: 60px 0;
127
+ }
128
+ .hero {
129
+ background-color: #f9fafb;
130
+ }
131
+ .card {
132
+ background-color: #ffffff;
133
+ border-radius: 8px;
134
+ box-shadow: 0 4px 6px rgba(0,0,0,0.05);
135
+ }
136
+ """,
137
+ "dark": """
138
+ body {
139
+ background-color: #121212;
140
+ color: #e0e0e0;
141
+ }
142
+ a {
143
+ color: #90caf9;
144
+ }
145
+ .btn-primary {
146
+ background-color: #90caf9;
147
+ color: #121212;
148
+ border: none;
149
+ padding: 10px 20px;
150
+ border-radius: 4px;
151
+ cursor: pointer;
152
+ transition: all 0.2s ease;
153
+ }
154
+ .btn-primary:hover {
155
+ background-color: #64b5f6;
156
+ }
157
+ .section {
158
+ padding: 60px 0;
159
+ }
160
+ .hero {
161
+ background-color: #1e1e1e;
162
+ }
163
+ .card {
164
+ background-color: #1e1e1e;
165
+ border-radius: 8px;
166
+ box-shadow: 0 4px 6px rgba(0,0,0,0.2);
167
+ }
168
+ """,
169
+ "colorful": """
170
+ body {
171
+ background-color: #ffffff;
172
+ color: #333333;
173
+ }
174
+ a {
175
+ color: #8b5cf6;
176
+ }
177
+ .btn-primary {
178
+ background-color: #8b5cf6;
179
+ color: white;
180
+ border: none;
181
+ padding: 10px 20px;
182
+ border-radius: 4px;
183
+ cursor: pointer;
184
+ transition: all 0.3s ease;
185
+ }
186
+ .btn-primary:hover {
187
+ background-color: #7c3aed;
188
+ transform: translateY(-2px);
189
+ }
190
+ .section {
191
+ padding: 60px 0;
192
+ }
193
+ .hero {
194
+ background: linear-gradient(135deg, #c084fc, #8b5cf6);
195
+ color: white;
196
+ }
197
+ .card {
198
+ background-color: #ffffff;
199
+ border-radius: 8px;
200
+ box-shadow: 0 10px 15px rgba(0,0,0,0.1);
201
+ border-top: 4px solid #8b5cf6;
202
+ transition: transform 0.3s ease;
203
+ }
204
+ .card:hover {
205
+ transform: translateY(-5px);
206
+ }
207
+ .accent {
208
+ color: #f472b6;
209
+ }
210
+ """
211
+ }
212
+ return themes.get(theme.lower(), themes["light"])
213
+
214
+ # Website section templates
215
+ def generate_navbar(site_name, pages=None):
216
+ """Generate a navigation bar for the website"""
217
+ if pages is None:
218
+ pages = ["Home", "Features", "Pricing", "Contact"]
219
+
220
+ links = "".join([f'<a href="#{page.lower()}">{page}</a>' for page in pages])
221
+
222
+ return f"""
223
+ <header>
224
+ <div class="container">
225
+ <nav class="navbar">
226
+ <div class="logo">{site_name}</div>
227
+ <div class="nav-links">
228
+ {links}
229
+ </div>
230
+ <div class="mobile-menu-btn" style="display: none; cursor: pointer;">
231
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
232
+ <line x1="3" y1="12" x2="21" y2="12"></line>
233
+ <line x1="3" y1="6" x2="21" y2="6"></line>
234
+ <line x1="3" y1="18" x2="21" y2="18"></line>
235
+ </svg>
236
+ </div>
237
+ </nav>
238
+ </div>
239
+ </header>
240
+ """
241
+
242
+ def generate_hero_section(title, subtitle, cta="Get Started"):
243
+ """Generate a hero section with a call to action"""
244
+ return f"""
245
+ <section class="hero" id="home">
246
+ <div class="container">
247
+ <div class="hero-content" style="display: flex; align-items: center; gap: 40px; padding: 60px 0;">
248
+ <div class="hero-text" style="flex: 1;">
249
+ <h1 style="font-size: 3rem; font-weight: 800; margin-bottom: 20px;">{title}</h1>
250
+ <p style="font-size: 1.2rem; margin-bottom: 30px;">{subtitle}</p>
251
+ <a href="#contact" class="btn-primary" style="display: inline-block; text-decoration: none;">{cta}</a>
252
+ </div>
253
+ <div class="hero-image" style="flex: 1;">
254
+ <div style="background-color: #e5e7eb; height: 300px; border-radius: 8px; display: flex; align-items: center; justify-content: center;">
255
+ <span style="color: #9ca3af;">Hero Image Placeholder</span>
256
+ </div>
257
+ </div>
258
+ </div>
259
+ </div>
260
+ </section>
261
+ """
262
+
263
+ def generate_features_section(features=None):
264
+ """Generate a features section with cards"""
265
+ if features is None:
266
+ features = [
267
+ {"title": "Feature 1", "description": "Description of feature 1 and its benefits."},
268
+ {"title": "Feature 2", "description": "Description of feature 2 and its benefits."},
269
+ {"title": "Feature 3", "description": "Description of feature 3 and its benefits."}
270
+ ]
271
+
272
+ feature_cards = ""
273
+ for feature in features:
274
+ feature_cards += f"""
275
+ <div class="feature-card card" style="padding: 30px; margin-bottom: 20px;">
276
+ <h3 style="font-size: 1.5rem; margin-bottom: 15px;">{feature['title']}</h3>
277
+ <p>{feature['description']}</p>
278
+ </div>
279
+ """
280
+
281
+ return f"""
282
+ <section class="section" id="features">
283
+ <div class="container">
284
+ <h2 style="font-size: 2rem; text-align: center; margin-bottom: 40px;">Features</h2>
285
+ <div class="feature-grid" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px;">
286
+ {feature_cards}
287
+ </div>
288
+ </div>
289
+ </section>
290
+ """
291
+
292
+ def generate_pricing_section(plans=None):
293
+ """Generate a pricing section with different plans"""
294
+ if plans is None:
295
+ plans = [
296
+ {
297
+ "name": "Basic",
298
+ "price": "$9.99",
299
+ "period": "month",
300
+ "features": ["Feature 1", "Feature 2", "Email Support"],
301
+ "highlighted": False
302
+ },
303
+ {
304
+ "name": "Pro",
305
+ "price": "$19.99",
306
+ "period": "month",
307
+ "features": ["All Basic features", "Feature 3", "Feature 4", "Priority Support"],
308
+ "highlighted": True
309
+ },
310
+ {
311
+ "name": "Enterprise",
312
+ "price": "$49.99",
313
+ "period": "month",
314
+ "features": ["All Pro features", "Feature 5", "Feature 6", "24/7 Support", "Custom Integration"],
315
+ "highlighted": False
316
+ }
317
+ ]
318
+
319
+ pricing_cards = ""
320
+ for plan in plans:
321
+ highlight_style = "transform: scale(1.05);" if plan["highlighted"] else ""
322
+ highlight_badge = '<div style="position: absolute; top: -10px; right: -10px; background-color: #f97316; color: white; padding: 5px 10px; border-radius: 20px; font-size: 0.8rem;">Popular</div>' if plan["highlighted"] else ""
323
+
324
+ features_list = "".join([f'<li style="margin-bottom: 10px;">{feature}</li>' for feature in plan["features"]])
325
+
326
+ pricing_cards += f"""
327
+ <div class="pricing-card card" style="padding: 30px; position: relative; {highlight_style}">
328
+ {highlight_badge}
329
+ <h3 style="font-size: 1.5rem; margin-bottom: 10px;">{plan['name']}</h3>
330
+ <div style="font-size: 2.5rem; font-weight: 700; margin-bottom: 20px;">
331
+ {plan['price']}
332
+ <span style="font-size: 1rem; font-weight: 400; color: #6b7280;">/{plan['period']}</span>
333
+ </div>
334
+ <ul style="list-style-type: none; margin-bottom: 30px;">
335
+ {features_list}
336
+ </ul>
337
+ <a href="#contact" class="btn-primary" style="display: block; text-align: center; text-decoration: none;">Choose Plan</a>
338
+ </div>
339
+ """
340
+
341
+ return f"""
342
+ <section class="section" id="pricing" style="background-color: #f9fafb;">
343
+ <div class="container">
344
+ <h2 style="font-size: 2rem; text-align: center; margin-bottom: 20px;">Pricing</h2>
345
+ <p style="text-align: center; margin-bottom: 40px; max-width: 600px; margin-left: auto; margin-right: auto;">Choose the perfect plan for your needs. All plans include our core features with different levels of support and additional functionalities.</p>
346
+ <div class="pricing-grid" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px;">
347
+ {pricing_cards}
348
+ </div>
349
+ </div>
350
+ </section>
351
+ """
352
+
353
+ def generate_testimonials_section(testimonials=None):
354
+ """Generate a testimonials section"""
355
+ if testimonials is None:
356
+ testimonials = [
357
+ {"name": "John Doe", "position": "CEO, Company A", "text": "This product has completely transformed how we operate our business. Highly recommended!"},
358
+ {"name": "Jane Smith", "position": "Marketing Director, Company B", "text": "The features and ease of use have made this an essential tool in our daily operations."},
359
+ {"name": "Mike Johnson", "position": "Freelancer", "text": "As someone who works independently, this tool has saved me countless hours of work."}
360
+ ]
361
+
362
+ testimonial_cards = ""
363
+ for testimonial in testimonials:
364
+ testimonial_cards += f"""
365
+ <div class="testimonial-card card" style="padding: 30px; text-align: center;">
366
+ <div style="font-size: 2rem; color: #d1d5db; margin-bottom: 20px;">"</div>
367
+ <p style="margin-bottom: 20px;">{testimonial['text']}</p>
368
+ <div style="font-weight: 600;">{testimonial['name']}</div>
369
+ <div style="font-size: 0.9rem; color: #6b7280;">{testimonial['position']}</div>
370
+ </div>
371
+ """
372
+
373
+ return f"""
374
+ <section class="section" id="testimonials">
375
+ <div class="container">
376
+ <h2 style="font-size: 2rem; text-align: center; margin-bottom: 40px;">What Our Customers Say</h2>
377
+ <div class="testimonials-grid" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px;">
378
+ {testimonial_cards}
379
+ </div>
380
+ </div>
381
+ </section>
382
+ """
383
+
384
+ def generate_contact_section():
385
+ """Generate a contact section with a form"""
386
+ return f"""
387
+ <section class="section" id="contact" style="background-color: #f9fafb;">
388
+ <div class="container">
389
+ <h2 style="font-size: 2rem; text-align: center; margin-bottom: 40px;">Contact Us</h2>
390
+ <form style="max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;">
391
+ <input type="text" placeholder="Your Name" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
392
+ <input type="email" placeholder="Your Email" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
393
+ <textarea placeholder="Your Message" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px; height: 150px;"></textarea>
394
+ <button type="submit" class="btn-primary" style="align-self: center;">Send Message</button>
395
+ </form>
396
+ </div>
397
+ </section>
398
+ """