import streamlit as st import torch import torchaudio from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor import tempfile model_name = "oyqiz/uzbek_stt" processor = Wav2Vec2Processor.from_pretrained(model_name) model = Wav2Vec2ForCTC.from_pretrained(model_name) st.title("Ovozni matnga o'girish") st.write("Audio faylingizni yuklang:") # File uploader uploaded_file = st.file_uploader("Audio faylingizni tanlang...", type=["wav", "mp3", "ogg"]) def transcribe_audio(audio_file): waveform, sample_rate = torchaudio.load(audio_file) if sample_rate != 16000: waveform = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)(waveform) sample_rate = 16000 input_values = processor(waveform, sampling_rate=sample_rate, return_tensors="pt").input_values with torch.no_grad(): input_values = input_values.squeeze(1) logits = model(input_values).logits predicted_ids = torch.argmax(logits, dim=-1) transcription = processor.batch_decode(predicted_ids)[0] return transcription if uploaded_file is not None: with tempfile.NamedTemporaryFile(delete=False) as tmp_file: tmp_file.write(uploaded_file.read()) tmp_file_path = tmp_file.name transcription = transcribe_audio(tmp_file_path) st.write("Natija:") st.write(transcription)