add examples and update requirements.txt
Browse files- app.py +59 -30
- examples/07sQYGJjXp.mp3 +0 -0
- examples/0Dx4G69NT1.mp3 +0 -0
- examples/0EklRxI2r7.mp3 +0 -0
- examples/0lhKyMVanh.mp3 +0 -0
- examples/3EeaoDRPEd.mp3 +0 -0
- examples/3Fi3cisTLe.mp3 +0 -0
- examples/3bEPdiqxC7.mp3 +0 -0
- examples/3zRKfpKl0Y.mp3 +0 -0
- examples/56S1DlxtmW.mp3 +0 -0
- examples/5jehSBK6Pg.mp3 +0 -0
- examples/5q7nveNeiy.mp3 +0 -0
- examples/67ub2dQVtY.mp3 +0 -0
- examples/68jlcwwZNQ.mp3 +0 -0
- examples/6D3IzKfPsg.mp3 +0 -0
- examples/6fDC05Y789.mp3 +0 -0
- examples/6tClWfytMf.mp3 +0 -0
- examples/7hJUpVTD91.mp3 +0 -0
- examples/9XiCrJdINc.mp3 +0 -0
- examples/AICriJDIrA.mp3 +0 -0
- examples/AT2Oo9AjZw.mp3 +0 -0
- examples/BPyRgUKYav.mp3 +0 -0
- examples/CbrP4lagnL.mp3 +0 -0
- examples/CmBBDRsOVU.mp3 +0 -0
- examples/FFAKzxhVgC.mp3 +0 -0
- examples/Lionel-Messi_(arywiki)-2.mp3 +0 -0
- examples/PDJbpexQFE.mp3 +0 -0
- examples/bsBqTDHUgx.mp3 +0 -0
- examples/bywrMXKv1a.mp3 +0 -0
- examples/cLOEsibJJW.mp3 +0 -0
- examples/fDyks4ZZsU.mp3 +0 -0
- examples/gksGGsLoAq.mp3 +0 -0
- examples/obud3p5tvb.mp3 +0 -0
- requirements.txt +3 -2
app.py
CHANGED
@@ -1,12 +1,18 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
# Load the model
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
dialect_mapping = {
|
11 |
"MSA": "Modern Standard Arabic",
|
12 |
"Egyptian": "Egyptian Arabic",
|
@@ -16,43 +22,66 @@ dialect_mapping = {
|
|
16 |
}
|
17 |
|
18 |
def predict_dialect(audio):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
21 |
sr, audio_array = audio
|
22 |
-
|
23 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
return {"Error": 1.0}
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Create the Gradio interface
|
42 |
demo = gr.Interface(
|
43 |
fn=predict_dialect,
|
44 |
-
inputs=gr.Audio(),
|
45 |
outputs=gr.Label(num_top_classes=5, label="Predicted Dialect"),
|
46 |
title="Arabic Dialect Identifier",
|
47 |
description="""This demo identifies Arabic dialects from speech audio.
|
48 |
Upload an audio file or record your voice speaking Arabic to see which dialect it matches.
|
49 |
The model identifies: Modern Standard Arabic (MSA), Egyptian, Gulf, Levantine, and Maghrebi dialects.""",
|
50 |
-
examples=
|
51 |
-
|
52 |
-
|
53 |
-
# ["examples/egyptian_example.wav"],
|
54 |
-
],
|
55 |
-
allow_flagging="never"
|
56 |
)
|
57 |
|
58 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
4 |
+
import os
|
5 |
|
6 |
# Load the model
|
7 |
+
print("Loading model...")
|
8 |
+
model_id = "badrex/mms-300m-arabic-dialect-identifier"
|
9 |
+
try:
|
10 |
+
classifier = pipeline("audio-classification", model=model_id)
|
11 |
+
print("Model loaded successfully")
|
12 |
+
except Exception as e:
|
13 |
+
print(f"Error loading model: {e}")
|
14 |
+
|
15 |
+
# Define dialect mapping
|
16 |
dialect_mapping = {
|
17 |
"MSA": "Modern Standard Arabic",
|
18 |
"Egyptian": "Egyptian Arabic",
|
|
|
22 |
}
|
23 |
|
24 |
def predict_dialect(audio):
|
25 |
+
try:
|
26 |
+
# The audio input from Gradio is a tuple of (sample_rate, audio_array)
|
27 |
+
if audio is None:
|
28 |
+
return {"Error": 1.0}
|
29 |
+
|
30 |
sr, audio_array = audio
|
31 |
+
|
32 |
+
# Process the audio input
|
33 |
+
if len(audio_array.shape) > 1:
|
34 |
+
audio_array = audio_array.mean(axis=1) # Convert stereo to mono
|
35 |
+
|
36 |
+
print(f"Processing audio: sample rate={sr}, shape={audio_array.shape}")
|
37 |
+
|
38 |
+
# Classify the dialect
|
39 |
+
predictions = classifier({"sampling_rate": sr, "raw": audio_array})
|
40 |
+
|
41 |
+
# Format results for display
|
42 |
+
results = {}
|
43 |
+
for pred in predictions:
|
44 |
+
dialect_name = dialect_mapping.get(pred['label'], pred['label'])
|
45 |
+
results[dialect_name] = float(pred['score'])
|
46 |
+
|
47 |
+
return results
|
48 |
+
except Exception as e:
|
49 |
+
print(f"Error in prediction: {e}")
|
50 |
return {"Error": 1.0}
|
51 |
+
|
52 |
+
# Find example files
|
53 |
+
example_files = []
|
54 |
+
examples_dir = "examples"
|
55 |
+
if os.path.exists(examples_dir):
|
56 |
+
for filename in os.listdir(examples_dir):
|
57 |
+
if filename.endswith((".wav", ".mp3", ".ogg")):
|
58 |
+
example_files.append(os.path.join(examples_dir, filename))
|
59 |
+
|
60 |
+
print(f"Found {len(example_files)} example files")
|
61 |
+
else:
|
62 |
+
print("Examples directory not found")
|
63 |
+
|
64 |
+
# Examples with labels
|
65 |
+
examples = []
|
66 |
+
if example_files:
|
67 |
+
for file in example_files:
|
68 |
+
basename = os.path.basename(file)
|
69 |
+
dialect = basename.split("_")[0] if "_" in basename else basename.split(".")[0]
|
70 |
+
label = dialect_mapping.get(dialect, dialect.capitalize())
|
71 |
+
examples.append([file, f"{label} Sample"])
|
72 |
|
73 |
# Create the Gradio interface
|
74 |
demo = gr.Interface(
|
75 |
fn=predict_dialect,
|
76 |
+
inputs=gr.Audio(),
|
77 |
outputs=gr.Label(num_top_classes=5, label="Predicted Dialect"),
|
78 |
title="Arabic Dialect Identifier",
|
79 |
description="""This demo identifies Arabic dialects from speech audio.
|
80 |
Upload an audio file or record your voice speaking Arabic to see which dialect it matches.
|
81 |
The model identifies: Modern Standard Arabic (MSA), Egyptian, Gulf, Levantine, and Maghrebi dialects.""",
|
82 |
+
examples=examples if examples else None,
|
83 |
+
examples_per_page=5,
|
84 |
+
flagging_mode=None # Updated from allow_flagging
|
|
|
|
|
|
|
85 |
)
|
86 |
|
87 |
# Launch the app
|
examples/07sQYGJjXp.mp3
ADDED
Binary file (19.7 kB). View file
|
|
examples/0Dx4G69NT1.mp3
ADDED
Binary file (56.1 kB). View file
|
|
examples/0EklRxI2r7.mp3
ADDED
Binary file (25.1 kB). View file
|
|
examples/0lhKyMVanh.mp3
ADDED
Binary file (27.7 kB). View file
|
|
examples/3EeaoDRPEd.mp3
ADDED
Binary file (36.9 kB). View file
|
|
examples/3Fi3cisTLe.mp3
ADDED
Binary file (45.2 kB). View file
|
|
examples/3bEPdiqxC7.mp3
ADDED
Binary file (39.7 kB). View file
|
|
examples/3zRKfpKl0Y.mp3
ADDED
Binary file (43.5 kB). View file
|
|
examples/56S1DlxtmW.mp3
ADDED
Binary file (48.3 kB). View file
|
|
examples/5jehSBK6Pg.mp3
ADDED
Binary file (26.5 kB). View file
|
|
examples/5q7nveNeiy.mp3
ADDED
Binary file (69.6 kB). View file
|
|
examples/67ub2dQVtY.mp3
ADDED
Binary file (27.2 kB). View file
|
|
examples/68jlcwwZNQ.mp3
ADDED
Binary file (92.8 kB). View file
|
|
examples/6D3IzKfPsg.mp3
ADDED
Binary file (33.4 kB). View file
|
|
examples/6fDC05Y789.mp3
ADDED
Binary file (35.2 kB). View file
|
|
examples/6tClWfytMf.mp3
ADDED
Binary file (54.5 kB). View file
|
|
examples/7hJUpVTD91.mp3
ADDED
Binary file (25 kB). View file
|
|
examples/9XiCrJdINc.mp3
ADDED
Binary file (53.3 kB). View file
|
|
examples/AICriJDIrA.mp3
ADDED
Binary file (59.2 kB). View file
|
|
examples/AT2Oo9AjZw.mp3
ADDED
Binary file (42.6 kB). View file
|
|
examples/BPyRgUKYav.mp3
ADDED
Binary file (38.5 kB). View file
|
|
examples/CbrP4lagnL.mp3
ADDED
Binary file (51.2 kB). View file
|
|
examples/CmBBDRsOVU.mp3
ADDED
Binary file (59.9 kB). View file
|
|
examples/FFAKzxhVgC.mp3
ADDED
Binary file (40.6 kB). View file
|
|
examples/Lionel-Messi_(arywiki)-2.mp3
ADDED
Binary file (94.5 kB). View file
|
|
examples/PDJbpexQFE.mp3
ADDED
Binary file (44.3 kB). View file
|
|
examples/bsBqTDHUgx.mp3
ADDED
Binary file (50 kB). View file
|
|
examples/bywrMXKv1a.mp3
ADDED
Binary file (94.4 kB). View file
|
|
examples/cLOEsibJJW.mp3
ADDED
Binary file (99.1 kB). View file
|
|
examples/fDyks4ZZsU.mp3
ADDED
Binary file (19.5 kB). View file
|
|
examples/gksGGsLoAq.mp3
ADDED
Binary file (290 kB). View file
|
|
examples/obud3p5tvb.mp3
ADDED
Binary file (31.6 kB). View file
|
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
gradio>=
|
2 |
transformers>=4.36.0
|
3 |
torch>=2.0.0
|
4 |
-
|
|
|
|
1 |
+
gradio>=5.20.0
|
2 |
transformers>=4.36.0
|
3 |
torch>=2.0.0
|
4 |
+
torchaudio>=2.0.0
|
5 |
+
librosa>=0.10.1
|