Skip to content

Commit

Permalink
feat: Update DialogueItem voice property to use speaker instead of de…
Browse files Browse the repository at this point in the history
…precated values
  • Loading branch information
knowsuchagency committed Jun 9, 2024
1 parent 592cbe6 commit 07ea011
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@

class DialogueItem(BaseModel):
text: str
voice: Literal["alloy", "onyx", "fable"]
speaker: Literal["female-1", "male-1", "female-2"]

@property
def voice(self):
return {
"female-1": "alloy",
"male-1": "onyx",
"female-2": "shimmer",
}[self.speaker]


class Dialogue(BaseModel):
Expand All @@ -23,27 +31,31 @@ class Dialogue(BaseModel):
@llm(model="gemini/gemini-1.5-flash")
def generate_dialogue(text: str) -> Dialogue:
"""
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.
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.
Here is the input text you will be working with:
```
<input_text>
{text}
```
</input_text>
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.
<scratchpad>
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.
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.
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.
Write your brainstorming ideas and a rough outline for the podcast dialogue in a scratchpad.
Write your brainstorming ideas and a rough outline for the podcast dialogue here.
</scratchpad>
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.
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.
<podcast_dialogue>
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.
</podcast_dialogue>
"""


Expand All @@ -63,7 +75,7 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
return file.getvalue()


def generate_audio(file: bytes, openai_api_key: str) -> bytes:
def generate_audio(file: bytes, openai_api_key: str = None) -> bytes:

if not os.getenv("OPENAI_API_KEY", openai_api_key):
raise gr.Error("OpenAI API key is required")
Expand All @@ -78,8 +90,7 @@ def generate_audio(file: bytes, openai_api_key: str) -> bytes:
characters = 0

for line in llm_output.dialogue:
logger.info(line.text)
logger.info(line.voice)
logger.info(f"{line.speaker}: {line.text}")

audio = get_mp3(line.text, line.voice, openai_api_key)
result += audio
Expand All @@ -100,6 +111,7 @@ def generate_audio(file: bytes, openai_api_key: str) -> bytes:
),
gr.Textbox(
label="OpenAI API Key",
visible=not os.getenv("OPENAI_API_KEY"),
),
],
outputs=[
Expand Down

0 comments on commit 07ea011

Please sign in to comment.