Spaces:
Sleeping
Sleeping
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() |