Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- Model Used.txt +1 -0
- app.py +75 -0
- author.txt +15 -0
- packages.txt +1 -0
- readme.md.txt +22 -0
- requirements.txt +6 -0
Model Used.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
superb/wav2vec2-base-superb-sid
|
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Ensure yt_dlp is available
|
| 6 |
+
try:
|
| 7 |
+
import yt_dlp as youtube_dl
|
| 8 |
+
except ImportError:
|
| 9 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "yt-dlp"])
|
| 10 |
+
import yt_dlp as youtube_dl
|
| 11 |
+
|
| 12 |
+
import gradio as gr
|
| 13 |
+
from transformers import pipeline
|
| 14 |
+
|
| 15 |
+
def download_video(video_url, filename="downloaded_video.mp4"):
|
| 16 |
+
ydl_opts = {
|
| 17 |
+
'format': 'bestaudio/best',
|
| 18 |
+
'outtmpl': filename,
|
| 19 |
+
'noplaylist': True,
|
| 20 |
+
'quiet': True,
|
| 21 |
+
'user_agent': (
|
| 22 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
|
| 23 |
+
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
| 24 |
+
'Chrome/115.0.0.0 Safari/537.36'
|
| 25 |
+
)
|
| 26 |
+
}
|
| 27 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
| 28 |
+
ydl.download([video_url])
|
| 29 |
+
return filename
|
| 30 |
+
|
| 31 |
+
def extract_audio(video_filename, audio_filename="extracted_audio.wav"):
|
| 32 |
+
command = [
|
| 33 |
+
"ffmpeg",
|
| 34 |
+
"-y",
|
| 35 |
+
"-i", video_filename,
|
| 36 |
+
"-vn",
|
| 37 |
+
"-acodec", "pcm_s16le",
|
| 38 |
+
"-ar", "16000",
|
| 39 |
+
"-ac", "1",
|
| 40 |
+
audio_filename
|
| 41 |
+
]
|
| 42 |
+
subprocess.run(command, check=True)
|
| 43 |
+
return audio_filename
|
| 44 |
+
|
| 45 |
+
def classify_accent(audio_file, model_name="superb/wav2vec2-base-superb-sid"):
|
| 46 |
+
classifier = pipeline("audio-classification", model=model_name)
|
| 47 |
+
results = classifier(audio_file)
|
| 48 |
+
if results:
|
| 49 |
+
top = results[0]
|
| 50 |
+
return f"Speaker ID (as accent proxy): {top['label']}\nConfidence: {top['score'] * 100:.2f}%"
|
| 51 |
+
return "No result."
|
| 52 |
+
|
| 53 |
+
def accent_classifier(video_url):
|
| 54 |
+
try:
|
| 55 |
+
video_file = download_video(video_url)
|
| 56 |
+
audio_file = extract_audio(video_file)
|
| 57 |
+
result = classify_accent(audio_file)
|
| 58 |
+
except Exception as e:
|
| 59 |
+
result = f"Error occurred: {e}"
|
| 60 |
+
finally:
|
| 61 |
+
for f in ["downloaded_video.mp4", "extracted_audio.wav"]:
|
| 62 |
+
if os.path.exists(f):
|
| 63 |
+
os.remove(f)
|
| 64 |
+
return result
|
| 65 |
+
|
| 66 |
+
iface = gr.Interface(
|
| 67 |
+
fn=accent_classifier,
|
| 68 |
+
inputs=gr.Textbox(label="Video URL", placeholder="Paste a public YouTube or Vimeo video link here"),
|
| 69 |
+
outputs="text",
|
| 70 |
+
title="Accent Classifier",
|
| 71 |
+
description="Download a video, extract the audio, and classify the speaker (as an accent proxy) using a Hugging Face model."
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
iface.launch()
|
author.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
---
|
| 3 |
+
|
| 4 |
+
## 🧳 To package it all:
|
| 5 |
+
|
| 6 |
+
If you’re on your machine:
|
| 7 |
+
|
| 8 |
+
1. Create a folder (e.g. `accent_classifier`)
|
| 9 |
+
2. Save all 4 files (`app.py`, `README.md`, `requirements.txt`, `packages.txt`) into it
|
| 10 |
+
3. Right-click → **Send to → Compressed (zipped) folder**
|
| 11 |
+
4. Upload the `.zip` to Hugging Face or unzip it into your local project
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ffmpeg
|
readme.md.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Accent Classifier
|
| 3 |
+
emoji: "🎙️"
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.32.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# 🎙️ Accent Classifier App
|
| 13 |
+
|
| 14 |
+
This Gradio-powered app allows you to paste a public video URL (YouTube, Vimeo, Dailymotion), download it with `yt-dlp`, extract the audio using `ffmpeg`, and classify the speaker identity (as a proxy for accent) using the `superb/wav2vec2-base-superb-sid` model from Hugging Face.
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## 🔧 Setup
|
| 19 |
+
|
| 20 |
+
```bash
|
| 21 |
+
pip install -r requirements.txt
|
| 22 |
+
sudo apt install ffmpeg
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
torchaudio
|
| 5 |
+
yt-dlp
|
| 6 |
+
tensorflow
|