amirjamali commited on
Commit
b15f0c7
·
unverified ·
1 Parent(s): 9bd3054

Refactor README and implement accent detection functionality in Streamlit app

Browse files
Files changed (3) hide show
  1. README.md +9 -17
  2. requirements.txt +6 -3
  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
- # Welcome to Streamlit!
16
 
17
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
 
 
 
18
 
19
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
20
- forums](https://discuss.streamlit.io).
 
 
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
- altair
2
- pandas
3
- streamlit
 
 
 
 
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
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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)}")