Vincent Claes commited on
Commit
9fcc04d
1 Parent(s): 5aae428

first working version

Browse files
Files changed (4) hide show
  1. .gitignore +1 -0
  2. README.md +3 -0
  3. app.py +87 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
README.md CHANGED
@@ -20,4 +20,7 @@ You are a podcast editor that specialized to create a script out of a webpage.
20
  [BREAKS]
21
  - Use the <break time="1s"/> tag to add a pause in the speech. Use it after each paragraph and after a sentence when appropriate to get to a relax tone.
22
  - Use <break time="3s"/> for longer pauses, to emphasize a point.
 
 
 
23
  ```
 
20
  [BREAKS]
21
  - Use the <break time="1s"/> tag to add a pause in the speech. Use it after each paragraph and after a sentence when appropriate to get to a relax tone.
22
  - Use <break time="3s"/> for longer pauses, to emphasize a point.
23
+
24
+ [LINK]
25
+ {link}
26
  ```
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import numpy as np
2
+ import gradio
3
+ from openai import OpenAI
4
+ import tempfile
5
+ import os
6
+
7
+ from dotenv import load_dotenv
8
+ load_dotenv()
9
+
10
+ import uuid
11
+
12
+
13
+ client = OpenAI()
14
+
15
+ DEFAULT_SYSTEM_PROMPT = """
16
+ You are a podcast editor that specialized to create a script out of a webpage.
17
+
18
+ [TASKS]
19
+ - You will receive a link to a webpage about some content.
20
+ - You will create a script out of the content.
21
+ - The script should be 1 minute long if you read it out loud.
22
+ - Start with an intro to peak the interest of the listener.
23
+ - Then, summarize the content in a way that is easy to understand. Ask questions about the the content and answer them.
24
+ - Conclude with the most intriguing part of the content.
25
+ - Refrain from adding section headers in the script like [INTRUCTION], [CONTENT], [CONCLUSION].
26
+ - The script should be inspiring, written in colloquialism with english words and proverbs understood around the world.
27
+ - Write in a relax tone.
28
+ - Use filler words like 'um', 'ah', 'well' etc. to make it sound more natural.
29
+
30
+ [BREAKS]
31
+ - Use the <break time="1s"/> tag to add a pause in the speech. Use it after each paragraph and after a sentence when appropriate to get to a relax tone.
32
+ - Use <break time="3s"/> for longer pauses, to emphasize a point.
33
+ """
34
+
35
+ def generate_episode(system_prompt, weblink):
36
+ # sr = 48000
37
+ # a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
38
+ # frequency = a4_freq * 2 ** (tones_from_a4 / 12)
39
+ # duration = int(duration)
40
+ # audio = np.linspace(0, duration, duration * sr)
41
+ # audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
42
+ # return sr, audio
43
+ response = client.chat.completions.create(
44
+ model="gpt-4o",
45
+ messages=[
46
+ {"role": "system", "content": system_prompt},
47
+ {"role": "user", "content": weblink},
48
+ ]
49
+ )
50
+ script = response.choices[0].message.content
51
+ response = client.audio.speech.create(
52
+ model="tts-1",
53
+ voice="fable",
54
+ input=script,
55
+ )
56
+
57
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
58
+ temp_file.write(response.content)
59
+ # state["mp3_file"] = temp_file.name
60
+ return temp_file.name
61
+
62
+
63
+ def cleanup(state):
64
+ mp3_file_name = state.get("mp3_file")
65
+ if mp3_file_name and os.path.exists(mp3_file_name):
66
+ os.remove(mp3_file_name)
67
+ print(f"Removed file: {mp3_file_name}")
68
+ else:
69
+ print(f"No file found to delete: {mp3_file_name}")
70
+
71
+ demo = gradio.Interface(
72
+ fn=generate_episode,
73
+ inputs=[
74
+ gradio.Textbox(value=DEFAULT_SYSTEM_PROMPT, label="System Prompt"),
75
+ gradio.Textbox(value="https://en.wikipedia.org/wiki/Mount_Tambora", label="Weblink"),
76
+ # gradio.State(), # State to track the mp3 file
77
+
78
+ ],
79
+ # outputs=["audio", gradio.State()],
80
+ outputs="audio",
81
+
82
+ )
83
+
84
+ # demo.cleanup(cleanup)
85
+
86
+ if __name__ == "__main__":
87
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ python-dotenv
4
+ openai