Spaces:
Running
on
Zero
Running
on
Zero
Upload 2 files
Browse files- app.py +14 -1
- requirements.txt +1 -0
app.py
CHANGED
@@ -6,6 +6,7 @@ import noisereduce as nr
|
|
6 |
import numpy as np
|
7 |
import os
|
8 |
import phonemizer
|
|
|
9 |
import random
|
10 |
import re
|
11 |
import spaces
|
@@ -314,7 +315,7 @@ def lf_generate(segments, voice, speed=1.0, reduce_noise=0.5, opening_cut=4000,
|
|
314 |
outs = lf_forward(token_lists[i:i+batch_size], voice, speed)
|
315 |
except gr.exceptions.Error as e:
|
316 |
if wavs:
|
317 |
-
gr.Warning(e)
|
318 |
else:
|
319 |
raise gr.Error(e)
|
320 |
break
|
@@ -343,10 +344,22 @@ def did_change_segments(segments):
|
|
343 |
gr.Button(f'Generate x{x}', variant='primary' if x else 'secondary', interactive=x > 0),
|
344 |
]
|
345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
with gr.Blocks() as lf_tts:
|
347 |
with gr.Row():
|
348 |
with gr.Column():
|
|
|
349 |
text = gr.Textbox(label='Input Text')
|
|
|
350 |
voice = gr.Dropdown(list(CHOICES.items()), label='Voice')
|
351 |
with gr.Accordion('Text Settings', open=False):
|
352 |
skip_square_brackets = gr.Checkbox(True, label='Skip [Square Brackets]', info='Recommended for academic papers, Wikipedia articles, or texts with citations.')
|
|
|
6 |
import numpy as np
|
7 |
import os
|
8 |
import phonemizer
|
9 |
+
import pypdf
|
10 |
import random
|
11 |
import re
|
12 |
import spaces
|
|
|
315 |
outs = lf_forward(token_lists[i:i+batch_size], voice, speed)
|
316 |
except gr.exceptions.Error as e:
|
317 |
if wavs:
|
318 |
+
gr.Warning(str(e))
|
319 |
else:
|
320 |
raise gr.Error(e)
|
321 |
break
|
|
|
344 |
gr.Button(f'Generate x{x}', variant='primary' if x else 'secondary', interactive=x > 0),
|
345 |
]
|
346 |
|
347 |
+
def extract_text(file):
|
348 |
+
if file.endswith('.pdf'):
|
349 |
+
with open(file, 'rb') as rb:
|
350 |
+
pdf_reader = pypdf.PdfReader(rb)
|
351 |
+
return '\n'.join([page.extract_text() for page in pdf_reader.pages])
|
352 |
+
elif file.endswith('.txt'):
|
353 |
+
with open(file, 'r') as r:
|
354 |
+
return '\n'.join([line for line in r])
|
355 |
+
return None
|
356 |
+
|
357 |
with gr.Blocks() as lf_tts:
|
358 |
with gr.Row():
|
359 |
with gr.Column():
|
360 |
+
file_input = gr.File(file_types=['.pdf', '.txt'], label='Input File: pdf or txt')
|
361 |
text = gr.Textbox(label='Input Text')
|
362 |
+
file_input.upload(fn=extract_text, inputs=[file_input], outputs=[text])
|
363 |
voice = gr.Dropdown(list(CHOICES.items()), label='Voice')
|
364 |
with gr.Accordion('Text Settings', open=False):
|
365 |
skip_square_brackets = gr.Checkbox(True, label='Skip [Square Brackets]', info='Recommended for academic papers, Wikipedia articles, or texts with citations.')
|
requirements.txt
CHANGED
@@ -4,6 +4,7 @@ mojimoji
|
|
4 |
munch
|
5 |
noisereduce
|
6 |
phonemizer
|
|
|
7 |
scipy
|
8 |
torch
|
9 |
transformers
|
|
|
4 |
munch
|
5 |
noisereduce
|
6 |
phonemizer
|
7 |
+
pypdf
|
8 |
scipy
|
9 |
torch
|
10 |
transformers
|