Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +43 -0
- requirements.txt +12 -0
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
4 |
+
from peft import PeftModel, PeftConfig
|
5 |
+
import librosa
|
6 |
+
|
7 |
+
# Model sozlamalari
|
8 |
+
peft_model_id = "Elyordev/fine_tune_whisper_uzbek"
|
9 |
+
language = "Uzbek"
|
10 |
+
task = "transcribe"
|
11 |
+
|
12 |
+
# PEFT konfiguratsiyasini yuklash
|
13 |
+
peft_config = PeftConfig.from_pretrained(peft_model_id)
|
14 |
+
|
15 |
+
# CPU uchun model yuklash
|
16 |
+
model = WhisperForConditionalGeneration.from_pretrained(
|
17 |
+
peft_config.base_model_name_or_path,
|
18 |
+
device_map="cpu"
|
19 |
+
)
|
20 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
21 |
+
|
22 |
+
# Tokenizer va Processor sozlash
|
23 |
+
processor = WhisperProcessor.from_pretrained(peft_config.base_model_name_or_path, language=language, task=task)
|
24 |
+
|
25 |
+
# Streamlit interfeysi
|
26 |
+
st.title("Uzbek Whisper STT Hugging Face Spaces App")
|
27 |
+
st.write("Fine-tuned Whisper model for Uzbek speech recognition. Upload your audio to get the transcription.")
|
28 |
+
|
29 |
+
# Audio yuklash
|
30 |
+
uploaded_file = st.file_uploader("Ovozli fayl yuklang", type=["wav", "mp3", "m4a"])
|
31 |
+
|
32 |
+
def transcribe(audio_file):
|
33 |
+
audio, sr = librosa.load(audio_file, sr=16000)
|
34 |
+
inputs = processor(audio, sampling_rate=16000, return_tensors="pt").input_features
|
35 |
+
predicted_ids = model.generate(inputs, forced_decoder_ids=processor.get_decoder_prompt_ids(language="uz", task="transcribe"))
|
36 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
|
37 |
+
return transcription
|
38 |
+
|
39 |
+
if uploaded_file:
|
40 |
+
st.audio(uploaded_file, format="audio/wav")
|
41 |
+
st.write("**Transkripsiya natijasi:**")
|
42 |
+
transcription = transcribe(uploaded_file)
|
43 |
+
st.success(transcription)
|
requirements.txt
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
git+https://github.com/huggingface/transformers.git@main
|
2 |
+
git+https://github.com/huggingface/peft.git@main
|
3 |
+
torch
|
4 |
+
gradio
|
5 |
+
huggingface_hub
|
6 |
+
librosa
|
7 |
+
evaluate>=0.4.3
|
8 |
+
jiwer
|
9 |
+
bitsandbytes
|
10 |
+
datasets
|
11 |
+
accelerate
|
12 |
+
loralib
|