GenscriptAI123 commited on
Commit
6a6a2f6
·
verified ·
1 Parent(s): ce60576

Update html_generator.py

Browse files
Files changed (1) hide show
  1. html_generator.py +36 -41
html_generator.py CHANGED
@@ -1,13 +1,11 @@
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:
@@ -19,7 +17,7 @@ except:
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>
@@ -37,10 +35,10 @@ def get_base_template(title, content, theme="light"):
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%;
@@ -48,7 +46,7 @@ def get_base_template(title, content, theme="light"):
48
  margin: 0 auto;
49
  padding: 0 20px;
50
  }}
51
-
52
  /* Navigation */
53
  header {{
54
  padding: 20px 0;
@@ -73,7 +71,7 @@ def get_base_template(title, content, theme="light"):
73
  .nav-links a:hover {{
74
  opacity: 0.8;
75
  }}
76
-
77
  /* Responsive design */
78
  @media (max-width: 768px) {{
79
  .hero-content {{
@@ -216,9 +214,9 @@ 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">
@@ -268,7 +266,7 @@ def generate_features_section(features=None):
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"""
@@ -277,7 +275,7 @@ def generate_features_section(features=None):
277
  <p>{feature['description']}</p>
278
  </div>
279
  """
280
-
281
  return f"""
282
  <section class="section" id="features">
283
  <div class="container">
@@ -294,35 +292,35 @@ def generate_pricing_section(plans=None):
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}
@@ -337,7 +335,7 @@ def generate_pricing_section(plans=None):
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">
@@ -358,7 +356,7 @@ def generate_testimonials_section(testimonials=None):
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"""
@@ -369,7 +367,7 @@ def generate_testimonials_section(testimonials=None):
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">
@@ -382,31 +380,28 @@ def generate_testimonials_section(testimonials=None):
382
  """
383
 
384
  def generate_contact_section():
385
-
386
  """Generate a contact section with a form"""
387
-
388
  return f"""
389
-
390
  <section class="section" id="contact" style="background-color: #f9fafb;">
391
-
392
  <div class="container">
393
-
394
  <h2 style="font-size: 2rem; text-align: center; margin-bottom: 40px;">Contact Us</h2>
395
-
396
  <form style="max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;">
397
-
398
  <input type="text" placeholder="Your Name" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
399
-
400
  <input type="email" placeholder="Your Email" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
401
-
402
  <textarea placeholder="Your Message" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px; height: 150px;"></textarea>
403
-
404
  <button type="submit" class="btn-primary" style="align-self: center;">Send Message</button>
405
-
406
  </form>
407
-
408
  </div>
409
-
410
  </section>
 
 
 
 
 
411
 
412
- """
 
 
 
 
 
 
 
1
  import random
2
  from transformers import pipeline
3
  import re
4
 
5
  # Initialize the text generation pipeline
 
6
  try:
7
  generator = pipeline('text-generation', model='gpt2')
8
+ except Exception as e:
9
  # Fallback for environments where Hugging Face models might not be available
10
  print("Warning: Using mock generator as fallback. Install transformers for full functionality.")
11
  class MockGenerator:
 
17
  def get_base_template(title, content, theme="light"):
18
  """Basic HTML template with proper structure and responsive meta tags"""
19
  css_theme = get_theme_css(theme)
20
+
21
  return f"""<!DOCTYPE html>
22
  <html lang="en">
23
  <head>
 
35
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
36
  line-height: 1.6;
37
  }}
38
+
39
  /* Theme styles */
40
  {css_theme}
41
+
42
  /* Responsive styles */
43
  .container {{
44
  width: 90%;
 
46
  margin: 0 auto;
47
  padding: 0 20px;
48
  }}
49
+
50
  /* Navigation */
51
  header {{
52
  padding: 20px 0;
 
71
  .nav-links a:hover {{
72
  opacity: 0.8;
73
  }}
74
+
75
  /* Responsive design */
76
  @media (max-width: 768px) {{
77
  .hero-content {{
 
214
  """Generate a navigation bar for the website"""
215
  if pages is None:
216
  pages = ["Home", "Features", "Pricing", "Contact"]
217
+
218
  links = "".join([f'<a href="#{page.lower()}">{page}</a>' for page in pages])
219
+
220
  return f"""
221
  <header>
222
  <div class="container">
 
266
  {"title": "Feature 2", "description": "Description of feature 2 and its benefits."},
267
  {"title": "Feature 3", "description": "Description of feature 3 and its benefits."}
268
  ]
269
+
270
  feature_cards = ""
271
  for feature in features:
272
  feature_cards += f"""
 
275
  <p>{feature['description']}</p>
276
  </div>
277
  """
278
+
279
  return f"""
280
  <section class="section" id="features">
281
  <div class="container">
 
292
  if plans is None:
293
  plans = [
294
  {
295
+ "name": "Basic",
296
+ "price": "$9.99",
297
+ "period": "month",
298
  "features": ["Feature 1", "Feature 2", "Email Support"],
299
  "highlighted": False
300
  },
301
  {
302
+ "name": "Pro",
303
+ "price": "$19.99",
304
+ "period": "month",
305
  "features": ["All Basic features", "Feature 3", "Feature 4", "Priority Support"],
306
  "highlighted": True
307
  },
308
  {
309
+ "name": "Enterprise",
310
+ "price": "$49.99",
311
+ "period": "month",
312
  "features": ["All Pro features", "Feature 5", "Feature 6", "24/7 Support", "Custom Integration"],
313
  "highlighted": False
314
  }
315
  ]
316
+
317
  pricing_cards = ""
318
  for plan in plans:
319
  highlight_style = "transform: scale(1.05);" if plan["highlighted"] else ""
320
  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 ""
321
+
322
  features_list = "".join([f'<li style="margin-bottom: 10px;">{feature}</li>' for feature in plan["features"]])
323
+
324
  pricing_cards += f"""
325
  <div class="pricing-card card" style="padding: 30px; position: relative; {highlight_style}">
326
  {highlight_badge}
 
335
  <a href="#contact" class="btn-primary" style="display: block; text-align: center; text-decoration: none;">Choose Plan</a>
336
  </div>
337
  """
338
+
339
  return f"""
340
  <section class="section" id="pricing" style="background-color: #f9fafb;">
341
  <div class="container">
 
356
  {"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."},
357
  {"name": "Mike Johnson", "position": "Freelancer", "text": "As someone who works independently, this tool has saved me countless hours of work."}
358
  ]
359
+
360
  testimonial_cards = ""
361
  for testimonial in testimonials:
362
  testimonial_cards += f"""
 
367
  <div style="font-size: 0.9rem; color: #6b7280;">{testimonial['position']}</div>
368
  </div>
369
  """
370
+
371
  return f"""
372
  <section class="section" id="testimonials">
373
  <div class="container">
 
380
  """
381
 
382
  def generate_contact_section():
 
383
  """Generate a contact section with a form"""
 
384
  return f"""
 
385
  <section class="section" id="contact" style="background-color: #f9fafb;">
 
386
  <div class="container">
 
387
  <h2 style="font-size: 2rem; text-align: center; margin-bottom: 40px;">Contact Us</h2>
 
388
  <form style="max-width: 600px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px;">
 
389
  <input type="text" placeholder="Your Name" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
 
390
  <input type="email" placeholder="Your Email" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px;">
 
391
  <textarea placeholder="Your Message" style="padding: 10px; border: 1px solid #d1d5db; border-radius: 4px; height: 150px;"></textarea>
 
392
  <button type="submit" class="btn-primary" style="align-self: center;">Send Message</button>
 
393
  </form>
 
394
  </div>
 
395
  </section>
396
+ """
397
+
398
+ def generate_website_html(title, sections):
399
+ """
400
+ Generate the complete HTML for a website.
401
 
402
+ :param title: The title of the website.
403
+ :param sections: A list of HTML sections to include in the body.
404
+ :return: A complete HTML string.
405
+ """
406
+ content = "".join(sections)
407
+ return get_base_template(title, content, theme="light")