File size: 79,372 Bytes
099c05b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DrL_MhvI1xPn"
      },
      "source": [
        "# PDF to Audio Converter\n",
        "\n",
        "This code can be used to convert PDFs into audio podcasts, lectures, summaries, and more. It uses OpenAI's GPT models for text generation and text-to-speech conversion.\n",
        "\n",
        "Source: [https://github.com/lamm-mit/PDF2Audio](https://github.com/lamm-mit/PDF2Audio)\n",
        "\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "JrPccs_M1qZ9",
        "outputId": "bf90828d-c67c-4cfa-919f-9c434c0a55ec"
      },
      "outputs": [],
      "source": [
        "!pip install loguru gradio promptic pydantic pypdf tenacity openai -q"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 626
        },
        "id": "nEduHdSD1fE-",
        "outputId": "e450cf4a-f3b9-437f-d7b3-a34d2bc4467c"
      },
      "outputs": [],
      "source": [
        "# @title\n",
        "import concurrent.futures as cf\n",
        "import glob\n",
        "import io\n",
        "import os\n",
        "import time\n",
        "from pathlib import Path\n",
        "from tempfile import NamedTemporaryFile\n",
        "from typing import List, Literal\n",
        "\n",
        "import gradio as gr\n",
        "\n",
        "from loguru import logger\n",
        "from openai import OpenAI\n",
        "from promptic import llm\n",
        "from pydantic import BaseModel, ValidationError\n",
        "from pypdf import PdfReader\n",
        "from tenacity import retry, retry_if_exception_type\n",
        "\n",
        "import re\n",
        "\n",
        "def read_readme():\n",
        "    readme_path = Path(\"README.md\")\n",
        "    if readme_path.exists():\n",
        "        with open(readme_path, \"r\") as file:\n",
        "            content = file.read()\n",
        "            # Use regex to remove metadata enclosed in -- ... --\n",
        "            content = re.sub(r'--.*?--', '', content, flags=re.DOTALL)\n",
        "            return content\n",
        "    else:\n",
        "        return \"README.md not found. Please check the repository for more information.\"\n",
        "        \n",
        "# Define multiple sets of instruction templates\n",
        "INSTRUCTION_TEMPLATES = {\n",
        "################# PODCAST ##################\n",
        "    \"podcast\": {\n",
        "        \"intro\": \"\"\"Your task is to take the input text provided and turn it into an lively, engaging, informative podcast dialogue, in the style of NPR. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages. \n",
        "\n",
        "Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast. \n",
        "\n",
        "Define all terms used carefully for a broad audience of listeners.\n",
        "\"\"\",\n",
        "        \"text_instructions\": \"First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.\",\n",
        "        \"scratch_pad\": \"\"\"Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.\n",
        "\n",
        "Keep in mind that your podcast should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.\n",
        "\n",
        "Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.\n",
        "\n",
        "Define all terms used clearly and spend effort to explain the background.\n",
        "\n",
        "Write your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.\n",
        "\n",
        "Make sure to make it fun and exciting. \n",
        "\"\"\",\n",
        "        \"prelude\": \"\"\"Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.\n",
        "\"\"\",\n",
        "        \"dialog\": \"\"\"Write a very long, engaging, informative podcast dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience. \n",
        "\n",
        "Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.\n",
        "\n",
        "Make the dialogue as long and detailed as possible, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.\n",
        "\n",
        "At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off. \n",
        "\n",
        "The podcast should have around 20000 words.\n",
        "\"\"\",\n",
        "    },\n",
        "################# MATERIAL DISCOVERY SUMMARY ##################\n",
        "    \"SciAgents material discovery summary\": {\n",
        "        \"intro\": \"\"\"Your task is to take the input text provided and turn it into a lively, engaging conversation between a professor and a student in a panel discussion that describes a new material. The professor acts like Richard Feynman, but you never mention the name.\n",
        "\n",
        "The input text is the result of a design developed by SciAgents, an AI tool for scientific discovery that has come up with a detailed materials design.\n",
        "\n",
        "Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast.\n",
        "\n",
        "Define all terms used carefully for a broad audience of listeners.\n",
        "\"\"\",\n",
        "        \"text_instructions\": \"First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.\",\n",
        "        \"scratch_pad\": \"\"\"Brainstorm creative ways to discuss the main topics and key points you identified in the material design summary, especially paying attention to design features developed by SciAgents. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.\n",
        "\n",
        "Keep in mind that your description should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.\n",
        "\n",
        "Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.\n",
        "\n",
        "Define all terms used clearly and spend effort to explain the background.\n",
        "\n",
        "Write your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.\n",
        "\n",
        "Make sure to make it fun and exciting. You never refer to the podcast, you just discuss the discovery and you focus on the new material design only.\n",
        "\"\"\",\n",
        "        \"prelude\": \"\"\"Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.\n",
        "\"\"\",\n",
        "        \"dialog\": \"\"\"Write a very long, engaging, informative dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. The presentation must focus on the novel aspects of the material design, behavior, and all related aspects.\n",
        "\n",
        "Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience, but make it detailed, logical, and technical so that it has all necessary aspects for listeners to understand the material and its unexpected properties.\n",
        "\n",
        "Remember, this describes a design developed by SciAgents, and this must be explicitly stated for the listeners.\n",
        "\n",
        "Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.\n",
        "\n",
        "Make the dialogue as long and detailed as possible with great scientific depth, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.\n",
        "\n",
        "At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off.\n",
        "\n",
        "The conversation should have around 20000 words.\n",
        "\"\"\"\n",
        "    },\n",
        "################# LECTURE ##################\n",
        "    \"lecture\": {\n",
        "        \"intro\": \"\"\"You are Professor Richard Feynman. Your task is to develop a script for a lecture. You never mention your name.\n",
        "\n",
        "The material covered in the lecture is based on the provided text. \n",
        "\n",
        "Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that need to be covered in the lecture. \n",
        "\n",
        "Define all terms used carefully for a broad audience of students.\n",
        "\"\"\",\n",
        "        \"text_instructions\": \"First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.\",\n",
        "        \"scratch_pad\": \"\"\"\n",
        "Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.\n",
        "\n",
        "Keep in mind that your lecture should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.\n",
        "\n",
        "Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.\n",
        "\n",
        "Define all terms used clearly and spend effort to explain the background.\n",
        "\n",
        "Write your brainstorming ideas and a rough outline for the lecture here. Be sure to note the key insights and takeaways you want to reiterate at the end.\n",
        "\n",
        "Make sure to make it fun and exciting. \n",
        "\"\"\",\n",
        "        \"prelude\": \"\"\"Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.\n",
        "\"\"\",\n",
        "        \"dialog\": \"\"\"Write a very long, engaging, informative script here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to the students.\n",
        "\n",
        "Include clear definitions and terms, and examples. \n",
        "\n",
        "Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.\n",
        "\n",
        "There is only one speaker, you, the professor. Stay on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest lecture you can, while still communicating the key information from the input text in an engaging way.\n",
        "\n",
        "At the end of the lecture, naturally summarize the main insights and takeaways from the lecture. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. \n",
        "\n",
        "Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas covered in this lecture one last time before class is over. \n",
        "\n",
        "The lecture should have around 20000 words.\n",
        "\"\"\",\n",
        "    },\n",
        "################# SUMMARY ##################\n",
        "        \"summary\": {\n",
        "        \"intro\": \"\"\"Your task is to develop a summary of a paper. You never mention your name.\n",
        "\n",
        "Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that need to be summarized.\n",
        "\n",
        "Define all terms used carefully for a broad audience.\n",
        "\"\"\",\n",
        "        \"text_instructions\": \"First, carefully read through the input text and identify the main topics, key points, and key facts. Think about how you could present this information in an accurate summary.\",\n",
        "        \"scratch_pad\": \"\"\"Brainstorm creative ways to present the main topics and key points you identified in the input text. Consider using analogies, examples, or hypothetical scenarios to make the content more relatable and engaging for listeners.\n",
        "\n",
        "Keep in mind that your summary should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms. Define all terms used clearly and spend effort to explain the background.\n",
        "\n",
        "Write your brainstorming ideas and a rough outline for the summary here. Be sure to note the key insights and takeaways you want to reiterate at the end.\n",
        "\n",
        "Make sure to make it engaging and exciting. \n",
        "\"\"\",\n",
        "        \"prelude\": \"\"\"Now that you have brainstormed ideas and created a rough outline, it is time to write the actual summary. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.\n",
        "\"\"\",\n",
        "        \"dialog\": \"\"\"Write a a script here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to the the audience.\n",
        "\n",
        "Start your script by stating that this is a summary, referencing the title or headings in the input text. If the input text has no title, come up with a succinct summary of what is covered to open.\n",
        "\n",
        "Include clear definitions and terms, and examples, of all key issues. \n",
        "\n",
        "Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.\n",
        "\n",
        "There is only one speaker, you. Stay on topic and maintaining an engaging flow. \n",
        "\n",
        "Naturally summarize the main insights and takeaways from the summary. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. \n",
        "\n",
        "The summary should have around 1024 words.\n",
        "\"\"\",\n",
        "    },\n",
        "################# SHORT SUMMARY ##################\n",
        "        \"short summary\": {\n",
        "        \"intro\": \"\"\"Your task is to develop a summary of a paper. You never mention your name.\n",
        "\n",
        "Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that need to be summarized.\n",
        "\n",
        "Define all terms used carefully for a broad audience.\n",
        "\"\"\",\n",
        "        \"text_instructions\": \"First, carefully read through the input text and identify the main topics, key points, and key facts. Think about how you could present this information in an accurate summary.\",\n",
        "        \"scratch_pad\": \"\"\"Brainstorm creative ways to present the main topics and key points you identified in the input text. Consider using analogies, examples, or hypothetical scenarios to make the content more relatable and engaging for listeners.\n",
        "\n",
        "Keep in mind that your summary should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms. Define all terms used clearly and spend effort to explain the background.\n",
        "\n",
        "Write your brainstorming ideas and a rough outline for the summary here. Be sure to note the key insights and takeaways you want to reiterate at the end.\n",
        "\n",
        "Make sure to make it engaging and exciting. \n",
        "\"\"\",\n",
        "        \"prelude\": \"\"\"Now that you have brainstormed ideas and created a rough outline, it is time to write the actual summary. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.\n",
        "\"\"\",\n",
        "        \"dialog\": \"\"\"Write a a script here, based on the key points and creative ideas you came up with during the brainstorming session. Keep it concise, and use a conversational tone and include any necessary context or explanations to make the content accessible to the the audience.\n",
        "\n",
        "Start your script by stating that this is a summary, referencing the title or headings in the input text. If the input text has no title, come up with a succinct summary of what is covered to open.\n",
        "\n",
        "Include clear definitions and terms, and examples, of all key issues. \n",
        "\n",
        "Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.\n",
        "\n",
        "There is only one speaker, you. Stay on topic and maintaining an engaging flow. \n",
        "\n",
        "Naturally summarize the main insights and takeaways from the short summary. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. \n",
        "\n",
        "The summary should have around 256 words.\n",
        "\"\"\",\n",
        "    },\n",
        "################# PODCAST French ##################\n",
        "\"podcast (French)\": {\n",
        "    \"intro\": \"\"\"Votre tâche consiste à prendre le texte fourni et à le transformer en un dialogue de podcast vivant, engageant et informatif, dans le style de NPR. Le texte d'entrée peut être désorganisé ou non structuré, car il peut provenir de diverses sources telles que des fichiers PDF ou des pages web.\n",
        "\n",
        "Ne vous inquiétez pas des problèmes de formatage ou des informations non pertinentes ; votre objectif est d'extraire les points clés, d'identifier les définitions et les faits intéressants qui pourraient être discutés dans un podcast.\n",
        "\n",
        "Définissez soigneusement tous les termes utilisés pour un public large.\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"Tout d'abord, lisez attentivement le texte d'entrée et identifiez les principaux sujets, points clés et faits ou anecdotes intéressants. Réfléchissez à la manière dont vous pourriez présenter ces informations de manière amusante et engageante, convenant à une présentation de haute qualité.\",\n",
        "    \"scratch_pad\": \"\"\"Réfléchissez à des moyens créatifs pour discuter des principaux sujets et points clés que vous avez identifiés dans le texte d'entrée. Envisagez d'utiliser des analogies, des exemples, des techniques de narration ou des scénarios hypothétiques pour rendre le contenu plus accessible et attrayant pour les auditeurs.\n",
        "\n",
        "Gardez à l'esprit que votre podcast doit être accessible à un large public, donc évitez d'utiliser trop de jargon ou de supposer une connaissance préalable du sujet. Si nécessaire, trouvez des moyens d'expliquer brièvement les concepts complexes en termes simples.\n",
        "\n",
        "Utilisez votre imagination pour combler les lacunes du texte d'entrée ou pour poser des questions stimulantes qui pourraient être explorées dans le podcast. L'objectif est de créer un dialogue informatif et divertissant, donc n'hésitez pas à faire preuve de créativité dans votre approche.\n",
        "\n",
        "Définissez clairement tous les termes utilisés et prenez le temps d'expliquer le contexte.\n",
        "\n",
        "Écrivez ici vos idées de brainstorming et une esquisse générale pour le dialogue du podcast. Assurez-vous de noter les principaux points et enseignements que vous souhaitez réitérer à la fin.\n",
        "\n",
        "Faites en sorte que ce soit amusant et captivant.\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"Maintenant que vous avez réfléchi à des idées et créé une esquisse générale, il est temps d'écrire le dialogue réel du podcast. Visez un flux naturel et conversationnel entre l'hôte et tout invité. Intégrez les meilleures idées de votre session de brainstorming et assurez-vous d'expliquer tous les sujets complexes de manière compréhensible.\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"Écrivez ici un dialogue de podcast très long, captivant et informatif, basé sur les points clés et les idées créatives que vous avez développés lors de la session de brainstorming. Utilisez un ton conversationnel et incluez tout contexte ou explication nécessaire pour rendre le contenu accessible à un public général.\n",
        "\n",
        "Ne créez jamais de noms fictifs pour les hôtes et les invités, mais rendez cela engageant et immersif pour les auditeurs. N'incluez pas de marqueurs entre crochets comme [Hôte] ou [Invité]. Conceptionnez votre sortie pour être lue à haute voix – elle sera directement convertie en audio.\n",
        "\n",
        "Faites en sorte que le dialogue soit aussi long et détaillé que possible, tout en restant sur le sujet et en maintenant un flux engageant. Utilisez toute votre capacité de production pour créer l'épisode de podcast le plus long possible, tout en communiquant les informations clés du texte d'entrée de manière divertissante.\n",
        "\n",
        "À la fin du dialogue, l'hôte et les invités doivent naturellement résumer les principales idées et enseignements de leur discussion. Cela doit découler naturellement de la conversation, en réitérant les points clés de manière informelle et conversationnelle. Évitez de donner l'impression qu'il s'agit d'un récapitulatif évident – l'objectif est de renforcer les idées centrales une dernière fois avant de conclure.\n",
        "\n",
        "Le podcast doit comporter environ 20 000 mots.\n",
        "\"\"\",\n",
        "},\n",
        "\n",
        "################# PODCAST GERMAN ##################\n",
        "\"podcast (German)\": {\n",
        "    \"intro\": \"\"\"Deine Aufgabe ist es, den bereitgestellten Text in einen lebendigen, fesselnden und informativen Podcast-Dialog im Stil von NPR zu verwandeln. Der Eingabetext kann unstrukturiert oder chaotisch sein, da er aus verschiedenen Quellen wie PDFs oder Webseiten stammen kann.\n",
        "\n",
        "Mach dir keine Sorgen über Formatierungsprobleme oder irrelevante Informationen; dein Ziel ist es, die wichtigsten Punkte zu extrahieren, Definitionen und interessante Fakten zu identifizieren, die in einem Podcast besprochen werden könnten.\n",
        "\n",
        "Definiere alle verwendeten Begriffe sorgfältig für ein breites Publikum.\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"Lies zuerst den Eingabetext sorgfältig durch und identifiziere die Hauptthemen, Schlüsselpunkte und interessante Fakten oder Anekdoten. Überlege, wie du diese Informationen auf unterhaltsame und ansprechende Weise präsentieren könntest, sodass sie für eine hochwertige Präsentation geeignet sind.\",\n",
        "    \"scratch_pad\": \"\"\"Denke kreativ darüber nach, wie du die Hauptthemen und Schlüsselpunkte, die du im Eingabetext identifiziert hast, diskutieren könntest. Verwende Analogien, Beispiele, Erzähltechniken oder hypothetische Szenarien, um den Inhalt für die Zuhörer nachvollziehbarer und ansprechender zu gestalten.\n",
        "\n",
        "Behalte im Hinterkopf, dass dein Podcast einem breiten Publikum zugänglich sein sollte, daher vermeide zu viel Fachjargon oder die Annahme von Vorwissen über das Thema. Falls nötig, überlege dir Möglichkeiten, um komplexe Konzepte kurz und einfach zu erklären.\n",
        "\n",
        "Nutze deine Fantasie, um Lücken im Eingabetext zu füllen oder um nachdenklich stimmende Fragen zu formulieren, die im Podcast erforscht werden könnten. Das Ziel ist es, einen informativen und unterhaltsamen Dialog zu schaffen, daher kannst du bei deinem Ansatz kreativ sein.\n",
        "\n",
        "Definiere alle verwendeten Begriffe klar und nimm dir die Zeit, den Hintergrund zu erläutern.\n",
        "\n",
        "Schreibe deine Brainstorming-Ideen und eine grobe Gliederung für den Podcast-Dialog hier auf. Achte darauf, die wichtigsten Erkenntnisse und Aussagen, die du am Ende wiederholen möchtest, zu notieren.\n",
        "\n",
        "Sorge dafür, dass es unterhaltsam und spannend ist.\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"Nun, da du Ideen gesammelt und eine grobe Gliederung erstellt hast, ist es an der Zeit, den eigentlichen Podcast-Dialog zu schreiben. Strebe einen natürlichen, konversationellen Fluss zwischen dem Moderator und etwaigen Gästen an. Nutze die besten Ideen aus deiner Brainstorming-Sitzung und erkläre alle komplexen Themen auf eine leicht verständliche Weise.\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"Schreibe hier einen sehr langen, fesselnden und informativen Podcast-Dialog, basierend auf den wichtigsten Punkten und kreativen Ideen, die du während der Brainstorming-Sitzung erarbeitet hast. Verwende einen konversationellen Ton und füge alle notwendigen Kontexte oder Erklärungen hinzu, um den Inhalt für ein allgemeines Publikum zugänglich zu machen.\n",
        "\n",
        "Verwende niemals erfundene Namen für die Moderatoren und Gäste, aber gestalte es zu einem fesselnden und immersiven Erlebnis für die Zuhörer. Verwende keine Platzhalter wie [Moderator] oder [Gast]. Dein Output wird direkt in Audio umgewandelt, daher entwerfe den Dialog so, dass er laut vorgelesen werden kann.\n",
        "\n",
        "Gestalte den Dialog so lang und detailliert wie möglich, bleibe dabei jedoch immer beim Thema und erhalte einen flüssigen, ansprechenden Verlauf. Verwende deine volle Output-Kapazität, um die längste mögliche Podcast-Episode zu erstellen, während du die wichtigsten Informationen aus dem Eingabetext auf unterhaltsame Weise vermittelst.\n",
        "\n",
        "Am Ende des Dialogs sollen der Moderator und die Gäste die wichtigsten Erkenntnisse und Aussagen ihres Gesprächs auf natürliche Weise zusammenfassen. Dies sollte organisch aus der Konversation hervorgehen und die wichtigsten Punkte in einem lockeren, gesprächigen Stil wiederholen. Vermeide es, wie eine offensichtliche Zusammenfassung zu klingen – das Ziel ist es, die zentralen Ideen ein letztes Mal zu verstärken, bevor der Podcast endet.\n",
        "\n",
        "Der Podcast sollte etwa 20.000 Wörter umfassen.\n",
        "\"\"\",\n",
        "    },\n",
        "    \n",
        "################# PODCAST SPANISH ##################\n",
        "\"podcast (Spanish)\": {\n",
        "    \"intro\": \"\"\"Tu tarea es tomar el texto de entrada proporcionado y convertirlo en un diálogo de podcast animado, atractivo e informativo, al estilo de NPR. El texto de entrada puede estar desordenado o poco estructurado, ya que podría provenir de diversas fuentes como archivos PDF o páginas web.\n",
        "\n",
        "No te preocupes por los problemas de formato o por la información irrelevante; tu objetivo es extraer los puntos clave, identificar definiciones y hechos interesantes que podrían discutirse en un podcast.\n",
        "\n",
        "Define cuidadosamente todos los términos utilizados para una audiencia amplia.\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"Primero, lee detenidamente el texto de entrada e identifica los temas principales, los puntos clave y cualquier hecho o anécdota interesante. Piensa en cómo podrías presentar esta información de una manera divertida y atractiva, adecuada para una presentación de alta calidad.\",\n",
        "    \"scratch_pad\": \"\"\"Piensa de manera creativa sobre cómo discutir los temas principales y los puntos clave que has identificado en el texto de entrada. Considera usar analogías, ejemplos, técnicas narrativas o escenarios hipotéticos para hacer que el contenido sea más comprensible y atractivo para los oyentes.\n",
        "\n",
        "Ten en cuenta que tu podcast debe ser accesible para una audiencia general, así que evita usar demasiado jerga técnica o asumir que la audiencia tiene conocimientos previos del tema. Si es necesario, piensa en formas de explicar brevemente cualquier concepto complejo en términos sencillos.\n",
        "\n",
        "Usa tu imaginación para llenar los vacíos en el texto de entrada o para formular preguntas provocadoras que podrían explorarse en el podcast. El objetivo es crear un diálogo informativo y entretenido, por lo que puedes ser creativo en tu enfoque.\n",
        "\n",
        "Define claramente todos los términos utilizados y asegúrate de explicar el trasfondo.\n",
        "\n",
        "Escribe tus ideas de brainstorming y un esquema general del diálogo del podcast aquí. Asegúrate de anotar los puntos clave y las conclusiones que deseas reiterar al final.\n",
        "\n",
        "Asegúrate de que sea divertido y emocionante.\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"Ahora que has realizado una lluvia de ideas y has creado un esquema general, es hora de escribir el diálogo real del podcast. Apunta a un flujo natural y conversacional entre el presentador y cualquier invitado. Incorpora las mejores ideas de tu sesión de lluvia de ideas y asegúrate de explicar cualquier tema complejo de una manera fácil de entender.\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"Escribe aquí un diálogo de podcast muy largo, atractivo e informativo, basado en los puntos clave y las ideas creativas que se te ocurrieron durante la sesión de brainstorming. Usa un tono conversacional e incluye el contexto o las explicaciones necesarias para que el contenido sea accesible a una audiencia general.\n",
        "\n",
        "Nunca uses nombres inventados para los presentadores e invitados, pero haz que sea una experiencia atractiva e inmersiva para los oyentes. No incluyas ningún marcador de posición entre corchetes como [Presentador] o [Invitado]. Diseña tu salida para que sea leída en voz alta, ya que se convertirá directamente en audio.\n",
        "\n",
        "Haz el diálogo lo más largo y detallado posible, manteniéndote en el tema y asegurando un flujo atractivo. Apunta a utilizar toda tu capacidad de salida para crear el episodio de podcast más largo posible, mientras comunicas la información clave del texto de entrada de una manera entretenida.\n",
        "\n",
        "Al final del diálogo, el presentador y los invitados deben resumir naturalmente las principales ideas y conclusiones de su conversación. Esto debe fluir orgánicamente desde la conversación, reiterando los puntos clave de manera casual y conversacional. Evita que suene como un resumen obvio: el objetivo es reforzar las ideas centrales una última vez antes de finalizar.\n",
        "\n",
        "El podcast debe tener alrededor de 20,000 palabras.\n",
        "\"\"\",\n",
        "    },\n",
        "\n",
        "################# PODCAST Portuguese ##################\n",
        "\"podcast (Portuguese)\": {\n",
        "    \"intro\": \"\"\"Sua tarefa é pegar o texto de entrada fornecido e transformá-lo em um diálogo de podcast animado, envolvente e informativo, no estilo da NPR. O texto de entrada pode ser desorganizado ou não estruturado, pois pode vir de várias fontes, como PDFs ou páginas da web.\n",
        "\n",
        "Não se preocupe com problemas de formatação ou informações irrelevantes; seu objetivo é extrair os pontos principais, identificar definições e fatos interessantes que possam ser discutidos em um podcast.\n",
        "\n",
        "Defina cuidadosamente todos os termos usados para um público amplo.\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"Primeiro, leia atentamente o texto de entrada e identifique os principais tópicos, pontos-chave e quaisquer fatos ou anedotas interessantes. Pense em como você poderia apresentar essas informações de maneira divertida e envolvente, adequada para uma apresentação de alta qualidade.\",\n",
        "    \"scratch_pad\": \"\"\"Pense de maneira criativa sobre como discutir os principais tópicos e pontos-chave que você identificou no texto de entrada. Considere usar analogias, exemplos, técnicas de narrativa ou cenários hipotéticos para tornar o conteúdo mais acessível e interessante para os ouvintes.\n",
        "\n",
        "Tenha em mente que seu podcast deve ser acessível a um público geral, por isso, evite usar jargões técnicos ou presumir que o público tem conhecimento prévio do assunto. Se necessário, pense em maneiras de explicar brevemente qualquer conceito complexo em termos simples.\n",
        "\n",
        "Use sua imaginação para preencher quaisquer lacunas no texto de entrada ou para criar perguntas instigantes que possam ser exploradas no podcast. O objetivo é criar um diálogo informativo e divertido, então sinta-se à vontade para ser criativo em sua abordagem.\n",
        "\n",
        "Defina claramente todos os termos utilizados e faça um esforço para explicar o contexto.\n",
        "\n",
        "Escreva suas ideias de brainstorming e um esboço para o diálogo do podcast aqui. Certifique-se de anotar os principais insights e pontos que deseja reiterar no final.\n",
        "\n",
        "Certifique-se de que seja divertido e empolgante.\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"Agora que você já fez um brainstorming de ideias e criou um esboço, é hora de escrever o diálogo real do podcast. Busque um fluxo natural e conversacional entre o apresentador e qualquer convidado. Incorpore as melhores ideias de sua sessão de brainstorming e certifique-se de explicar qualquer tópico complexo de maneira fácil de entender.\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"Escreva aqui um diálogo de podcast muito longo, envolvente e informativo, com base nos pontos-chave e nas ideias criativas que você criou durante a sessão de brainstorming. Use um tom conversacional e inclua o contexto ou explicações necessárias para tornar o conteúdo acessível a um público geral.\n",
        "\n",
        "Nunca use nomes inventados para os apresentadores e convidados, mas faça com que seja uma experiência envolvente e imersiva para os ouvintes. Não inclua marcadores de posição como [Apresentador] ou [Convidado]. Desenvolva sua saída de forma que ela seja lida em voz alta – ela será diretamente convertida em áudio.\n",
        "\n",
        "Faça o diálogo o mais longo e detalhado possível, mantendo-se no tema e garantindo um fluxo envolvente. Use sua capacidade total de produção para criar o episódio de podcast mais longo possível, enquanto comunica as informações principais do texto de entrada de maneira divertida.\n",
        "\n",
        "No final do diálogo, o apresentador e os convidados devem resumir naturalmente as principais ideias e insights de sua conversa. Isso deve fluir organicamente a partir da conversa, reiterando os pontos-chave de maneira casual e conversacional. Evite soar como um resumo óbvio – o objetivo é reforçar as ideias centrais uma última vez antes de finalizar.\n",
        "\n",
        "O podcast deve ter cerca de 20.000 palavras.\n",
        "\"\"\",\n",
        "    },\n",
        "\n",
        "################# PODCAST Hindi ##################\n",
        "\"podcast (Hindi)\": {\n",
        "    \"intro\": \"\"\"आपका कार्य दिए गए इनपुट टेक्स्ट को लेकर उसे एक जीवंत, आकर्षक और जानकारीपूर्ण पॉडकास्ट वार्तालाप में बदलना है, NPR की शैली में। इनपुट टेक्स्ट असंगठित या अव्यवस्थित हो सकता है, क्योंकि यह विभिन्न स्रोतों जैसे PDFs या वेब पेजों से आ सकता है।\n",
        "\n",
        "फ़ॉर्मेटिंग समस्याओं या अप्रासंगिक जानकारी की चिंता न करें; आपका उद्देश्य मुख्य बिंदुओं को निकालना, परिभाषाओं और दिलचस्प तथ्यों को पहचानना है जिन्हें पॉडकास्ट में चर्चा की जा सकती है।\n",
        "\n",
        "सभी उपयोग किए गए शब्दों को सावधानीपूर्वक व्यापक दर्शकों के लिए परिभाषित करें।\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"सबसे पहले, इनपुट टेक्स्ट को ध्यान से पढ़ें और मुख्य विषयों, प्रमुख बिंदुओं और किसी भी दिलचस्प तथ्य या उपाख्यानों की पहचान करें। इस जानकारी को प्रस्तुत करने के बारे में सोचें कि आप इसे एक मज़ेदार, आकर्षक तरीके से कैसे प्रस्तुत कर सकते हैं जो उच्च गुणवत्ता वाली प्रस्तुति के लिए उपयुक्त हो।\",\n",
        "    \"scratch_pad\": \"\"\"मुख्य विषयों और प्रमुख बिंदुओं पर चर्चा करने के रचनात्मक तरीकों के बारे में सोचें जिन्हें आपने इनपुट टेक्स्ट में पहचाना है। उदाहरणों, कहानियों की तकनीकों, या काल्पनिक परिदृश्यों का उपयोग करके सामग्री को श्रोताओं के लिए अधिक सम्बंधित और आकर्षक बनाने पर विचार करें।\n",
        "\n",
        "ध्यान रखें कि आपका पॉडकास्ट एक सामान्य दर्शक के लिए सुलभ होना चाहिए, इसलिए बहुत अधिक तकनीकी शब्दजाल से बचें या यह न मानें कि विषय का पूर्व ज्ञान है। यदि आवश्यक हो, तो किसी भी जटिल अवधारणा को सरल शब्दों में संक्षेप में समझाने के तरीकों के बारे में सोचें।\n",
        "\n",
        "अपनी कल्पना का उपयोग करके इनपुट टेक्स्ट में किसी भी अंतराल को भरें या पॉडकास्ट में खोजे जा सकने वाले विचारोत्तेजक सवालों के साथ आएं। उद्देश्य एक जानकारीपूर्ण और मनोरंजक वार्तालाप बनाना है, इसलिए अपने दृष्टिकोण में रचनात्मक होने से न डरें।\n",
        "\n",
        "सभी उपयोग किए गए शब्दों को स्पष्ट रूप से परिभाषित करें और पृष्ठभूमि समझाने के लिए समय दें।\n",
        "\n",
        "यहां अपने विचार-मंथन और पॉडकास्ट वार्तालाप के लिए एक मोटा खाका लिखें। सुनिश्चित करें कि आपने उन प्रमुख अंतर्दृष्टियों और निष्कर्षों को नोट किया है जिन्हें आप अंत में दोहराना चाहते हैं।\n",
        "\n",
        "इसे मजेदार और रोमांचक बनाएं।\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"अब जब आपने विचार-मंथन किया है और एक मोटा खाका तैयार कर लिया है, तो वास्तविक पॉडकास्ट वार्तालाप लिखने का समय आ गया है। होस्ट और किसी भी अतिथि वक्ता के बीच एक स्वाभाविक, संवादात्मक प्रवाह की दिशा में कार्य करें। अपने विचार-मंथन सत्र से सर्वश्रेष्ठ विचारों को शामिल करें और सुनिश्चित करें कि किसी भी जटिल विषय को आसानी से समझ में आने वाले तरीके से समझाया जाए।\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"यहां एक बहुत लंबा, आकर्षक और जानकारीपूर्ण पॉडकास्ट वार्तालाप लिखें, जो उन प्रमुख बिंदुओं और रचनात्मक विचारों पर आधारित हो जो आपने विचार-मंथन सत्र के दौरान बनाए थे। एक संवादात्मक शैली का उपयोग करें और सामग्री को एक सामान्य दर्शक के लिए सुलभ बनाने के लिए किसी भी आवश्यक संदर्भ या व्याख्याएं शामिल करें।\n",
        "\n",
        "होस्ट और अतिथि वक्ताओं के लिए कभी भी काल्पनिक नामों का उपयोग न करें, बल्कि श्रोताओं के लिए इसे एक आकर्षक और immersive अनुभव बनाएं। किसी भी प्रकार के ब्रैकेटेड प्लेसहोल्डर्स जैसे [होस्ट] या [अतिथि] को शामिल न करें। अपनी आउटपुट को इस तरह डिज़ाइन करें कि इसे ज़ोर से पढ़ा जा सके – इसे सीधे ऑडियो में परिवर्तित किया जाएगा।\n",
        "\n",
        "डायलॉग को यथासंभव लंबा और विस्तृत बनाएं, फिर भी विषय पर बने रहें और प्रवाह को आकर्षक बनाए रखें। अपनी पूरी आउटपुट क्षमता का उपयोग करते हुए यथासंभव लंबे पॉडकास्ट एपिसोड को बनाएं, जबकि फिर भी इनपुट टेक्स्ट से प्रमुख जानकारी को मनोरंजक तरीके से संप्रेषित करें।\n",
        "\n",
        "वार्तालाप के अंत में, होस्ट और अतिथि वक्ता अपने चर्चा से स्वाभाविक रूप से मुख्य अंतर्दृष्टियों और निष्कर्षों को संक्षेप में प्रस्तुत करें। यह वार्तालाप से स्वाभाविक रूप से प्रवाहित होना चाहिए, अनौपचारिक, संवादात्मक तरीके से प्रमुख बिंदुओं को फिर से स्पष्ट करें। इसे स्पष्ट पुनरावृत्ति की तरह न बनाएं – उद्देश्य केंद्रीय विचारों को एक आखिरी बार सुदृढ़ करना है, इससे पहले कि वार्तालाप समाप्त हो जाए।\n",
        "\n",
        "पॉडकास्ट में लगभग 20,000 शब्द होने चाहिए।\n",
        "\"\"\",\n",
        "    },\n",
        "\n",
        "################# PODCAST Chinese ##################\n",
        "\"podcast (Chinese)\": {\n",
        "    \"intro\": \"\"\"你的任务是将提供的输入文本转变为一个生动、有趣、信息丰富的播客对话,风格类似NPR。输入文本可能是凌乱的或未结构化的,因为它可能来自PDF或网页等各种来源。\n",
        "\n",
        "不要担心格式问题或任何无关的信息;你的目标是提取关键点,识别定义和可能在播客中讨论的有趣事实。\n",
        "\n",
        "为广泛的听众仔细定义所有使用的术语。\n",
        "\"\"\",\n",
        "    \"text_instructions\": \"首先,仔细阅读输入文本,识别主要话题、关键点和任何有趣的事实或轶事。思考如何以一种有趣且引人入胜的方式呈现这些信息,适合高质量的呈现。\",\n",
        "    \"scratch_pad\": \"\"\"集思广益,想出一些讨论你在输入文本中识别到的主要话题和关键点的创意方式。考虑使用类比、例子、讲故事的技巧或假设场景,让内容对听众更具相关性和吸引力。\n",
        "\n",
        "请记住,你的播客应面向普通大众,因此避免使用过多的行话或假设听众对该主题有预先的了解。如有必要,考虑简要解释任何复杂概念,用简单的术语进行说明。\n",
        "\n",
        "利用你的想象力填补输入文本中的任何空白,或提出一些值得探索的发人深省的问题。目标是创造一个信息丰富且有趣的对话,因此可以在方法上大胆创新。\n",
        "\n",
        "明确地定义所有使用的术语,并花时间解释背景。\n",
        "\n",
        "在这里写下你的头脑风暴想法和播客对话的粗略大纲。务必记录你想在结尾重复的关键见解和收获。\n",
        "\n",
        "确保让它有趣且令人兴奋。\n",
        "\"\"\",\n",
        "    \"prelude\": \"\"\"现在你已经进行了头脑风暴并创建了一个粗略大纲,是时候编写实际的播客对话了。目标是主持人与嘉宾之间的自然对话流。结合你头脑风暴中的最佳想法,并确保以简单易懂的方式解释任何复杂的主题。\n",
        "\"\"\",\n",
        "    \"dialog\": \"\"\"在这里写下一个非常长、引人入胜且信息丰富的播客对话,基于你在头脑风暴会议中提出的关键点和创意。使用对话语气,并包含任何必要的上下文或解释,使内容易于普通听众理解。\n",
        "\n",
        "不要为主持人和嘉宾使用虚构的名字,而是让听众体验一个引人入胜且沉浸式的经历。不要包括像[主持人]或[嘉宾]这样的占位符。设计你的输出以供大声朗读——它将被直接转换为音频。\n",
        "\n",
        "使对话尽可能长且详细,同时保持在主题上并维持引人入胜的流畅性。充分利用你的输出能力,创造尽可能长的播客节目,同时以有趣的方式传达输入文本中的关键信息。\n",
        "\n",
        "在对话的最后,主持人和嘉宾应自然总结他们讨论的主要见解和收获。这应从对话中自然流出,以随意、对话的方式重复关键点。避免显得像是显而易见的总结——目标是在结束前最后一次加强核心思想。\n",
        "\n",
        "播客应约有20,000字。\n",
        "\"\"\",\n",
        "    },\n",
        "\n",
        "}\n",
        "\n",
        "# Function to update instruction fields based on template selection\n",
        "def update_instructions(template):\n",
        "    return (\n",
        "        INSTRUCTION_TEMPLATES[template][\"intro\"],\n",
        "        INSTRUCTION_TEMPLATES[template][\"text_instructions\"],\n",
        "        INSTRUCTION_TEMPLATES[template][\"scratch_pad\"],\n",
        "        INSTRUCTION_TEMPLATES[template][\"prelude\"],\n",
        "        INSTRUCTION_TEMPLATES[template][\"dialog\"]\n",
        "           )\n",
        "\n",
        "import concurrent.futures as cf\n",
        "import glob\n",
        "import io\n",
        "import os\n",
        "import time\n",
        "from pathlib import Path\n",
        "from tempfile import NamedTemporaryFile\n",
        "from typing import List, Literal\n",
        "\n",
        "import gradio as gr\n",
        "\n",
        "from loguru import logger\n",
        "from openai import OpenAI\n",
        "from promptic import llm\n",
        "from pydantic import BaseModel, ValidationError\n",
        "from pypdf import PdfReader\n",
        "from tenacity import retry, retry_if_exception_type\n",
        "\n",
        "# Define standard values\n",
        "STANDARD_TEXT_MODELS = [\n",
        "    \"o1-preview-2024-09-12\",\n",
        "    \"o1-preview\",\n",
        "    \"gpt-4o-2024-08-06\",\n",
        "    \"gpt-4o-mini\",\n",
        "    \"o1-mini-2024-09-12\",\n",
        "    \"o1-mini\",\n",
        "    \"chatgpt-4o-latest\",\n",
        "    \"gpt-4-turbo\",\n",
        "    \"openai/custom_model\",\n",
        "]\n",
        "\n",
        "STANDARD_AUDIO_MODELS = [\n",
        "    \"tts-1\",\n",
        "    \"tts-1-hd\",\n",
        "]\n",
        "\n",
        "STANDARD_VOICES = [\n",
        "    \"alloy\",\n",
        "    \"echo\",\n",
        "    \"fable\",\n",
        "    \"onyx\",\n",
        "    \"nova\",\n",
        "    \"shimmer\",\n",
        "]\n",
        "\n",
        "class DialogueItem(BaseModel):\n",
        "    text: str\n",
        "    speaker: Literal[\"speaker-1\", \"speaker-2\"]\n",
        "\n",
        "class Dialogue(BaseModel):\n",
        "    scratchpad: str\n",
        "    dialogue: List[DialogueItem]\n",
        "\n",
        "def get_mp3(text: str, voice: str, audio_model: str, api_key: str = None) -> bytes:\n",
        "    client = OpenAI(\n",
        "        api_key=api_key or os.getenv(\"OPENAI_API_KEY\"),\n",
        "    )\n",
        "\n",
        "    with client.audio.speech.with_streaming_response.create(\n",
        "        model=audio_model,\n",
        "        voice=voice,\n",
        "        input=text,\n",
        "    ) as response:\n",
        "        with io.BytesIO() as file:\n",
        "            for chunk in response.iter_bytes():\n",
        "                file.write(chunk)\n",
        "            return file.getvalue()\n",
        "\n",
        "\n",
        "from functools import wraps\n",
        "\n",
        "def conditional_llm(model, api_base=None, api_key=None):\n",
        "    \"\"\"\n",
        "    Conditionally apply the @llm decorator based on the api_base parameter.\n",
        "    If api_base is provided, it applies the @llm decorator with api_base.\n",
        "    Otherwise, it applies the @llm decorator without api_base.\n",
        "    \"\"\"\n",
        "    def decorator(func):\n",
        "        if api_base:\n",
        "            return llm(model=model, api_base=api_base)(func)\n",
        "        else:\n",
        "            return llm(model=model, api_key=api_key)(func)\n",
        "    return decorator\n",
        "\n",
        "def generate_audio(\n",
        "    files: list,\n",
        "    openai_api_key: str = None,\n",
        "    text_model: str = \"o1-preview-2024-09-12\",\n",
        "    audio_model: str = \"tts-1\",\n",
        "    speaker_1_voice: str = \"alloy\",\n",
        "    speaker_2_voice: str = \"echo\",\n",
        "    api_base: str = None,\n",
        "    intro_instructions: str = '',\n",
        "    text_instructions: str = '',\n",
        "    scratch_pad_instructions: str = '',\n",
        "    prelude_dialog: str = '',\n",
        "    podcast_dialog_instructions: str = '',\n",
        "    edited_transcript: str = None,\n",
        "    user_feedback: str = None,\n",
        "    original_text: str = None,\n",
        "    debug = False,\n",
        ") -> tuple:\n",
        "    # Validate API Key\n",
        "    if not os.getenv(\"OPENAI_API_KEY\") and not openai_api_key:\n",
        "        raise gr.Error(\"OpenAI API key is required\")\n",
        "\n",
        "    combined_text = original_text or \"\"\n",
        "\n",
        "    # If there's no original text, extract it from the uploaded files\n",
        "    if not combined_text:\n",
        "        for file in files:\n",
        "            with Path(file).open(\"rb\") as f:\n",
        "                reader = PdfReader(f)\n",
        "                text = \"\\n\\n\".join([page.extract_text() for page in reader.pages if page.extract_text()])\n",
        "                combined_text += text + \"\\n\\n\"\n",
        "\n",
        "    # Configure the LLM based on selected model and api_base\n",
        "    @retry(retry=retry_if_exception_type(ValidationError))\n",
        "    @conditional_llm(model=text_model, api_base=api_base, api_key=openai_api_key)\n",
        "    def generate_dialogue(text: str, intro_instructions: str, text_instructions: str, scratch_pad_instructions: str, \n",
        "                          prelude_dialog: str, podcast_dialog_instructions: str,\n",
        "                          edited_transcript: str = None, user_feedback: str = None, ) -> Dialogue:\n",
        "        \"\"\"\n",
        "        {intro_instructions}\n",
        "        \n",
        "        Here is the original input text:\n",
        "        \n",
        "        <input_text>\n",
        "        {text}\n",
        "        </input_text>\n",
        "\n",
        "        {text_instructions}\n",
        "        \n",
        "        <scratchpad>\n",
        "        {scratch_pad_instructions}\n",
        "        </scratchpad>\n",
        "        \n",
        "        {prelude_dialog}\n",
        "        \n",
        "        <podcast_dialogue>\n",
        "        {podcast_dialog_instructions}\n",
        "        </podcast_dialogue>\n",
        "        {edited_transcript}{user_feedback}\n",
        "        \"\"\"\n",
        "\n",
        "    instruction_improve='Based on the original text, please generate an improved version of the dialogue by incorporating the edits, comments and feedback.'\n",
        "    edited_transcript_processed=\"\\nPreviously generated edited transcript, with specific edits and comments that I want you to carefully address:\\n\"+\"<edited_transcript>\\n\"+edited_transcript+\"</edited_transcript>\" if edited_transcript !=\"\" else \"\"\n",
        "    user_feedback_processed=\"\\nOverall user feedback:\\n\\n\"+user_feedback if user_feedback !=\"\" else \"\"\n",
        "\n",
        "    if edited_transcript_processed.strip()!='' or user_feedback_processed.strip()!='':\n",
        "        user_feedback_processed=\"<requested_improvements>\"+user_feedback_processed+\"\\n\\n\"+instruction_improve+\"</requested_improvements>\" \n",
        "    \n",
        "    if debug:\n",
        "        logger.info (edited_transcript_processed)\n",
        "        logger.info (user_feedback_processed)\n",
        "    \n",
        "    # Generate the dialogue using the LLM\n",
        "    llm_output = generate_dialogue(\n",
        "        combined_text,\n",
        "        intro_instructions=intro_instructions,\n",
        "        text_instructions=text_instructions,\n",
        "        scratch_pad_instructions=scratch_pad_instructions,\n",
        "        prelude_dialog=prelude_dialog,\n",
        "        podcast_dialog_instructions=podcast_dialog_instructions,\n",
        "        edited_transcript=edited_transcript_processed,\n",
        "        user_feedback=user_feedback_processed\n",
        "    )\n",
        "\n",
        "    # Generate audio from the transcript\n",
        "    audio = b\"\"\n",
        "    transcript = \"\"\n",
        "    characters = 0\n",
        "\n",
        "    with cf.ThreadPoolExecutor() as executor:\n",
        "        futures = []\n",
        "        for line in llm_output.dialogue:\n",
        "            transcript_line = f\"{line.speaker}: {line.text}\"\n",
        "            voice = speaker_1_voice if line.speaker == \"speaker-1\" else speaker_2_voice\n",
        "            future = executor.submit(get_mp3, line.text, voice, audio_model, openai_api_key)\n",
        "            futures.append((future, transcript_line))\n",
        "            characters += len(line.text)\n",
        "\n",
        "        for future, transcript_line in futures:\n",
        "            audio_chunk = future.result()\n",
        "            audio += audio_chunk\n",
        "            transcript += transcript_line + \"\\n\\n\"\n",
        "\n",
        "    logger.info(f\"Generated {characters} characters of audio\")\n",
        "\n",
        "    temporary_directory = \"./gradio_cached_examples/tmp/\"\n",
        "    os.makedirs(temporary_directory, exist_ok=True)\n",
        "\n",
        "    # Use a temporary file -- Gradio's audio component doesn't work with raw bytes in Safari\n",
        "    temporary_file = NamedTemporaryFile(\n",
        "        dir=temporary_directory,\n",
        "        delete=False,\n",
        "        suffix=\".mp3\",\n",
        "    )\n",
        "    temporary_file.write(audio)\n",
        "    temporary_file.close()\n",
        "\n",
        "    # Delete any files in the temp directory that end with .mp3 and are over a day old\n",
        "    for file in glob.glob(f\"{temporary_directory}*.mp3\"):\n",
        "        if os.path.isfile(file) and time.time() - os.path.getmtime(file) > 24 * 60 * 60:\n",
        "            os.remove(file)\n",
        "\n",
        "    return temporary_file.name, transcript, combined_text\n",
        "\n",
        "def validate_and_generate_audio(*args):\n",
        "    files = args[0]\n",
        "    if not files:\n",
        "        return None, None, None, \"Please upload at least one PDF file before generating audio.\"\n",
        "    try:\n",
        "        audio_file, transcript, original_text = generate_audio(*args)\n",
        "        return audio_file, transcript, original_text, None  # Return None as the error when successful\n",
        "    except Exception as e:\n",
        "        # If an error occurs during generation, return None for the outputs and the error message\n",
        "        return None, None, None, str(e)\n",
        "\n",
        "def edit_and_regenerate(edited_transcript, user_feedback, *args):\n",
        "    # Replace the original transcript and feedback in the args with the new ones\n",
        "    #new_args = list(args)\n",
        "    #new_args[-2] = edited_transcript  # Update edited transcript\n",
        "    #new_args[-1] = user_feedback  # Update user feedback\n",
        "    return validate_and_generate_audio(*new_args)\n",
        "\n",
        "# New function to handle user feedback and regeneration\n",
        "def process_feedback_and_regenerate(feedback, *args):\n",
        "    # Add user feedback to the args\n",
        "    new_args = list(args)\n",
        "    new_args.append(feedback)  # Add user feedback as a new argument\n",
        "    return validate_and_generate_audio(*new_args)\n",
        "\n",
        "with gr.Blocks(title=\"PDF to Audio\", css=\"\"\"\n",
        "    #header {\n",
        "        display: flex;\n",
        "        align-items: center;\n",
        "        justify-content: space-between;\n",
        "        padding: 20px;\n",
        "        background-color: transparent;\n",
        "        border-bottom: 1px solid #ddd;\n",
        "    }\n",
        "    #title {\n",
        "        font-size: 24px;\n",
        "        margin: 0;\n",
        "    }\n",
        "    #logo_container {\n",
        "        width: 200px;\n",
        "        height: 200px;\n",
        "        display: flex;\n",
        "        justify-content: center;\n",
        "        align-items: center;\n",
        "    }\n",
        "    #logo_image {\n",
        "        max-width: 100%;\n",
        "        max-height: 100%;\n",
        "        object-fit: contain;\n",
        "    }\n",
        "    #main_container {\n",
        "        margin-top: 20px;\n",
        "    }\n",
        "\"\"\") as demo:\n",
        "    \n",
        "    with gr.Row(elem_id=\"header\"):\n",
        "        with gr.Column(scale=4):\n",
        "            gr.Markdown(\"# Convert PDFs into an audio podcast, lecture, summary and others\\n\\nFirst, upload one or more PDFs, select options, then push Generate Audio.\\n\\nYou can also select a variety of custom option and direct the way the result is generated.\", elem_id=\"title\")\n",
        "        with gr.Column(scale=1):\n",
        "            gr.HTML('''\n",
        "                <div id=\"logo_container\">\n",
        "                    <img src=\"https://huggingface.co/spaces/lamm-mit/PDF2Audio/resolve/main/logo.png\" id=\"logo_image\" alt=\"Logo\">\n",
        "                </div>\n",
        "            ''')\n",
        "    #gr.Markdown(\"\")    \n",
        "    submit_btn = gr.Button(\"Generate Audio\", elem_id=\"submit_btn\")\n",
        "\n",
        "    with gr.Row(elem_id=\"main_container\"):\n",
        "        with gr.Column(scale=2):\n",
        "            files = gr.Files(label=\"PDFs\", file_types=[\"pdf\"], )\n",
        "            \n",
        "            openai_api_key = gr.Textbox(\n",
        "                label=\"OpenAI API Key\",\n",
        "                visible=True,  # Always show the API key field\n",
        "                placeholder=\"Enter your OpenAI API Key here...\",\n",
        "                type=\"password\"  # Hide the API key input\n",
        "            )\n",
        "            text_model = gr.Dropdown(\n",
        "                label=\"Text Generation Model\",\n",
        "                choices=STANDARD_TEXT_MODELS,\n",
        "                value=\"o1-preview-2024-09-12\", #\"gpt-4o-mini\",\n",
        "                info=\"Select the model to generate the dialogue text.\",\n",
        "            )\n",
        "            audio_model = gr.Dropdown(\n",
        "                label=\"Audio Generation Model\",\n",
        "                choices=STANDARD_AUDIO_MODELS,\n",
        "                value=\"tts-1\",\n",
        "                info=\"Select the model to generate the audio.\",\n",
        "            )\n",
        "            speaker_1_voice = gr.Dropdown(\n",
        "                label=\"Speaker 1 Voice\",\n",
        "                choices=STANDARD_VOICES,\n",
        "                value=\"alloy\",\n",
        "                info=\"Select the voice for Speaker 1.\",\n",
        "            )\n",
        "            speaker_2_voice = gr.Dropdown(\n",
        "                label=\"Speaker 2 Voice\",\n",
        "                choices=STANDARD_VOICES,\n",
        "                value=\"echo\",\n",
        "                info=\"Select the voice for Speaker 2.\",\n",
        "            )\n",
        "            api_base = gr.Textbox(\n",
        "                label=\"Custom API Base\",\n",
        "                placeholder=\"Enter custom API base URL if using a custom/local model...\",\n",
        "                info=\"If you are using a custom or local model, provide the API base URL here, e.g.: http://localhost:8080/v1 for llama.cpp REST server.\",\n",
        "            )\n",
        "\n",
        "        with gr.Column(scale=3):\n",
        "            template_dropdown = gr.Dropdown(\n",
        "                label=\"Instruction Template\",\n",
        "                choices=list(INSTRUCTION_TEMPLATES.keys()),\n",
        "                value=\"podcast\",\n",
        "                info=\"Select the instruction template to use. You can also edit any of the fields for more tailored results.\",\n",
        "            )\n",
        "            intro_instructions = gr.Textbox(\n",
        "                label=\"Intro Instructions\",\n",
        "                lines=10,\n",
        "                value=INSTRUCTION_TEMPLATES[\"podcast\"][\"intro\"],\n",
        "                info=\"Provide the introductory instructions for generating the dialogue.\",\n",
        "            )\n",
        "            text_instructions = gr.Textbox(\n",
        "                label=\"Standard Text Analysis Instructions\",\n",
        "                lines=10,\n",
        "                placeholder=\"Enter text analysis instructions...\",\n",
        "                value=INSTRUCTION_TEMPLATES[\"podcast\"][\"text_instructions\"],\n",
        "                info=\"Provide the instructions for analyzing the raw data and text.\",\n",
        "            )\n",
        "            scratch_pad_instructions = gr.Textbox(\n",
        "                label=\"Scratch Pad Instructions\",\n",
        "                lines=15,\n",
        "                value=INSTRUCTION_TEMPLATES[\"podcast\"][\"scratch_pad\"],\n",
        "                info=\"Provide the scratch pad instructions for brainstorming presentation/dialogue content.\",\n",
        "            )\n",
        "            prelude_dialog = gr.Textbox(\n",
        "                label=\"Prelude Dialog\",\n",
        "                lines=5,\n",
        "                value=INSTRUCTION_TEMPLATES[\"podcast\"][\"prelude\"],\n",
        "                info=\"Provide the prelude instructions before the presentation/dialogue is developed.\",\n",
        "            )\n",
        "            podcast_dialog_instructions = gr.Textbox(\n",
        "                label=\"Podcast Dialog Instructions\",\n",
        "                lines=20,\n",
        "                value=INSTRUCTION_TEMPLATES[\"podcast\"][\"dialog\"],\n",
        "                info=\"Provide the instructions for generating the presentation or podcast dialogue.\",\n",
        "            )\n",
        "\n",
        "    audio_output = gr.Audio(label=\"Audio\", format=\"mp3\", interactive=False, autoplay=False)\n",
        "    transcript_output = gr.Textbox(label=\"Transcript\", lines=20, show_copy_button=True)\n",
        "    original_text_output = gr.Textbox(label=\"Original Text\", lines=10, visible=False)\n",
        "    error_output = gr.Textbox(visible=False)  # Hidden textbox to store error message\n",
        "\n",
        "    use_edited_transcript = gr.Checkbox(label=\"Use Edited Transcript (check if you want to make edits to the initially generated transcript)\", value=False)\n",
        "    edited_transcript = gr.Textbox(label=\"Edit Transcript Here. E.g., mark edits in the text with clear instructions. E.g., '[ADD DEFINITION OF MATERIOMICS]'.\", lines=20, visible=False,\n",
        "                                   show_copy_button=True, interactive=False)\n",
        "\n",
        "    user_feedback = gr.Textbox(label=\"Provide Feedback or Notes\", lines=10, #placeholder=\"Enter your feedback or notes here...\"\n",
        "                              )\n",
        "    regenerate_btn = gr.Button(\"Regenerate Audio with Edits and Feedback\")\n",
        "    # Function to update the interactive state of edited_transcript\n",
        "    def update_edit_box(checkbox_value):\n",
        "        return gr.update(interactive=checkbox_value, lines=20 if checkbox_value else 20, visible=True if checkbox_value else False)\n",
        "\n",
        "    # Update the interactive state of edited_transcript when the checkbox is toggled\n",
        "    use_edited_transcript.change(\n",
        "        fn=update_edit_box,\n",
        "        inputs=[use_edited_transcript],\n",
        "        outputs=[edited_transcript]\n",
        "    )\n",
        "    # Update instruction fields when template is changed\n",
        "    template_dropdown.change(\n",
        "        fn=update_instructions,\n",
        "        inputs=[template_dropdown],\n",
        "        outputs=[intro_instructions, text_instructions, scratch_pad_instructions, prelude_dialog, podcast_dialog_instructions]\n",
        "    )\n",
        "    \n",
        "    submit_btn.click(\n",
        "        fn=validate_and_generate_audio,\n",
        "        inputs=[\n",
        "            files, openai_api_key, text_model, audio_model, \n",
        "            speaker_1_voice, speaker_2_voice, api_base,\n",
        "            intro_instructions, text_instructions, scratch_pad_instructions, \n",
        "            prelude_dialog, podcast_dialog_instructions, \n",
        "            edited_transcript,  # placeholder for edited_transcript\n",
        "            user_feedback,  # placeholder for user_feedback\n",
        "        ],\n",
        "        outputs=[audio_output, transcript_output, original_text_output, error_output]\n",
        "    ).then(\n",
        "        fn=lambda audio, transcript, original_text, error: (\n",
        "            transcript if transcript else \"\",\n",
        "            error if error else None\n",
        "        ),\n",
        "        inputs=[audio_output, transcript_output, original_text_output, error_output],\n",
        "        outputs=[edited_transcript, error_output]\n",
        "    ).then(\n",
        "        fn=lambda error: gr.Warning(error) if error else None,\n",
        "        inputs=[error_output],\n",
        "        outputs=[]\n",
        "    )\n",
        "\n",
        "    regenerate_btn.click(\n",
        "        fn=lambda use_edit, edit, *args: validate_and_generate_audio(\n",
        "            *args[:12],  # All inputs up to podcast_dialog_instructions\n",
        "            edit if use_edit else \"\",  # Use edited transcript if checkbox is checked, otherwise empty string\n",
        "            *args[12:]  # user_feedback and original_text_output\n",
        "        ),\n",
        "        inputs=[\n",
        "            use_edited_transcript, edited_transcript,\n",
        "            files, openai_api_key, text_model, audio_model, \n",
        "            speaker_1_voice, speaker_2_voice, api_base,\n",
        "            intro_instructions, text_instructions, scratch_pad_instructions, \n",
        "            prelude_dialog, podcast_dialog_instructions,\n",
        "            user_feedback, original_text_output\n",
        "        ],\n",
        "        outputs=[audio_output, transcript_output, original_text_output, error_output]\n",
        "    ).then(\n",
        "        fn=lambda audio, transcript, original_text, error: (\n",
        "            transcript if transcript else \"\",\n",
        "            error if error else None\n",
        "        ),\n",
        "        inputs=[audio_output, transcript_output, original_text_output, error_output],\n",
        "        outputs=[edited_transcript, error_output]\n",
        "    ).then(\n",
        "        fn=lambda error: gr.Warning(error) if error else None,\n",
        "        inputs=[error_output],\n",
        "        outputs=[]\n",
        "    )\n",
        "\n",
        "    # Add README content at the bottom\n",
        "    gr.Markdown(\"---\")  # Horizontal line to separate the interface from README\n",
        "    gr.Markdown(read_readme())\n",
        "    \n",
        "# Enable queueing for better performance\n",
        "demo.queue(max_size=20, default_concurrency_limit=32)\n",
        "\n",
        "# Launch the Gradio app\n",
        "if __name__ == \"__main__\":\n",
        "    demo.launch()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Fvlp5EvQ2ApM"
      },
      "source": [
        "## Credits\n",
        "\n",
        "This project was inspired by and based on the code available at [https://github.com/knowsuchagency/pdf-to-podcast](https://github.com/knowsuchagency/pdf-to-podcast) and [https://github.com/knowsuchagency/promptic](https://github.com/knowsuchagency/promptic).\n",
        "\n",
        "```bibtex\n",
        "@article{ghafarollahi2024sciagentsautomatingscientificdiscovery,\n",
        "    title={SciAgents: Automating scientific discovery through multi-agent intelligent graph reasoning},\n",
        "    author={Alireza Ghafarollahi and Markus J. Buehler},\n",
        "    year={2024},\n",
        "    eprint={2409.05556},\n",
        "    archivePrefix={arXiv},\n",
        "    primaryClass={cs.AI},\n",
        "    url={https://arxiv.org/abs/2409.05556},\n",
        "}\n",
        "@article{buehler2024graphreasoning,\n",
        "    title={Accelerating Scientific Discovery with Generative Knowledge Extraction, Graph-Based Representation, and Multimodal Intelligent Graph Reasoning},\n",
        "    author={Markus J. Buehler},\n",
        "    journal={Machine Learning: Science and Technology},\n",
        "    year={2024},\n",
        "    url={http://iopscience.iop.org/article/10.1088/2632-2153/ad7228},\n",
        "}\n",
        "```"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}