File size: 1,369 Bytes
6db32b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import time
from deep_translator import GoogleTranslator

def tarjim(text, choice, progress = gr.Progress()):
    progress(0, desc="Tarjima qilish boshlandi. Iltimos ozgina vaqt kuting...")
    try:
        if text and choice: 
            support_languages = GoogleTranslator().get_supported_languages(as_dict=True)
            for i in progress.tqdm(range(100)):
                time.sleep(0.01)
            return GoogleTranslator(source='auto',target=support_languages[choice]).translate(text.replace('\n', ' '))
        else:
            return gr.Info("Kiritish maydoni bo'sh bo'lmasligi kerak %s" % text)
    except Exception as e:
        return gr.Error("Xatolik nomi: %s" % e)

with gr.Blocks() as demo:
    gr.Markdown(
    """
    # Tezkor tarjima!
    Ma'lumotlarni tezkor tajima qilish uchun kiritish maydonini bo'sh qoldirmang.
    """)
    with gr.Row():
        with gr.Column():
            tanlash = gr.Dropdown(label='Tilni tanlang', choices=GoogleTranslator().get_supported_languages(), value='uzbek')
            inp = gr.Textbox(label='kirish qismi', placeholder="Tarjima mantnini kiriting..." ,autofocus=True)
        with gr.Column():
            out = gr.Textbox(label='Natija', show_copy_button=True)
        theme=gr.themes.Base()
    inp.change(tarjim, [inp, tanlash], out)

if __name__ == "__main__":
    demo.launch()