LilyF commited on
Commit
d79329d
·
1 Parent(s): 5d73b0d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -15
app.py CHANGED
@@ -1,22 +1,46 @@
1
  import gradio as gr
 
 
2
 
3
- def my_function(input1, input2):
4
- print(input1)
5
- print(input2)
6
- return input1 + input2
7
 
8
- title = 'My gradio app'
9
- description = "My simple description for my first gradio app"
 
 
 
 
 
 
10
 
11
- input1_textbox = gr.Textbox(label="Context Box")
12
- input2_textbox = gr.Textbox(label="Question Box")
13
 
14
- output1_textbox = gr.Textbox()
 
 
 
 
15
 
16
- iface = gr.Interface(fn=my_function,
17
- inputs=[input1_textbox, input2_textbox],
18
- outputs=[output1_textbox],
19
- title=title,
20
- description=description)
 
 
 
21
 
22
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)