File size: 1,693 Bytes
ad2cddc
b06ca90
 
 
 
 
 
 
ad2cddc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
import os
os.environ["HF_HOME"] = "/tmp/huggingface"
os.environ["HF_HUB_CACHE"] = "/tmp/huggingface/hub"
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface/transformers"
os.environ["TORCH_HOME"] = "/tmp/torch"
os.environ["XDG_CACHE_HOME"] = "/tmp/xdg_cache"

import streamlit as st
from d import download_and_extract_audio, analyze_accent, get_accent_classifier

st.title("English Accent Classifier")
st.write("""
Upload a public video URL (e.g., YouTube, Loom, or direct MP4 link). The tool will extract the audio, analyze the speaker’s accent, and provide a confidence score.
""")

# Show spinner and load model at startup
if "model_loaded" not in st.session_state:
    with st.spinner("Loading models (this may take a while the first time)..."):
        get_accent_classifier()
    st.session_state["model_loaded"] = True
    st.success("Model loaded!")

video_url = st.text_input("Enter public video URL:")

if st.button("Analyze Accent") and video_url:
    with st.spinner("Downloading and extracting audio..."):
        try:
            audio_path = download_and_extract_audio(video_url)
        except Exception as e:
            st.error(f"Audio extraction failed: {e}")
            st.stop()
    st.success("Audio extracted successfully!")
    st.audio(audio_path)
    with st.spinner("Analyzing accent (downloading model if needed)..."):
        try:
            accent, confidence, summary = analyze_accent(audio_path)
        except Exception as e:
            st.error(f"Accent analysis failed: {e}")
            st.stop()
    st.markdown(f"**Accent:** {accent}")
    st.markdown(f"**English Accent Confidence:** {confidence:.2f}%")
    st.markdown(f"**Summary:** {summary}")