Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,46 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
print(input1)
|
5 |
-
print(input2)
|
6 |
-
return input1 + input2
|
7 |
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
input2_textbox = gr.Textbox(label="Question Box")
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from espnet2.bin.tts_inference import Text2Speech
|
4 |
|
5 |
+
def generateTextAndAudio(inputText, numGen):
|
|
|
|
|
|
|
6 |
|
7 |
+
# --- Generating the Text ---
|
8 |
+
# With the provided text from user, generate more text up to `numGen` tokens/sub-words
|
9 |
+
textOutput = textGenerator(inputText, max_length = numGen)
|
10 |
+
# The output of the text generator is a list of dictionaries, grab the first dictionary
|
11 |
+
# then get the generated text from the dictionary using the `generated_text` key
|
12 |
+
genText = textOutput[0]['generated_text']
|
13 |
+
|
14 |
+
print("Input Text:", inputText)
|
15 |
|
16 |
+
print("Generated Text:", genText)
|
|
|
17 |
|
18 |
+
# --- Generating the Audio ---
|
19 |
+
# With the newly generated text, generate some speech
|
20 |
+
audioOutput = audioGenerator(genText)
|
21 |
+
# Get the wav data
|
22 |
+
genAudio = audioOutput['wav']
|
23 |
|
24 |
+
# Return two things
|
25 |
+
# 1) Generated Text
|
26 |
+
# 2) 24k sampling rate, and the Generated Audio (wav) as numpy (instead of tensor)
|
27 |
+
return genText, (24000, genAudio.numpy())
|
28 |
+
|
29 |
+
# Main
|
30 |
+
textGenerator = pipeline('text-generation', model = 'gpt2')
|
31 |
+
audioGenerator = Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_joint_finetune_conformer_fastspeech2_hifigan")
|
32 |
|
33 |
+
input1_textbox = gr.Textbox(label="Input text")
|
34 |
+
input2_slider = gr.Slider(minimum=1, maximum=100, step=1, default=30, label="Number of words to generate")
|
35 |
+
|
36 |
+
output1_textbox = gr.Textbox(label = "Generated Text")
|
37 |
+
output2_Audio = gr.Audio(label = "Generated Audio")
|
38 |
+
|
39 |
+
title = "Generate Text and it's Audio!"
|
40 |
+
description = "Provide the text, and how many subwords to generate"
|
41 |
+
|
42 |
+
iface = gr.Interface(fn=generateTextAndAudio,
|
43 |
+
inputs=[input1_textbox, input2_slider],
|
44 |
+
outputs=[output1_textbox, output2_Audio],
|
45 |
+
title=title,
|
46 |
+
description=description).launch(debug = True)
|