knowsuchagency commited on
Commit
07ea011
1 Parent(s): 592cbe6

feat: Update DialogueItem voice property to use speaker instead of deprecated values

Browse files
Files changed (1) hide show
  1. main.py +21 -9
main.py CHANGED
@@ -12,7 +12,15 @@ from pypdf import PdfReader
12
 
13
  class DialogueItem(BaseModel):
14
  text: str
15
- voice: Literal["alloy", "onyx", "fable"]
 
 
 
 
 
 
 
 
16
 
17
 
18
  class Dialogue(BaseModel):
@@ -23,27 +31,31 @@ class Dialogue(BaseModel):
23
  @llm(model="gemini/gemini-1.5-flash")
24
  def generate_dialogue(text: str) -> Dialogue:
25
  """
26
- Your task is to take the input text provided and turn it into an engaging, informative podcast dialogue. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages.
27
 
28
  Here is the input text you will be working with:
29
 
30
- ```
31
  {text}
32
- ```
33
 
34
  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 an audio podcast.
35
 
 
36
  Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.
37
 
38
  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.
39
 
40
  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.
41
 
42
- Write your brainstorming ideas and a rough outline for the podcast dialogue in a scratchpad.
 
43
 
44
  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.
45
 
46
- Write your engaging, informative podcast dialogue 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.
 
 
47
  """
48
 
49
 
@@ -63,7 +75,7 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
63
  return file.getvalue()
64
 
65
 
66
- def generate_audio(file: bytes, openai_api_key: str) -> bytes:
67
 
68
  if not os.getenv("OPENAI_API_KEY", openai_api_key):
69
  raise gr.Error("OpenAI API key is required")
@@ -78,8 +90,7 @@ def generate_audio(file: bytes, openai_api_key: str) -> bytes:
78
  characters = 0
79
 
80
  for line in llm_output.dialogue:
81
- logger.info(line.text)
82
- logger.info(line.voice)
83
 
84
  audio = get_mp3(line.text, line.voice, openai_api_key)
85
  result += audio
@@ -100,6 +111,7 @@ demo = gr.Interface(
100
  ),
101
  gr.Textbox(
102
  label="OpenAI API Key",
 
103
  ),
104
  ],
105
  outputs=[
 
12
 
13
  class DialogueItem(BaseModel):
14
  text: str
15
+ speaker: Literal["female-1", "male-1", "female-2"]
16
+
17
+ @property
18
+ def voice(self):
19
+ return {
20
+ "female-1": "alloy",
21
+ "male-1": "onyx",
22
+ "female-2": "shimmer",
23
+ }[self.speaker]
24
 
25
 
26
  class Dialogue(BaseModel):
 
31
  @llm(model="gemini/gemini-1.5-flash")
32
  def generate_dialogue(text: str) -> Dialogue:
33
  """
34
+ Your task is to take the input text provided and turn it into an engaging, informative podcast dialogue. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages. Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points and interesting facts that could be discussed in a podcast.
35
 
36
  Here is the input text you will be working with:
37
 
38
+ <input_text>
39
  {text}
40
+ </input_text>
41
 
42
  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 an audio podcast.
43
 
44
+ <scratchpad>
45
  Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.
46
 
47
  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.
48
 
49
  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.
50
 
51
+ Write your brainstorming ideas and a rough outline for the podcast dialogue here.
52
+ </scratchpad>
53
 
54
  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.
55
 
56
+ <podcast_dialogue>
57
+ Write your 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. Rather than adding variable brackets like `[Host Name]` or `[Guest Name]`, use made-up names for the host and any guest speakers to create a more engaging and immersive experience for listeners as your output will be used to generate audio.
58
+ </podcast_dialogue>
59
  """
60
 
61
 
 
75
  return file.getvalue()
76
 
77
 
78
+ def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:
79
 
80
  if not os.getenv("OPENAI_API_KEY", openai_api_key):
81
  raise gr.Error("OpenAI API key is required")
 
90
  characters = 0
91
 
92
  for line in llm_output.dialogue:
93
+ logger.info(f"{line.speaker}: {line.text}")
 
94
 
95
  audio = get_mp3(line.text, line.voice, openai_api_key)
96
  result += audio
 
111
  ),
112
  gr.Textbox(
113
  label="OpenAI API Key",
114
+ visible=not os.getenv("OPENAI_API_KEY"),
115
  ),
116
  ],
117
  outputs=[