File size: 1,224 Bytes
5186110
790f9dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import whisper
import tempfile
import os

MODEL_OPTIONS = ["tiny", "base", "small", "medium", "large"]
LANGUAGE_OPTIONS = ["en", "ta", "hi", "ml", "te"]

@st.cache_resource
def load_model(model_name):
    return whisper.load_model(model_name)

st.title("🎧 Whisper Audio Transcriber")
st.markdown("Transcribe Tamil, English or other audio using OpenAI's Whisper model.")

language = st.selectbox("πŸ—£οΈ Select Language", LANGUAGE_OPTIONS, index=1)
model_name = st.selectbox("🧠 Select Whisper Model", MODEL_OPTIONS, index=2)
uploaded_file = st.file_uploader("🎡 Upload your audio file", type=["mp3", "wav", "m4a"])

if uploaded_file:
    model = load_model(model_name)

    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
        tmp.write(uploaded_file.read())
        tmp_path = tmp.name

    st.info(f"Transcribing with `{model_name}` model and language `{language}`...")

    try:
        result = model.transcribe(tmp_path, language=language)
        st.success("βœ… Done!")
        st.markdown("#### πŸ“ Transcription Output:")
        st.write(result["text"])
    except Exception as e:
        st.error(f"❌ Error: {e}")
    finally:
        os.remove(tmp_path)