ac / src /streamlit_app.py
slav7's picture
Upload 2 files
b06ca90 verified
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}")