Spaces:
Sleeping
Sleeping
added conversations
Browse files
app.py
CHANGED
|
@@ -1,23 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import os, torch, io
|
|
|
|
| 4 |
os.system('python -m unidic download')
|
| 5 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
| 6 |
from melo.api import TTS
|
| 7 |
import tempfile
|
| 8 |
|
| 9 |
@spaces.GPU
|
| 10 |
-
def synthesize(
|
| 11 |
speed = 1.0
|
| 12 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 13 |
models = {
|
| 14 |
-
|
| 15 |
}
|
| 16 |
-
speakers=['EN-US','EN-Default']
|
| 17 |
-
|
| 18 |
-
models['EN'].tts_to_file(text, models['EN'].hps.data.spk2id[speakers[1]], bio, speed=speed, pbar=progress.tqdm, format='wav')
|
| 19 |
-
return bio.getvalue()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
with gr.Blocks() as demo:
|
| 23 |
gr.Markdown('# Article to Podcast')
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
import os, torch, io
|
| 4 |
+
import json
|
| 5 |
os.system('python -m unidic download')
|
| 6 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
| 7 |
from melo.api import TTS
|
| 8 |
import tempfile
|
| 9 |
|
| 10 |
@spaces.GPU
|
| 11 |
+
def synthesize(conversation_text, speed, progress=gr.Progress()):
|
| 12 |
speed = 1.0
|
| 13 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 14 |
models = {
|
| 15 |
+
'EN': TTS(language='EN', device=device),
|
| 16 |
}
|
| 17 |
+
speakers = ['EN-US', 'EN-Default']
|
| 18 |
+
final_bio = io.BytesIO()
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
conversation = json.loads(conversation_text)
|
| 21 |
+
for i, turn in enumerate(conversation["conversation"]):
|
| 22 |
+
bio = io.BytesIO()
|
| 23 |
+
text = turn["text"]
|
| 24 |
+
speaker = speakers[i % 2]
|
| 25 |
+
speaker_id = models['EN'].hps.data.spk2id[speaker]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
models['EN'].tts_to_file(text, speaker_id, bio, speed=speed, pbar=progress.tqdm, format='wav')
|
| 29 |
+
bio.seek(0)
|
| 30 |
+
final_bio.write(bio.read())
|
| 31 |
+
|
| 32 |
+
final_bio.seek(0)
|
| 33 |
+
return final_bio.getvalue()
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
gr.Markdown('# Article to Podcast')
|