-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemes.py
1687 lines (1501 loc) · 63.9 KB
/
themes.py
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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import datetime
from llama_index.core import VectorStoreIndex, Document
from llama_index.core.output_parsers import LangchainOutputParser
from llama_index.llms.together import TogetherLLM
from llama_index.embeddings.together import TogetherEmbedding
from langchain.output_parsers import StructuredOutputParser, ResponseSchema
import json, os
import base64
from together.error import AuthenticationError
from together import Together
from langchain_core.exceptions import OutputParserException
def generate_image(prompt, filename):
# Directly use the API key instead of getting it from environment variables
api_key = "fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
try:
client = Together(api_key=api_key)
response = client.images.generate(
prompt=prompt,
model="SG161222/Realistic_Vision_V3.0_VAE",
width=1024,
height=1024,
steps=30,
n=1,
seed=-1
)
# Decode the base64 image and save it
img_data = base64.b64decode(response.data[0].b64_json)
golo =f"./static/generated/{filename}"
with open(golo, 'wb') as f:
f.write(img_data)
return golo
except AuthenticationError as e:
print(f"Authentication Error: {e}")
print("Please check your API key and ensure it's correct.")
return None
except Exception as e:
print(f"An error occurred while generating the image: {e}")
return None
import re
def get_youtube_embed_url(url):
# Regular expression to match YouTube video IDs
pattern = r'(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)'
# Extract the video ID
match = re.search(pattern, url)
if match:
video_id = match.group(1)
# Construct the embed URL
embed_url = f'https://www.youtube.com/embed/{video_id}'
return embed_url
else:
return None
def generate_content(doc_content, template='future', author='Anonymous', style='default', youtube_url="https://www.youtube.com/watch?v=dQw4w9WgXcQ"):
template = template.lower()
#EMBEDDED VERSION
youtube_url = get_youtube_embed_url(youtube_url)
if template == "future":
document = Document(text=doc_content)
embed_model = TogetherEmbedding(
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
index = VectorStoreIndex.from_documents([document], embed_model=embed_model)
response_schemas = [
ResponseSchema(name="title", description="The main title of the blog post"),
ResponseSchema(name="subtitle", description="A brief description or tagline for the blog post"),
ResponseSchema(name="introduction", description="An introductory paragraph for the blog post"),
ResponseSchema(name="main_points", description="A list of 5 main points or sections of the blog post, each explained in about 100 words"),
ResponseSchema(name="conclusion", description="A concluding paragraph for the blog post"),
ResponseSchema(name="image_descriptions", description="Descriptions for five images related to the content")
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
llm = TogetherLLM(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
query_engine = index.as_query_engine(
llm=llm,
output_parser=LangchainOutputParser(output_parser),
)
response = query_engine.query(f"""Create a detailed and comprehensive blog post based on the given content.
The blog post should be at least 2000 words long, with 5 main points.
Provide in-depth explanations and examples for each point.
{format_instructions}""")
try:
parsed_output = output_parser.parse(response.response)
except json.JSONDecodeError as e:
print(f"Error parsing JSON: {e}")
print(f"Raw response: {response.response}")
# Fallback to default values
parsed_output = {
"title": "Blog Post",
"subtitle": "An interesting read",
"introduction": "This is an introduction to the topic...",
"main_points": ["Point 1", "Point 2", "Point 3", "Point 4", "Point 5"],
"conclusion": "In conclusion...",
"image_descriptions": ["A relevant image", "Another relevant image", "A third relevant image", "A fourth relevant image", "A fifth relevant image"]
}
print(parsed_output)
# Generate images
images = []
for i, desc in enumerate(parsed_output["image_descriptions"]):
print(desc)
for i, desc in enumerate(parsed_output["image_descriptions"]):
images.append(generate_image(desc, f"blog_image_{i}.png"))
# Create mini posts content
mini_posts = ''.join([f'''
<article class="mini-post">
<header>
<h3><a href="#">{point[:30]}...</a></h3>
<time class="published" datetime="{datetime.date.today().isoformat()}">{datetime.date.today().strftime('%B %d, %Y')}</time>
<a href="#" class="author"><img src=".{images[i+1]}" alt="" /></a>
</header>
<a href="#" class="image"><img src=".{images[i+1]}" alt="" /></a>
</article>
''' for i, point in enumerate(parsed_output['main_points'][:4])])
html_content = f"""
<!DOCTYPE HTML>
<html>
<style>
</style>
<head>
<title>{parsed_output['title']}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<h1><a href="index.html">{parsed_output['title']}</a></h1>
<nav class="links">
<ul>
<li><a href="#intro">Intro</a></li>
<li><a href="#main-points">Main Points</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</nav>
</header>
<!-- Main -->
<div id="main">
<!-- Post -->
<article class="post">
<header>
<div class="title">
<h2>{parsed_output['title']}</h2>
<p>{parsed_output['subtitle']}</p>
</div>
<div class="meta">
<time class="published" datetime="{datetime.date.today().isoformat()}">{datetime.date.today().strftime('%B %d, %Y')}</time>
<a href="#" class="author"><span class="name">{author}</span><img src=".{images[0]}" alt="" /></a>
</div>
</header>
<a href="#" class="image featured"><img src=".{images[0]}" alt="" /></a>
<section id="intro">
<h3>Introduction</h3>
<p>{parsed_output['introduction']}</p>
</section>
<section id="main-points">
<h3>Main Points</h3>
{' '.join(f'<div><h4>Point {i+1}</h4><p>{point}</p></div>' for i, point in enumerate(parsed_output['main_points']))}
</section>
<section id="conclusion">
<h3>Conclusion</h3>
<p>{parsed_output['conclusion']}</p>
</section>
<section>
<iframe position: relative; width="560" height="315" src={youtube_url}
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe>
</section>
</article>
</div>
<!-- Sidebar -->
<section id="sidebar">
<!-- Intro -->
<section id="intro">
<a href="#" class="logo"><img src=".{images[0]}" alt="" /></a>
<header>
<h2>{parsed_output['title']}</h2>
<p>{parsed_output['subtitle']}</p>
</header>
</section>
<!-- Mini Posts -->
<section>
<div class="mini-posts">
{mini_posts}
</div>
</section>
<!-- About -->
<section class="blurb">
<h2>About</h2>
<p>{parsed_output['introduction'][:100]}...</p>
<ul class="actions">
<li><a href="#" class="button">Learn More</a></li>
</ul>
</section>
<!-- Footer -->
<section id="footer">
<p class="copyright">© {datetime.date.today().year} {author}. All rights reserved.</p>
</section>
</section>
</div>
</body>
</html>
"""
return html_content
elif template == 'editorial':
document = Document(text=doc_content)
embed_model = TogetherEmbedding(
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
index = VectorStoreIndex.from_documents([document], embed_model=embed_model)
response_schemas = [
ResponseSchema(name="title", description="The main title of the blog post"),
ResponseSchema(name="introduction", description="A brief introduction to the blog post"),
ResponseSchema(name="subheading", description="Sub heading for the blog post"),
ResponseSchema(name="subtitle", description="A brief description or tagline for the blog post"),
ResponseSchema(name="content", description="The main content of the blog post, as a list of 4 text sections"),
ResponseSchema(name="image_descriptions", description="Descriptions for 4 images related to the content, as a list of strings")
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
llm = TogetherLLM(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
query_engine = index.as_query_engine(
llm=llm,
output_parser=LangchainOutputParser(output_parser),
)
response = query_engine.query(f"""Create a detailed and comprehensive blog post based on the given content.
The blog post should be at least 2000 words long, with 5 main points.
Provide in-depth explanations and examples for each point.
{format_instructions}""")
try:
parsed_output = output_parser.parse(response.response)
except OutputParserException as e:
print(f"Error parsing output: {e}")
# Provide default values
parsed_output = {
"title": "A Guide to Starting a Career in Tech",
"intrdocution":"introduction about the blog",
"subheading": "this can be a subheading for the blog",
"subtitle": "Insights from industry professionals",
"content": ["Section 1 content", "Section 2 content", "Section 3 content", "Section 4 content"],
"image_descriptions": ["Tech workspace", "Coding on computer", "Team collaboration", "Tech innovation"]
}
# Ensure all expected keys are present
expected_keys = ["title", "subtitle", "content", "image_descriptions", "introduction", "subheading"]
for key in expected_keys:
if key not in parsed_output:
if key in ["content", "image_descriptions"]:
parsed_output[key] = []
else:
parsed_output[key] = ""
# Generate headings if content is present
content_with_headings = []
if parsed_output["content"]:
for i, content in enumerate(parsed_output["content"]):
heading_query = f"Generate a concise heading for the following content:\n\n{content[:200]}..."
heading_response = query_engine.query(heading_query)
content_with_headings.append({"heading": heading_response.response.strip(), "text": content})
else:
content_with_headings = [{"heading": f"Section {i+1}", "text": "Content unavailable"} for i in range(4)]
# Generate images
images = []
for i, desc in enumerate(parsed_output["image_descriptions"][:4]): # Limit to 4 images
images.append(generate_image(desc, f"blog_image_{i}.png"))
# Generate content HTML
content_html = ""
for section in content_with_headings:
content_html += f"<h3>{section['heading']}</h3><p>{section['text']}</p>"
html_content = f"""
<!DOCTYPE HTML>
<html>
<style>
</style>
<head>
<title>{parsed_output['title']}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="is-preload">
<!-- Wrapper -->
<div id="wrapper">
<!-- Main -->
<div id="main">
<div class="inner">
<!-- Header -->
<header id="header">
<a href="index.html" class="logo"><strong>{parsed_output['title']}</strong> by {author}</a>
<ul class="icons">
<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon brands fa-facebook-f"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon brands fa-snapchat-ghost"><span class="label">Snapchat</span></a></li>
<li><a href="#" class="icon brands fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon brands fa-medium-m"><span class="label">Medium</span></a></li>
</ul>
</header>
<!-- Content -->
<section>
<header class="main">
<h1>{parsed_output['title']}</h1>
</header>
<span class="image main"><img src=".{images[0]}" alt="" /></span>
<p>{parsed_output['subtitle']}</p>
{content_html}
</section>
</div>
</div>
<!-- Sidebar -->
<div id="sidebar">
<div class="inner">
<!-- Search -->
<section id="search" class="alt">
<form method="post" action="#">
<input type="text" name="query" id="query" placeholder="Search" />
</form>
</section>
<!-- Menu -->
<nav id="menu">
<header class="major">
<h2>Menu</h2>
</header>
<ul>
<li><a href="index.html">Homepage</a></li>
<li><a href="generic.html">Generic</a></li>
<li><a href="elements.html">Elements</a></li>
</ul>
</nav>
<!-- Section -->
<section>
<header class="major">
<h2>Recent Posts</h2>
</header>
<div class="mini-posts">
<article>
<a href="#" class="image"><img src=".{images[1]}" alt="" /></a>
<p>{content_with_headings[1]['heading']}</p>
</article>
<article>
<a href="#" class="image"><img src=".{images[2]}" alt="" /></a>
<p>{content_with_headings[2]['heading']}</p>
</article>
<article>
<a href="#" class="image"><img src=".{images[3]}" alt="" /></a>
<p>{content_with_headings[3]['heading']}</p>
</article>
</div>
<ul class="actions">
<li><a href="#" class="button">More</a></li>
</ul>
</section>
<section><iframe position: relative; width="400" height="315" src={youtube_url}
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe></section>
</section>
<!-- Section -->
<section>
<header class="major">
<h2>Get in touch</h2>
</header>
<p>If you have any questions or comments about this blog post, feel free to get in touch.</p>
<ul class="contact">
<li class="icon solid fa-envelope"><a href="#">information@example.com</a></li>
<li class="icon solid fa-phone">(000) 000-0000</li>
<li class="icon solid fa-home">1234 Somewhere Road #8254<br />
Nashville, TN 00000-0000</li>
</ul>
</section>
<!-- Footer -->
<footer id="footer">
<p class="copyright">© {author}. All rights reserved. Design: <a href="https://html5up.net">HTML5 UP</a>.</p>
</footer>
</div>
</div>
</div>
</body>
</html>
"""
return html_content
elif template == "reader":
document = Document(text=doc_content)
embed_model = TogetherEmbedding(
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
index = VectorStoreIndex.from_documents([document], embed_model=embed_model)
response_schemas = [
ResponseSchema(name="title", description="The main title of the blog post"),
ResponseSchema(name="introduction", description="introductory paragraph about the blog"),
ResponseSchema(name="subtitle", description="A brief description or tagline for the blog post"),
ResponseSchema(name="content", description="The main content of the blog post, as a list of 5 text sections"),
ResponseSchema(name="image_descriptions", description="Descriptions for 4 images related to the content, as a list of strings")
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
llm = TogetherLLM(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
query_engine = index.as_query_engine(
llm=llm,
output_parser=LangchainOutputParser(output_parser),
)
response = query_engine.query(f"""Create a detailed and comprehensive blog post based on the given content.
The blog post should be at least 2000 words long, with 5 main points.
Provide in-depth explanations and examples for each point.
{format_instructions}""")
try:
parsed_output = output_parser.parse(response.response)
except OutputParserException as e:
print(f"Error parsing output: {e}")
# Provide default values
parsed_output = {
"title": "A Guide to Starting a Career in Tech",
"subtitle": "Insights from industry professionals",
"content": ["Section 1 content", "Section 2 content", "Section 3 content", "Section 4 content"],
"image_descriptions": ["image description 1", "image description 2", "image description 3", "image description 4"]
}
print(parsed_output)
# Ensure all expected keys are present and have the correct type
expected_keys = ["title", "subtitle", "content", "image_descriptions"]
for key in expected_keys:
if key not in parsed_output:
if key in ["content", "image_descriptions"]:
parsed_output[key] = []
else:
parsed_output[key] = ""
# Generate headings if content is present
content_with_headings = []
if parsed_output["content"]:
for i, content in enumerate(parsed_output["content"]):
heading_query = f"Generate a concise heading for the following content:\n\n{content[:200]}..."
heading_response = query_engine.query(heading_query)
content_with_headings.append({"heading": heading_response.response.strip(), "text": content})
else:
content_with_headings = [{"heading": f"Section {i+1}", "text": "Content unavailable"} for i in range(5)]
# Generate images
images = []
for i, desc in enumerate(parsed_output["image_descriptions"][:4]): # Limit to 4 images
images.append(generate_image(desc, f"blog_image_{i}.png"))
print("Image Generated")
while len(images) < 4:
images.append("default_image.png")
# Generate content HTML
content_html = ""
for section in content_with_headings:
content_html += f"<h2>{section['heading']}</h2><p>{section['text']}</p>"
# Generate image sections HTML
image_sections = ""
for i, (image, desc) in enumerate(zip(images, parsed_output["image_descriptions"])):
image_sections += f"""
<article>
<a href="#" class="image"><img src=".{image}" alt="{desc}" /></a>
<div class="inner">
<p>{desc}</p>
</div>
</article>
"""
# HTML template using f-string
html_content = f"""
<!DOCTYPE HTML>
<html>
<style>
</style>
<head>
<title>{parsed_output['title']}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="is-preload">
<section id="header">
<header>
<span class="image avatar"><img src=".{images[0]}" alt="" /></span>
<h1 id="logo"><a href="#">{author}</a></h1>
<p>{parsed_output['subtitle']}</p>
</header>
<nav id="nav">
<ul>
<li><a href="#one" class="active">About</a></li>
<li><a href="#two">Main Content</a></li>
<li><a href="#three">Images</a></li>
<li><a href="#four">Contact</a></li>
</ul>
</nav>
<footer>
<ul class="icons">
<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon brands fa-facebook-f"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon brands fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon brands fa-github"><span class="label">Github</span></a></li>
<li><a href="#" class="icon solid fa-envelope"><span class="label">Email</span></a></li>
</ul>
</footer>
</section>
<div id="wrapper">
<div id="main">
<section id="one">
<div class="image main" data-position="center">
<img src=".{images[1]}" alt="" />
</div>
<div class="container">
<header class="major">
<h2>{parsed_output['title']}</h2>
<p>{parsed_output['subtitle']}</p>
</header>
<p>{parsed_output['introduction']}</p>
</div>
</section>
<section id="two">
<div class="container">
<h3>Main Content</h3>
{content_html}
</div>
</section>
<iframe position: relative; section style="display: flex; justify-content: right; align-items: right; flex-direction: column; height: 100%;"></section>><iframe position: relative; style="text-align: right; "width="1200" height="600" src="https://www.youtube.com/watch?v=dQw4w9WgXcQ"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe></section>
</section>
<div class="container">
<h3>Images</h3>
<div class="features">
{image_sections}
</div>
</div>
</section>
<section><iframe width="560" height="315" src={youtube_url}
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe></section>
<section id="four">
<div class="container">
<h3>Contact Me</h3>
<p>Get in touch for more information about {parsed_output['title']}.</p>
<form method="post" action="#">
<div class="row gtr-uniform">
<div class="col-6 col-12-xsmall"><input type="text" name="name" id="name" placeholder="Name" /></div>
<div class="col-6 col-12-xsmall"><input type="email" name="email" id="email" placeholder="Email" /></div>
<div class="col-12"><input type="text" name="subject" id="subject" placeholder="Subject" /></div>
<div class="col-12"><textarea name="message" id="message" placeholder="Message" rows="6"></textarea></div>
<div class="col-12">
<ul class="actions">
<li><input type="submit" class="primary" value="Send Message" /></li>
<li><input type="reset" value="Reset Form" /></li>
</ul>
</div>
</div>
</form>
</div>
</section>
</div>
<section id="footer">
<div class="container">
<ul class="copyright">
<li>© {author}. All rights reserved.</li>
</ul>
</div>
</section>
</div>
</body>
</html>
"""
return html_content
elif template == 'arcana':
document = Document(text=doc_content)
embed_model = TogetherEmbedding(
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
index = VectorStoreIndex.from_documents([document], embed_model=embed_model)
response_schemas = [
ResponseSchema(name="title", description="The main title of the blog post"),
ResponseSchema(name="introduction", description="A brief introduction to the blog post"),
ResponseSchema(name="subheading", description="Sub heading for the blog post"),
ResponseSchema(name="subtitle", description="A brief description or tagline for the blog post"),
ResponseSchema(name="content", description="The main content of the blog post, as a list of 4 text sections"),
ResponseSchema(name="image_descriptions", description="Descriptions for 4 images related to the content, as a list of strings")
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
llm = TogetherLLM(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
query_engine = index.as_query_engine(
llm=llm,
output_parser=LangchainOutputParser(output_parser),
)
response = query_engine.query(f"""Create a detailed and comprehensive blog post based on the given content.
The blog post should be at least 2000 words long, with 5 main points.
Provide in-depth explanations and examples for each point.
{format_instructions}""")
try:
parsed_output = output_parser.parse(response.response)
except OutputParserException as e:
print(f"Error parsing output: {e}")
# Provide default values
parsed_output = {
"title": "A Guide to Starting a Career in Tech",
"intrdocution":"introduction about the blog",
"subheading": "this can be a subheading for the blog",
"subtitle": "Insights from industry professionals",
"content": ["Section 1 content", "Section 2 content", "Section 3 content", "Section 4 content"],
"image_descriptions": ["Tech workspace", "Coding on computer", "Team collaboration", "Tech innovation"]
}
# Ensure all expected keys are present
expected_keys = ["title", "subtitle", "content", "image_descriptions", "introduction", "subheading"]
for key in expected_keys:
if key not in parsed_output:
if key in ["content", "image_descriptions"]:
parsed_output[key] = []
else:
parsed_output[key] = ""
# Generate headings if content is present
content_with_headings = []
if parsed_output["content"]:
for i, content in enumerate(parsed_output["content"]):
heading_query = f"Generate a concise heading for the following content:\n\n{content[:200]}..."
heading_response = query_engine.query(heading_query)
content_with_headings.append({"heading": heading_response.response.strip(), "text": content})
else:
content_with_headings = [{"heading": f"Section {i+1}", "text": "Content unavailable"} for i in range(4)]
# Generate images
images = []
for i, desc in enumerate(parsed_output["image_descriptions"][:4]): # Limit to 4 images
images.append(generate_image(desc, f"blog_image_{i}.png"))
# Generate content HTML
content_html = ""
for section in content_with_headings:
content_html += f"<h3>{section['heading']}</h3><p>{section['text']}</p>"
html_content = f"""
<!DOCTYPE HTML>
<html>
<style>
</style>
<head>
<title>{parsed_output['title']}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="is-preload">
<div id="page-wrapper">
<div id="header">
<h1>{parsed_output['title']}</h1>
<nav id="nav">
<ul>
<li>Home</a></li>
<li>
Dropdown
<ul>
Submenufc
</li>
</ul>
</li>
<li class="current"><a href="right-sidebar.html">Right Sidebar</a></li>
</ul>
</nav>
</div>
<!-- Main -->
<section class="wrapper style1">
<div class="container">
<div class="row gtr-200">
<div class="col-8 col-12-narrower">
<div id="content">
<!-- Content -->
<article>
<header>
<h2>{parsed_output['title']}</h2>
<p>{parsed_output['subtitle']}</p>
</header>
<span class="image featured"><img src=".{images[0]}" alt="" /></span>
{content_html}
</article>
</div>
</div>
<div class="col-4 col-12-narrower">
<div id="sidebar">
<!-- Sidebar -->
<section>
<h3>{content_with_headings[1]['heading']}</h3>
<p>{content_with_headings[1]['text']}</p>
<footer>
<a href="#" class="button">Continue Reading</a>
</footer>
</section>
<section>
<h3>Another Subheading</h3>
<section><iframe width="560" height="315" src={youtube_url}
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe></section>
</section>
</div>
</div>
</div>
</div>
</section>
<!-- Footer -->
<div id="footer">
<div class="container">
<div class="row">
<section class="col-3 col-6-narrower col-12-mobilep">
<h3>Links to Stuff(you can add)</h3>
<ul class="links">
<li><a href="#">Mattis et quis rutrum</a></li>
<li><a href="#">Suspendisse amet varius</a></li>
</ul>
</section>
<section class="col-6 col-12-narrower">
<h3>Get In Touch with {author}</h3>
<form>
<div class="row gtr-50">
<div class="col-6 col-12-mobilep">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="col-6 col-12-mobilep">
<input type="email" name="email" id="email" placeholder="Email" />
</div>
<div class="col-12">
<textarea name="message" id="message" placeholder="Message" rows="5"></textarea>
</div>
<div class="col-12">
<ul class="actions">
<li><input type="submit" class="button alt" value="Send Message" /></li>
</ul>
</div>
</div>
</form>
</section>
</div>
</div>
<!-- Icons -->
<ul class="icons">
<li><a href="#" class="icon brands fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon brands fa-facebook-f"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon brands fa-github"><span class="label">GitHub</span></a></li>
<li><a href="#" class="icon brands fa-linkedin-in"><span class="label">LinkedIn</span></a></li>
<li><a href="#" class="icon brands fa-google-plus-g"><span class="label">Google+</span></a></li>
</ul>
</div>
</div>
</body>
</html>
"""
return html_content
elif template == 'hycuna':
document = Document(text=doc_content)
embed_model = TogetherEmbedding(
model_name="togethercomputer/m2-bert-80M-8k-retrieval",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
index = VectorStoreIndex.from_documents([document], embed_model=embed_model)
response_schemas = [
ResponseSchema(name="title", description="The main title of the blog post, make it short and catchy"),
ResponseSchema(name="subtitle", description="A brief description or tagline for the blog post"),
ResponseSchema(name="introduction", description="An introductory paragraph for the main content"),
ResponseSchema(name="content", description="The main content of the blog post, as a list of 4 text sections"),
ResponseSchema(name="sidebar_sections", description="Content for the sidebar, including headers and lists"),
ResponseSchema(name="blurb", description="An informative text blurb for the footer"),
ResponseSchema(name="image_descriptions", description="Descriptions for 4 images related to the content, as a list of strings"),
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
llm = TogetherLLM(
model="mistralai/Mixtral-8x7B-Instruct-v0.1",
api_key="fb5107bddcd0f7f144ca41251d77bbb59f9f5f64cb21435473f15a2801d28d73"
)
query_engine = index.as_query_engine(
llm=llm,
output_parser=LangchainOutputParser(output_parser),
)
response = query_engine.query(f"""Create a detailed and comprehensive blog post based on the given content.
The blog post should be at least 2000 words long, with 5 main points.
Provide in-depth explanations and examples for each point.
{format_instructions}""")
try:
parsed_output = output_parser.parse(response.response)
except OutputParserException as e:
print(f"Error parsing output: {e}")
# Provide default values
parsed_output = {
"title": "A Guide to Starting a Career in Tech",
"intrdocution":"introduction about the blog",
"subheading": "this can be a subheading for the blog",
"subtitle": "Insights from industry professionals",
"content": ["Section 1 content", "Section 2 content", "Section 3 content", "Section 4 content"],
"image_descriptions": ["Tech workspace", "Coding on computer", "Team collaboration", "Tech innovation"]
}
# Ensure all expected keys are present
expected_keys = ["title", "subtitle", "introduction","subheading", "content", "sidebar_sections", "footer_links", "blurb", "image_descriptions"]
for key in expected_keys:
if key not in parsed_output:
parsed_output[key] = "" if key != "main_content" and key != "sidebar_sections" else []
content_with_headings = []
if parsed_output["content"]:
for i, content in enumerate(parsed_output["content"]):
heading_query = f"Generate a concise heading for the following content:\n\n{content[:200]}..."
heading_response = query_engine.query(heading_query)
content_with_headings.append({"heading": heading_response.response.strip(), "text": content})
else:
content_with_headings = [{"heading": f"Section {i+1}", "text": "Content unavailable"} for i in range(4)]
images = []
for i, desc in enumerate(parsed_output["image_descriptions"][:4]): # Limit to 4 images
images.append(generate_image(desc, f"blog_image_{i}.png"))
content_html = ""
for section in content_with_headings:
content_html += f"<h2>{section['heading']}</h2><p>{section['text']}</p>"
html_content = f"""
<!DOCTYPE HTML>
<html>
<style>
</style>
<head>
<title>{parsed_output['title']}</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="subpage">
<div id="page-wrapper">
<!-- Header -->
<section id="header">
<div class="container">
<div class="row">
<div class="col-12">
<h1><a href="index.html" id="logo">{parsed_output['title']}</a></h1>S
</div>
</div>
</div>
</section>
<!-- Content -->
<section id="content">
<div class="container">
<div class="row">
<div class="col-3 col-12-medium">
<article>
<a href="#" class="image"><img src=".{images[1]}" alt="" /></a>
<p>{content_with_headings[1]['heading']}</p>
</article>
<article>
<a href="#" class="image"><img src=".{images[2]}" alt="" /></a>
<p>{content_with_headings[2]['heading']}</p>
</article>
<article>
<a href="#" class="image"><img src=".{images[3]}" alt="" /></a>
<p>{content_with_headings[3]['heading']}</p>
</article>
</div>
<div class="col-9 col-12-medium imp-medium">
<!-- Main Content -->
<section>
<header>
<h2>{parsed_output['title']}</h2>
<h3>{parsed_output['subtitle']}</h3>
</header>
<p>{parsed_output['introduction']}</p>
<p>{parsed_output['subheading']}</p>
{content_html}
</section>
<section><iframe width="560" height="315" src={youtube_url}
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>Website created based on this YouTube video</iframe></section>
</section>
</div>
</div>
</div>
</section>
<!-- Footer -->
<section id="footer">
<div class="container">
<div class="row">
<div class="col-8 col-12-medium">
<!-- Links -->