Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +81 -0
- clear.svg +10 -0
- requirements.txt +2 -0
- submit.svg +66 -0
app.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import time
|
| 4 |
+
from pydub import AudioSegment
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
api_key = os.getenv("TOKEN")
|
| 8 |
+
API_URL = "https://api-inference.huggingface.co/models/oyqiz/uzbek_stt_1_version"
|
| 9 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
| 10 |
+
|
| 11 |
+
def query(filename, progress=gr.Progress()):
|
| 12 |
+
try:
|
| 13 |
+
progress(0, desc="Matnga o'tkazish boshlandi. Iltimos ozgina kuting...")
|
| 14 |
+
if filename is None:
|
| 15 |
+
return gr.Warning("Siz kiritgan fayl turida xatolik bor %s" %filename)
|
| 16 |
+
else:
|
| 17 |
+
with open(filename, "rb") as f:
|
| 18 |
+
data = f.read()
|
| 19 |
+
|
| 20 |
+
# Audio faylning uzunligini tekshirish
|
| 21 |
+
audio = AudioSegment.from_file(filename)
|
| 22 |
+
duration_seconds = audio.duration_seconds
|
| 23 |
+
if duration_seconds < 20:
|
| 24 |
+
return gr.Warning("Iltimos audio uzunligi 20 sekunddan kam bo'lmasin")
|
| 25 |
+
|
| 26 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
| 27 |
+
for i in progress.tqdm(range(100)):
|
| 28 |
+
time.sleep(0.1)
|
| 29 |
+
return response.json()['text']
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return gr.Error("Xatolik sodir bo'ldi: %s" %e)
|
| 32 |
+
|
| 33 |
+
stt = gr.Interface(
|
| 34 |
+
fn=query,
|
| 35 |
+
description="Ushbu dasturdan foydalanish siz uchun ajoyib taasurotlar keltirib chiqarishi mumkin",
|
| 36 |
+
inputs=gr.Audio(label="Audioning kirish qismi", type='filepath'),
|
| 37 |
+
outputs=gr.Textbox(label="Natija qismi", show_copy_button=True),
|
| 38 |
+
title="Uzbek STT",
|
| 39 |
+
examples=[
|
| 40 |
+
['https://mohir.ai/sample.mp3'],
|
| 41 |
+
['https://mohir.ai/audios/give_address.wav'],
|
| 42 |
+
['https://mohir.ai/audios/give_department.wav'],
|
| 43 |
+
['https://mohir.ai/audios/give_situation.wav'],
|
| 44 |
+
['https://mohir.ai/audios/introduction.wav'],
|
| 45 |
+
['https://mohir.ai/audios/thank_you.wav']
|
| 46 |
+
],
|
| 47 |
+
examples_per_page=2,
|
| 48 |
+
theme='HaleyCH/HaleyCH_Theme',
|
| 49 |
+
css="""
|
| 50 |
+
body {
|
| 51 |
+
background-image: url('img/pexels.jpg');
|
| 52 |
+
background-size: cover;
|
| 53 |
+
background-position: center;
|
| 54 |
+
animation: bg-animation 20s infinite alternate;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
@keyframes bg-animation {
|
| 58 |
+
0% {
|
| 59 |
+
background-color: rgba(255, 255, 255, 0.5);
|
| 60 |
+
}
|
| 61 |
+
50% {
|
| 62 |
+
background-color: rgba(255, 255, 255, 0.8);
|
| 63 |
+
}
|
| 64 |
+
100% {
|
| 65 |
+
background-color: rgba(255, 255, 255, 0.5);
|
| 66 |
+
}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
button:hover {
|
| 70 |
+
background-color: #4FAF50;
|
| 71 |
+
color: white;
|
| 72 |
+
}
|
| 73 |
+
""",
|
| 74 |
+
additional_inputs_accordion=gr.Accordion(label="Additional Inputs", open=False),
|
| 75 |
+
submit_btn = gr.Button("Tasdiqlash", variant="primary", size='sm', icon='submit.svg'),
|
| 76 |
+
clear_btn = gr.Button("Tozalash", variant="primary", size='sm', icon='clear.svg'),
|
| 77 |
+
delete_cache = (800, 800)
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
stt.launch()
|
clear.svg
ADDED
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
pydub
|
submit.svg
ADDED
|
|