-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
105 lines (85 loc) · 4.92 KB
/
Copy pathscript.py
File metadata and controls
105 lines (85 loc) · 4.92 KB
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
def generate_script(
pdf_text: str, mood: str = "funny", podcast_length: int = 300,
format: bool = True, anthropic_client: object = None) -> str:
"""
Generates a podcast script based on the provided document text.
This function uses an AI model to analyze the given text and create a podcast script
featuring a conversation between a host and a guest. The script includes an
introduction, discussion, real-world implications, and a conclusion.
Optionally, the script can be formatted into a specific dialogue tuple format.
Args:
text (str): The document text to be analyzed and converted into a podcast script.
style (str, optional): The tone/style of the podcast script. Defaults to "funny".
podcast_length (int, optional): The desired length of the podcast script in words.
Defaults to 300.
format (bool, optional): Whether to format the script into a dialogue tuple format.
Defaults to True.
Returns:
str: The generated podcast script, optionally formatted as specified.
"""
prompt = f"""
Please analyize the following document:
<document>{pdf_text}</document>
Based on the content of the document, create a podcast story with a conversation
between a host and a guest. Choose two gender-neutral real human names for the host
and guest that are relevant to the document's topic. Structure the podcast as follows:
1. Introduction: The host welcomes the audience and introduces the guest, providing
brief background information relevant to the document's topic.
2. Discussion: The host and guest engage in a conversation, discussing key points,
themes, and insights from the document. Include questions from the host and
responses from the guest that provide unique perspectives and interpretations of
the document's content.
3. Real-world implications: Have the host and guest explore how the document's content
relates to real-world scenarios, current events, or future possibilities. Encourage
them to share personal anecdotes or examples that illustrate the relevance of the
document's themes.
4. Conclusion: The host summarizes the main takeaways from the conversation and thanks
the guest for their insights. End with a call-to-action or final thought that ties
the document's content to the broader context of the podcast's theme.
Please generate the podcast script in a conversational tone, with clear distinctions
between the host and guest. Aim for a total word count of approximately {podcast_length}
words. The style and mood of the podcast script should be {mood}.
"""
response = anthropic_client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=4096,
messages=[
{"role": "user", "content": prompt},
{"role": "assistant", "content": "Here's a podcast script:"},
],
)
script = response.content[0].text
if format:
prompt = f"""Please take the following podcast script and convert it into the format shown below:
[ ("host", "Welcome to Tech Talk, where we delve into the latest advancements in
the world of technology. Today, we're joined by Dr. Mark Multimodal, who's here to
discuss his groundbreaking research on Google Gemini 1.5, a new AI model capable of
understanding incredibly long and complex information across different formats like
text, video, and audio. Dr. Multimodal, welcome to the show!"),
("guest", "Thank you, Tanya. It's a pleasure to be here."), ... ]
The script to be converted: {script}
Guidelines:
1. Each line of dialogue should be a tuple, with the first element being the speaker
(either "host" or the "guest") and the second element being the dialogue text.
2. Enclose each dialogue tuple in parentheses and separate them with commas.
3. Assign the resulting list of tuples to no variable, keep in list.
4. If the speaker's name in the original script doesn't exactly match "Host" or the
guest's name, replace it with the appropriate standardized name.
5. Remove any extra lines or text that are not part of the dialogue, such as scene
descriptions or actions.
Please generate the output in the specified format, ensuring that it accurately
represents the conversation between the host and the guest from the original
podcast script."""
response = anthropic_client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=4096,
messages=[
{"role": "user", "content": prompt},
{
"role": "assistant",
"content": "Here's your reformatted podcast script:",
},
],
)
script = response.content[0].text
return script