File size: 2,802 Bytes
ff6bf1d
 
 
 
83acec9
ff6bf1d
45a9671
ff6bf1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import requests
import gradio as gr
import time
from pydub import AudioSegment

API_URL = "https://api-inference.huggingface.co/models/oyqiz/uzbek_stt_1_version"
headers = {"Authorization": "Bearer "+ api_key }

def query(filename, progress=gr.Progress()):
    try:
        progress(0, desc="Matnga o'tkazish boshlandi. Iltimos ozgina kuting...")
        if filename is None:
            return gr.Warning("Siz kiritgan fayl turida xatolik bor %s" %filename)
        else:
            with open(filename, "rb") as f:
                data = f.read()

            # Audio faylning uzunligini tekshirish
            audio = AudioSegment.from_file(filename)
            duration_seconds = audio.duration_seconds
            if duration_seconds < 20:
                return gr.Warning("Iltimos audio uzunligi 20 sekunddan kam bo'lmasin")

            response = requests.post(API_URL, headers=headers, data=data)
            for i in progress.tqdm(range(100)):
                time.sleep(0.1)
            return response.json()['text']
    except Exception as e:
        return gr.Error("Xatolik sodir bo'ldi: %s" %e)

stt = gr.Interface(
    fn=query,
    description="Ushbu dasturdan foydalanish siz uchun ajoyib taasurotlar keltirib chiqarishi mumkin",
    inputs=gr.Audio(label="Audioning kirish qismi", type='filepath'),
    outputs=gr.Textbox(label="Natija qismi", show_copy_button=True),
    title="Uzbek STT",
    examples=[
        ['https://mohir.ai/sample.mp3'],
        ['https://mohir.ai/audios/give_address.wav'],
        ['https://mohir.ai/audios/give_department.wav'],
        ['https://mohir.ai/audios/give_situation.wav'],
        ['https://mohir.ai/audios/introduction.wav'],
        ['https://mohir.ai/audios/thank_you.wav']
    ],
    examples_per_page=2,
    theme='HaleyCH/HaleyCH_Theme',
    css="""
        body {
            background-image: url('img/pexels.jpg');
            background-size: cover;
            background-position: center;
            animation: bg-animation 20s infinite alternate;
        }

        @keyframes bg-animation {
            0% {
                background-color: rgba(255, 255, 255, 0.5);
            }
            50% {
                background-color: rgba(255, 255, 255, 0.8);
            }
            100% {
                background-color: rgba(255, 255, 255, 0.5);
            }
        }

        button:hover {
            background-color: #4FAF50;
            color: white;
        }
    """,
    additional_inputs_accordion=gr.Accordion(label="Additional Inputs", open=False),
    submit_btn = gr.Button("Tasdiqlash", variant="primary", size='sm', icon='submit.svg'),
    clear_btn = gr.Button("Tozalash", variant="primary", size='sm', icon='clear.svg'),
    delete_cache = (800, 800)
)

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