AmirFARES commited on
Commit
5f7fae9
·
1 Parent(s): 0371bb7
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Ignore test notebooks
2
+ *.ipynb
README.md CHANGED
@@ -1,19 +1,17 @@
1
- ---
2
- title: Accentometer
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
- ---
13
 
14
- # Welcome to Streamlit!
15
 
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
 
 
 
 
17
 
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
1
+ # 🎙️ English Accent Detector
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ This project detects the English accent of speakers in video recordings using Whisper ASR and heuristic classification.
4
 
5
+ ## 🔧 Features
6
+ - Accepts MP4 or Loom video links
7
+ - Extracts audio and transcribes with Whisper
8
+ - Classifies accent (British, American, Australian)
9
+ - Returns confidence score and transcript
10
 
11
+ ## 🚀 Hosted on Hugging Face Spaces
12
+ Try it live: [Your HF Space Link](https://huggingface.co/spaces/your-username/accent-detector)
13
+
14
+ ## 🧪 Run Locally
15
+ ```bash
16
+ pip install -r requirements.txt
17
+ streamlit run src/streamlit_app.py
requirements.txt CHANGED
@@ -1,3 +1,6 @@
1
  altair
2
- pandas
3
- streamlit
 
 
 
 
1
  altair
2
+ streamlit
3
+ moviepy
4
+ transformers
5
+ torch
6
+ requests
src/__pycache__/detector.cpython-312.pyc ADDED
Binary file (838 Bytes). View file
 
src/__pycache__/downloader.cpython-312.pyc ADDED
Binary file (902 Bytes). View file
 
src/__pycache__/extractor.cpython-312.pyc ADDED
Binary file (577 Bytes). View file
 
src/detector.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ asr = pipeline("automatic-speech-recognition", model="openai/whisper-base")
4
+
5
+ def detect_accent(audio_path: str):
6
+ result = asr(audio_path)
7
+ text = result["text"].lower()
8
+
9
+ # Heuristic accent classification (mocked rules)
10
+ if "cheers" in text or "mate" in text:
11
+ return "British", 85, text
12
+ elif "gonna" in text or "dude" in text:
13
+ return "American", 90, text
14
+ elif "bro" in text or "yeah nah" in text:
15
+ return "Australian", 80, text
16
+ else:
17
+ return "Uncertain", 50, text
src/downloader.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+
3
+ def download_video(url: str, filename: str = "video.mp4") -> str:
4
+ response = requests.get(url, stream=True)
5
+ if response.status_code == 200:
6
+ with open(filename, "wb") as f:
7
+ for chunk in response.iter_content(chunk_size=8192):
8
+ f.write(chunk)
9
+ else:
10
+ raise Exception("Failed to download video")
11
+ return filename
src/extractor.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from moviepy import VideoFileClip
2
+
3
+ def extract_audio(video_path: str, output_path: str = "audio.wav") -> str:
4
+ video = VideoFileClip(video_path)
5
+ video.audio.write_audiofile(output_path, codec="pcm_s16le")
6
+ return output_path
src/streamlit_app.py CHANGED
@@ -1,40 +1,29 @@
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
+ from downloader import download_video
3
+ from extractor import extract_audio
4
+ from detector import detect_accent
5
 
6
+ st.set_page_config(page_title="Accent Detector", page_icon="🎙️")
7
+
8
+ st.title("🎙️ English Accent Classifier")
9
+ st.write("Paste a public Loom or MP4 link and get an English accent classification.")
10
+
11
+ video_url = st.text_input("Video URL (MP4 or Loom):")
12
+
13
+ if st.button("Analyze") and video_url:
14
+ try:
15
+ with st.spinner("Downloading video..."):
16
+ video_file = download_video(video_url)
17
+
18
+ with st.spinner("Extracting audio..."):
19
+ audio_file = extract_audio(video_file)
20
+
21
+ with st.spinner("Transcribing & detecting accent..."):
22
+ accent, confidence, transcript = detect_accent(audio_file)
23
+
24
+ st.success(f"Accent: **{accent}**")
25
+ st.metric(label="Confidence", value=f"{confidence}%")
26
+ st.text_area("Transcript", transcript, height=150)
27
+
28
+ except Exception as e:
29
+ st.error(f"Error: {str(e)}")