Spaces:
Running
Running
Refactor README and implement accent detection functionality in Streamlit app
Browse files- README.md +9 -17
- requirements.txt +6 -3
- src/streamlit_app.py +43 -39
README.md
CHANGED
@@ -1,20 +1,12 @@
|
|
1 |
-
|
2 |
-
title: Accent Detector
|
3 |
-
emoji: 🚀
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: red
|
6 |
-
sdk: docker
|
7 |
-
app_port: 8501
|
8 |
-
tags:
|
9 |
-
- streamlit
|
10 |
-
pinned: false
|
11 |
-
short_description: Streamlit template space
|
12 |
-
license: mit
|
13 |
-
---
|
14 |
|
15 |
-
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
|
|
|
1 |
+
# 🎤 Accent Detection Tool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
This app accepts a public video URL, extracts the audio, detects the English-speaking accent or language, and provides a confidence score.
|
4 |
|
5 |
+
## Usage
|
6 |
+
- Enter a Loom or MP4 link.
|
7 |
+
- Click "Analyze"
|
8 |
+
- Get accent classification and score.
|
9 |
|
10 |
+
## Powered By
|
11 |
+
- [SpeechBrain](https://huggingface.co/speechbrain/lang-id-commonlanguage_ecapa)
|
12 |
+
- [Streamlit](https://streamlit.io)
|
requirements.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
yt_dlp
|
3 |
+
moviepy
|
4 |
+
speechbrain
|
5 |
+
torch
|
6 |
+
torchaudio
|
src/streamlit_app.py
CHANGED
@@ -1,40 +1,44 @@
|
|
1 |
-
import altair as alt
|
2 |
-
import numpy as np
|
3 |
-
import pandas as pd
|
4 |
import streamlit as st
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import os
|
3 |
+
import yt_dlp
|
4 |
+
from moviepy.editor import VideoFileClip
|
5 |
+
from speechbrain.pretrained import LanguageIdentification
|
6 |
+
|
7 |
+
def download_video(url, video_path="video.mp4"):
|
8 |
+
ydl_opts = {"outtmpl": video_path}
|
9 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
10 |
+
ydl.download([url])
|
11 |
+
|
12 |
+
def extract_audio(video_path="video.mp4", audio_path="audio.wav"):
|
13 |
+
video = VideoFileClip(video_path)
|
14 |
+
video.audio.write_audiofile(audio_path)
|
15 |
+
|
16 |
+
def detect_accent(audio_path="audio.wav"):
|
17 |
+
classifier = LanguageIdentification.from_hparams(source="speechbrain/lang-id-commonlanguage_ecapa", savedir="tmp_model")
|
18 |
+
prediction = classifier.classify_file(audio_path)
|
19 |
+
lang = prediction[1]
|
20 |
+
score = float(prediction[0][0])
|
21 |
+
return lang, score
|
22 |
+
|
23 |
+
# --- Streamlit App ---
|
24 |
+
st.title("🎤 Accent Detection Tool")
|
25 |
+
url = st.text_input("Enter a public video URL (e.g. Loom or direct MP4)")
|
26 |
+
|
27 |
+
if st.button("Analyze"):
|
28 |
+
try:
|
29 |
+
with st.spinner("Downloading video..."):
|
30 |
+
download_video(url)
|
31 |
+
|
32 |
+
with st.spinner("Extracting audio..."):
|
33 |
+
extract_audio()
|
34 |
+
|
35 |
+
with st.spinner("Detecting accent..."):
|
36 |
+
lang, confidence = detect_accent()
|
37 |
+
|
38 |
+
st.success("Analysis Complete!")
|
39 |
+
st.markdown(f"**Predicted Accent/Language:** `{lang}`")
|
40 |
+
st.markdown(f"**Confidence Score:** `{round(confidence * 100, 2)}%`")
|
41 |
+
st.caption("Note: This is based on SpeechBrain's language model and may group accents by broader language class.")
|
42 |
+
|
43 |
+
except Exception as e:
|
44 |
+
st.error(f"Error: {str(e)}")
|