m-ric HF Staff commited on
Commit
7746966
·
1 Parent(s): 4d33cb7

Add prompts

Browse files
Files changed (2) hide show
  1. app.py +13 -20
  2. prompts.py +55 -0
app.py CHANGED
@@ -24,6 +24,8 @@ PODCAST_SUBJECT = list(top_papers.values())[0]
24
  # -----------------------------------------------------------------------------
25
  # LLM that writes the script (unchanged)
26
  # -----------------------------------------------------------------------------
 
 
27
  client = InferenceClient(
28
  "meta-llama/Llama-3.3-70B-Instruct",
29
  provider="cerebras",
@@ -33,21 +35,12 @@ client = InferenceClient(
33
 
34
  def generate_podcast_text(subject: str) -> str:
35
  """Ask the LLM for a script of a podcast given by two hosts."""
36
- prompt = f"""Generate the script of "Open Paper review", a podcast told by 2 hosts about.
37
-
38
- Here is the topic: it's the top trending paper on Hugging Face daily papers today. You will need to analyze it by bringing profound insights.
39
-
40
- {subject}
41
- The podcast should be an insightful discussion, with some amount of playful banter.
42
- Separate dialog as follows, each replica in one line prefaced by the host number, [S1] for the male host and [S2] for the female host, for instance:
43
- [S1] Hello, how are you?
44
- [S2] I'm good, thank you. How are you?
45
- [S1] I'm good, thank you.
46
- [S2] Great.
47
- The podcast should last around 5 minutes.
48
- """
49
  response = client.chat_completion(
50
- [{"role": "user", "content": prompt[:1000]}],
 
 
 
 
51
  max_tokens=8156,
52
  )
53
  return response.choices[0].message.content
@@ -60,8 +53,8 @@ CUDA_AVAILABLE = torch.cuda.is_available()
60
  kmodel = KModel().to("cuda" if CUDA_AVAILABLE else "cpu").eval()
61
  kpipeline = KPipeline(lang_code="a") # English voices
62
 
63
- MALE_VOICE = "am_michael" # [S1]
64
- FEMALE_VOICE = "af_heart" # [S2]
65
 
66
  # Pre‑warm voices to avoid first‑call latency
67
  for v in (MALE_VOICE, FEMALE_VOICE):
@@ -88,14 +81,14 @@ def process_audio_chunks(podcast_text: str, speed: float = 1.0) -> None:
88
  break
89
 
90
  # Expect "[S1] ..." or "[S2] ..."
91
- if line.startswith("[S1]"):
92
  pipeline_voice = pipeline_voice_male
93
  voice = MALE_VOICE
94
- utterance = line[len("[S1]"):].strip()
95
- elif line.startswith("[S2]"):
96
  pipeline_voice = pipeline_voice_female
97
  voice = FEMALE_VOICE
98
- utterance = line[len("[S2]"):].strip()
99
  else: # fallback
100
  pipeline_voice = pipeline_voice_female
101
  voice = FEMALE_VOICE
 
24
  # -----------------------------------------------------------------------------
25
  # LLM that writes the script (unchanged)
26
  # -----------------------------------------------------------------------------
27
+ from prompts import SYSTEM_PROMPT
28
+
29
  client = InferenceClient(
30
  "meta-llama/Llama-3.3-70B-Instruct",
31
  provider="cerebras",
 
35
 
36
  def generate_podcast_text(subject: str) -> str:
37
  """Ask the LLM for a script of a podcast given by two hosts."""
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  response = client.chat_completion(
39
+ [
40
+ {"role": "system", "content": SYSTEM_PROMPT},
41
+ {"role": "user", "content": f"""Here is the topic: it's the top trending paper on Hugging Face daily papers today. You will need to analyze it by bringing profound insights.
42
+ {subject[:1000]}"""},
43
+ ],
44
  max_tokens=8156,
45
  )
46
  return response.choices[0].message.content
 
53
  kmodel = KModel().to("cuda" if CUDA_AVAILABLE else "cpu").eval()
54
  kpipeline = KPipeline(lang_code="a") # English voices
55
 
56
+ MALE_VOICE = "am_michael" # [MIKE]
57
+ FEMALE_VOICE = "af_heart" # [JANE]
58
 
59
  # Pre‑warm voices to avoid first‑call latency
60
  for v in (MALE_VOICE, FEMALE_VOICE):
 
81
  break
82
 
83
  # Expect "[S1] ..." or "[S2] ..."
84
+ if line.startswith("[MIKE]"):
85
  pipeline_voice = pipeline_voice_male
86
  voice = MALE_VOICE
87
+ utterance = line[len("[MIKE]"):].strip()
88
+ elif line.startswith("[JANE]"):
89
  pipeline_voice = pipeline_voice_female
90
  voice = FEMALE_VOICE
91
+ utterance = line[len("[JANE]"):].strip()
92
  else: # fallback
93
  pipeline_voice = pipeline_voice_female
94
  voice = FEMALE_VOICE
prompts.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # System prompt taken from the great space by Gabriel Chua: https://huggingface.co/spaces/gabrielchua/open-notebooklm/blob/main/prompts.py
2
+
3
+ SYSTEM_PROMPT = """
4
+ You are a world-class podcast producer tasked with transforming the provided input text into an engaging and informative podcast script. The input may be unstructured or messy, sourced from PDFs or web pages. Your goal is to extract the most interesting and insightful content for a compelling podcast discussion.
5
+ # Steps to Follow:
6
+
7
+ ### 1. Analyze the Input:
8
+ Carefully examine the text, identifying key topics, points, and interesting facts or anecdotes that could drive an engaging podcast conversation. Disregard irrelevant information or formatting issues.
9
+ DO this under the <analysis> part
10
+
11
+ ### 2. Brainstorm Ideas:
12
+ In the <scratchpad> part, creatively brainstorm ways to present the key points engagingly. Consider:
13
+ - Analogies, storytelling techniques, or hypothetical scenarios to make content relatable
14
+ - Ways to make complex topics accessible to a general audience
15
+ - Thought-provoking questions to explore during the podcast
16
+ - Creative approaches to fill any gaps in the information
17
+
18
+ ### 3. Craft the Dialogue:
19
+ Develop a natural, conversational flow between the two hosts named Jane and Mike. Incorporate:
20
+ - The best ideas from your brainstorming session
21
+ - Clear explanations of complex topics
22
+ - An engaging and lively tone to captivate listeners
23
+ - A balance of information and entertainment
24
+ Rules for the dialogue:
25
+ - The female host (Jane) always initiates the conversation and interviews the guest
26
+ - Include thoughtful questions from the host to guide the discussion
27
+ - Incorporate natural speech patterns, including occasional verbal fillers (e.g., "um," "well," "you know")
28
+ - Allow for natural interruptions and back-and-forth between host and guest
29
+ - Ensure the guest's responses are substantiated by the input text, avoiding unsupported claims
30
+ - Maintain a PG-rated conversation appropriate for all audiences
31
+ - The host concludes the conversation
32
+ **Summarize Key Insights:**
33
+ Naturally weave a summary of key points into the closing part of the dialogue. This should feel like a casual conversation rather than a formal recap, reinforcing the main takeaways before signing off.
34
+ **Maintain Authenticity:**
35
+ Throughout the script, strive for authenticity in the conversation. Include:
36
+ - Moments of genuine curiosity or surprise from the host
37
+ - Instances where one of the hosts might briefly struggle to articulate a complex idea
38
+ - Light-hearted moments or humor when appropriate
39
+ - Brief personal anecdotes or examples that relate to the topic (within the bounds of the input text)
40
+ **Consider Pacing and Structure:
41
+ Ensure the dialogue has a natural ebb and flow:
42
+ - Start with a strong hook to grab the listener's attention
43
+ - Gradually build complexity as the conversation progresses
44
+ - Include brief "breather" moments for listeners to absorb complex information
45
+ - End on a high note, perhaps with a thought-provoking question or a call-to-action for listeners
46
+
47
+ IMPORTANT RULE: Each line of dialogue should go in a new line [JANE] or [MIKE], as follows:
48
+
49
+ [JANE] Hello, how are you?
50
+ [MIKE] I'm good, thank you. How are you?
51
+ [JANE] I'm good, thank you.
52
+ [MIKE] Great.
53
+
54
+ Remember: Each intervention from a host should be on the same line.
55
+ """