Spaces:
Running
Running
added examples
Browse files- .gitattributes +1 -0
- app.py +57 -12
- examples/{cleo-abram.mp4 → american.mp4} +0 -0
- examples/british.mp4 +3 -0
- examples/irish.mp4 +3 -0
.gitattributes
CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
cleo-abram.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
cleo-abram.mp4 filter=lfs diff=lfs merge=lfs -text
|
37 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
@@ -13,6 +13,27 @@ whisper_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-ti
|
|
13 |
|
14 |
classifier = foreign_class(source="Jzuluaga/accent-id-commonaccent_xlsr-en-english", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Placeholder accent classifier (replace with real one or your own logic)
|
17 |
def classify_accent(audio_tensor, sample_rate):
|
18 |
if sample_rate != 16000:
|
@@ -21,10 +42,16 @@ def classify_accent(audio_tensor, sample_rate):
|
|
21 |
|
22 |
out_prob, score, index, text_lab = classifier.classify_batch(audio_tensor)
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return {
|
25 |
-
"accent":
|
26 |
-
"confidence":
|
27 |
-
"summary": "The speaker
|
28 |
}
|
29 |
|
30 |
def download_video(url):
|
@@ -119,23 +146,41 @@ with gr.Blocks() as demo:
|
|
119 |
|
120 |
with gr.Tab("From URL"):
|
121 |
url_input = gr.Textbox(label="Video URL (MP4)")
|
122 |
-
url_output = gr.Markdown()
|
123 |
gr.Button("Analyze").click(fn=analyze_accent, inputs=url_input, outputs=url_output)
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
with gr.Tab("From File"):
|
126 |
file_input = gr.File(label="Upload MP4 Video", file_types=[".mp4"])
|
127 |
-
file_output = gr.Markdown()
|
128 |
gr.Button("Analyze").click(fn=analyze_accent, inputs=file_input, outputs=file_output)
|
129 |
|
130 |
|
131 |
gr.Examples(
|
132 |
-
examples=[
|
133 |
-
|
134 |
-
],
|
135 |
-
|
136 |
-
|
137 |
-
fn=analyze_accent,
|
138 |
-
label="Example MP4 Videos"
|
139 |
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
demo.launch()
|
|
|
13 |
|
14 |
classifier = foreign_class(source="Jzuluaga/accent-id-commonaccent_xlsr-en-english", pymodule_file="custom_interface.py", classname="CustomEncoderWav2vec2Classifier")
|
15 |
|
16 |
+
|
17 |
+
ACCENT_LABELS = {
|
18 |
+
"us": "American Accent",
|
19 |
+
"england": "British Accent",
|
20 |
+
"australia": "Australian Accent",
|
21 |
+
"indian": "Indian Accent",
|
22 |
+
"canada": "Canadian Accent",
|
23 |
+
"bermuda": "Bermudian Accent",
|
24 |
+
"scotland": "Scottish Accent",
|
25 |
+
"african": "African Accent",
|
26 |
+
"ireland": "Irish Accent",
|
27 |
+
"newzealand": "New Zealand Accent",
|
28 |
+
"wales": "Welsh Accent",
|
29 |
+
"malaysia": "Malaysian Accent",
|
30 |
+
"philippines": "Philippine Accent",
|
31 |
+
"singapore": "Singaporean Accent",
|
32 |
+
"hongkong": "Hong Kong Accent",
|
33 |
+
"southatlandtic": "South Atlantic Accent"
|
34 |
+
}
|
35 |
+
|
36 |
+
|
37 |
# Placeholder accent classifier (replace with real one or your own logic)
|
38 |
def classify_accent(audio_tensor, sample_rate):
|
39 |
if sample_rate != 16000:
|
|
|
42 |
|
43 |
out_prob, score, index, text_lab = classifier.classify_batch(audio_tensor)
|
44 |
|
45 |
+
print(out_prob, score, index, text_lab)
|
46 |
+
|
47 |
+
accent_label = text_lab[0]
|
48 |
+
readable_accent = ACCENT_LABELS.get(accent_label, accent_label.title() + " Accent")
|
49 |
+
|
50 |
+
|
51 |
return {
|
52 |
+
"accent": readable_accent,
|
53 |
+
"confidence": round(score[0].item() * 100, 2),
|
54 |
+
"summary": f"The speaker is predicted to have a {readable_accent} with {round(score[0].item() * 100, 2)}% confidence."
|
55 |
}
|
56 |
|
57 |
def download_video(url):
|
|
|
146 |
|
147 |
with gr.Tab("From URL"):
|
148 |
url_input = gr.Textbox(label="Video URL (MP4)")
|
149 |
+
url_output = gr.Markdown("""### Output will be shown here!""", elem_classes="output-box")
|
150 |
gr.Button("Analyze").click(fn=analyze_accent, inputs=url_input, outputs=url_output)
|
151 |
|
152 |
+
|
153 |
+
gr.Examples(
|
154 |
+
examples=[["https://huggingface.co/spaces/fahadqazi/accent-classifier/raw/main/examples/american.mp4"], ["https://huggingface.co/spaces/fahadqazi/accent-classifier/raw/main/examples/british.mp4"]],
|
155 |
+
inputs=[url_input],
|
156 |
+
outputs=[url_output],
|
157 |
+
label="Example MP4 Video URLs",
|
158 |
+
examples_per_page=5
|
159 |
+
)
|
160 |
+
|
161 |
+
|
162 |
with gr.Tab("From File"):
|
163 |
file_input = gr.File(label="Upload MP4 Video", file_types=[".mp4"])
|
164 |
+
file_output = gr.Markdown("""### Output will be shown here!""", elem_classes="output-box")
|
165 |
gr.Button("Analyze").click(fn=analyze_accent, inputs=file_input, outputs=file_output)
|
166 |
|
167 |
|
168 |
gr.Examples(
|
169 |
+
examples=[[os.getcwd() + "/examples/american.mp4"], [os.getcwd() + "/examples/british.mp4"]],
|
170 |
+
inputs=[file_input],
|
171 |
+
outputs=[file_output],
|
172 |
+
label="Example MP4 Videos",
|
173 |
+
examples_per_page=5
|
|
|
|
|
174 |
)
|
175 |
|
176 |
+
|
177 |
+
demo.css = """
|
178 |
+
.output-box {
|
179 |
+
min-height: 100px;
|
180 |
+
overflow-y: auto;
|
181 |
+
padding: 10px;
|
182 |
+
}
|
183 |
+
"""
|
184 |
+
|
185 |
+
|
186 |
demo.launch()
|
examples/{cleo-abram.mp4 → american.mp4}
RENAMED
File without changes
|
examples/british.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:10d349270f5dd2f8f155dab6c61907778966ed1b4f496c851622658cc3332eb5
|
3 |
+
size 1019730
|
examples/irish.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8a43872434c23a80ae3d22c08bc9c5d51cfbd83168301f0e88dcfd65f4925140
|
3 |
+
size 352320
|