File size: 2,380 Bytes
287cbe4
 
 
 
0c09796
287cbe4
0c09796
 
287cbe4
 
 
 
 
 
0c09796
287cbe4
 
 
 
 
 
 
 
 
 
 
 
4d2987c
287cbe4
4d2987c
287cbe4
 
 
 
4d2987c
 
 
287cbe4
 
 
 
 
5700b67
 
287cbe4
5700b67
4d2987c
287cbe4
57a39c2
5700b67
287cbe4
 
 
4d2987c
 
287cbe4
 
 
4d2987c
 
287cbe4
 
5700b67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import gradio as gr
from transformers import pipeline
from espnet2.bin.tts_inference import Text2Speech
import warnings
from krill_to_latin import Perevod


perevod  = Perevod()
warnings.filterwarnings('ignore')


def generateTextAndAudio(inputText, numGen):
    # --- Generating the Text ---
    # With the provided text from user, generate more text up to `numGen` tokens/sub-words
    inputText = perevod.translate_for_summarizer(inputText)
    textOutput = textGenerator(inputText, max_length=numGen)
    # The output of the text generator is a list of dictionaries, grab the first dictionary
    # then get the generated text from the dictionary using the `generated_text` key
    genText = textOutput[0]['generated_text']

    print("-" * 75)
    print("Input Text:", inputText)
    print("Generated Text:", genText)
    print("-" * 75)

    # --- Generating the Audio ---
    # With the newly generated text, generate some speech
    #audioOutput = audioGenerator(genText)
    # Get the wav data
    #genAudio = audioOutput['wav']

    # Return two things
    # 1) Generated Text
    # 2) 24k sampling rate, and the Generated Audio (wav) as numpy (instead of tensor)
    # return genText, (24000, genAudio.numpy())
    return genText
    

# Main
textGenerator = pipeline('text-generation', model='rifkat/GPTuz')
audioGenerator = Text2Speech.from_pretrained("espnet/kan-bayashi_ljspeech_joint_finetune_conformer_fastspeech2_hifigan")

input1_textbox = gr.Textbox(label="Tekst*")
input2_slider = gr.Slider(minimum=1, maximum=100, step=1, default=30, label="Generatsiya bo'ladigan so'zlar soni")

output1_textbox = gr.Textbox(label="Generatsiya bo'lgan tekst")
# output2_Audio = gr.Audio(label="Generatsiya bo'lgan audio")

title = "Tekst gereratsiya qiling!"
description = "Tekst kiriting va nechta so'z generatsiya qilishini"

examples = [
    ["Давлат хавфсизлик хизмати", 50],
    ["Шунинг учун биз", 30],
    ["Лекин бугун бу нарсани қилмасак", 60]
]
iface = gr.Interface(fn=generateTextAndAudio,
                     inputs=[input1_textbox, input2_slider],
                     # outputs=[output1_textbox, output2_Audio],
                     outputs=output1_textbox,
                     title=title,
                     description=description,
                     examples=examples).launch(debug=True)