Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import torch
|
|
4 |
import gradio as gr
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
from huggingface_hub import snapshot_download
|
|
|
|
|
7 |
import logging
|
8 |
|
9 |
logging.basicConfig(level=logging.INFO)
|
@@ -28,6 +30,40 @@ VOICES = ["tara", "leah", "jess", "leo", "dan", "mia", "zac", "zoe"]
|
|
28 |
# Available Emotive Tags
|
29 |
EMOTIVE_TAGS = ["`<laugh>`", "`<chuckle>`", "`<sigh>`", "`<cough>`", "`<sniffle>`", "`<groan>`", "`<yawn>`", "`<gasp>`"]
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
def process_prompt(prompt, voice, tokenizer, device):
|
32 |
prompt = f"{voice}: {prompt}"
|
33 |
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
@@ -122,18 +158,17 @@ def generate_speech(text, voice, temperature, top_p, repetition_penalty, max_new
|
|
122 |
return None
|
123 |
|
124 |
with gr.Blocks(title="Orpheus Text-to-Speech") as demo:
|
125 |
-
gr.Markdown(f"""
|
126 |
-
# 🎵 [Orpheus Text-to-Speech](https://github.com/canopyai/Orpheus-TTS)
|
127 |
-
Enter your text below and hear it converted to natural-sounding speech with the Orpheus TTS model.
|
128 |
-
|
129 |
-
## Tips for better prompts:
|
130 |
-
- Add paralinguistic elements like {", ".join(EMOTIVE_TAGS)} or `uhm` for more human-like speech.
|
131 |
-
- Longer text prompts generally work better than very short phrases
|
132 |
-
""")
|
133 |
-
|
134 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
with gr.Column(scale=2):
|
136 |
-
|
137 |
voice = gr.Dropdown(
|
138 |
choices=VOICES,
|
139 |
value="tara",
|
@@ -170,16 +205,22 @@ with gr.Blocks(title="Orpheus Text-to-Speech") as demo:
|
|
170 |
with gr.Column(scale=2):
|
171 |
audio_output = gr.Audio(label="Generated Speech", type="numpy")
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
submit_btn.click(
|
174 |
fn=generate_speech,
|
175 |
-
inputs=[
|
176 |
outputs=audio_output
|
177 |
)
|
178 |
|
179 |
clear_btn.click(
|
180 |
-
fn=lambda: (None, None),
|
181 |
inputs=[],
|
182 |
-
outputs=[
|
183 |
)
|
184 |
|
185 |
if __name__ == "__main__":
|
|
|
4 |
import gradio as gr
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
from huggingface_hub import snapshot_download
|
7 |
+
import google.generativeai as genai
|
8 |
+
import re
|
9 |
import logging
|
10 |
|
11 |
logging.basicConfig(level=logging.INFO)
|
|
|
30 |
# Available Emotive Tags
|
31 |
EMOTIVE_TAGS = ["`<laugh>`", "`<chuckle>`", "`<sigh>`", "`<cough>`", "`<sniffle>`", "`<groan>`", "`<yawn>`", "`<gasp>`"]
|
32 |
|
33 |
+
@spaces.GPU()
|
34 |
+
def generate_podcast_script(api_key, prompt, uploaded_file, duration, num_hosts):
|
35 |
+
try:
|
36 |
+
genai.configure(api_key=api_key)
|
37 |
+
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
38 |
+
|
39 |
+
combined_content = prompt or ""
|
40 |
+
if uploaded_file:
|
41 |
+
file_content = uploaded_file.read().decode('utf-8')
|
42 |
+
combined_content += "\n" + file_content if combined_content else file_content
|
43 |
+
|
44 |
+
prompt = f"""
|
45 |
+
Create a podcast script for {'one person' if num_hosts == 1 else 'two people'} discussing:
|
46 |
+
{combined_content}
|
47 |
+
|
48 |
+
Duration: {duration} minutes. Include natural speech, humor, and occasional off-topic thoughts.
|
49 |
+
Use speech fillers like um, ah. Vary emotional tone.
|
50 |
+
|
51 |
+
Format: {'Monologue' if num_hosts == 1 else 'Alternating dialogue'} without speaker labels.
|
52 |
+
Separate {'paragraphs' if num_hosts == 1 else 'lines'} with blank lines.
|
53 |
+
|
54 |
+
Use emotion tags in angle brackets: <laugh>, <sigh>, <chuckle>, <cough>, <sniffle>, <groan>, <yawn>, <gasp>.
|
55 |
+
|
56 |
+
Example: "I can't believe I stayed up all night <yawn> only to find out the meeting was canceled <groan>."
|
57 |
+
|
58 |
+
Ensure content flows naturally and stays on topic. Match the script length to {duration} minutes.
|
59 |
+
"""
|
60 |
+
|
61 |
+
response = model.generate_content(prompt)
|
62 |
+
return re.sub(r'[^a-zA-Z0-9\s.,?!<>]', '', response.text)
|
63 |
+
except Exception as e:
|
64 |
+
logger.error(f"Error generating podcast script: {str(e)}")
|
65 |
+
raise
|
66 |
+
|
67 |
def process_prompt(prompt, voice, tokenizer, device):
|
68 |
prompt = f"{voice}: {prompt}"
|
69 |
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
|
|
|
158 |
return None
|
159 |
|
160 |
with gr.Blocks(title="Orpheus Text-to-Speech") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
with gr.Row():
|
162 |
+
with gr.Column(scale=1):
|
163 |
+
gemini_api_key = gr.Textbox(label="Gemini API Key", type="password")
|
164 |
+
prompt = gr.Textbox(label="Prompt", lines=8, placeholder="Enter your text here...")
|
165 |
+
uploaded_file = gr.File(label="Upload File")
|
166 |
+
duration = gr.Slider(minimum=1, maximum=60, value=5, step=1, label="Duration (minutes)")
|
167 |
+
num_hosts = gr.Radio(["1", "2"], label="Number of Hosts", value="1")
|
168 |
+
generate_script_btn = gr.Button("Generate Podcast Script")
|
169 |
+
|
170 |
with gr.Column(scale=2):
|
171 |
+
script_output = gr.Textbox(label="Generated Script", lines=10)
|
172 |
voice = gr.Dropdown(
|
173 |
choices=VOICES,
|
174 |
value="tara",
|
|
|
205 |
with gr.Column(scale=2):
|
206 |
audio_output = gr.Audio(label="Generated Speech", type="numpy")
|
207 |
|
208 |
+
generate_script_btn.click(
|
209 |
+
fn=generate_podcast_script,
|
210 |
+
inputs=[gemini_api_key, prompt, uploaded_file, duration, num_hosts],
|
211 |
+
outputs=script_output
|
212 |
+
)
|
213 |
+
|
214 |
submit_btn.click(
|
215 |
fn=generate_speech,
|
216 |
+
inputs=[script_output, voice, temperature, top_p, repetition_penalty, max_new_tokens],
|
217 |
outputs=audio_output
|
218 |
)
|
219 |
|
220 |
clear_btn.click(
|
221 |
+
fn=lambda: (None, None, None),
|
222 |
inputs=[],
|
223 |
+
outputs=[prompt, script_output, audio_output]
|
224 |
)
|
225 |
|
226 |
if __name__ == "__main__":
|