Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,49 +1,59 @@
|
|
| 1 |
-
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
'
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from detect import SimpleOfflineAccentClassifier
|
| 3 |
+
|
| 4 |
+
def analyze_audio(audio_file):
|
| 5 |
+
if audio_file is None:
|
| 6 |
+
return "Please upload an audio file."
|
| 7 |
+
|
| 8 |
+
try:
|
| 9 |
+
classifier = SimpleOfflineAccentClassifier()
|
| 10 |
+
result = classifier.predict_accent(audio_file)
|
| 11 |
+
|
| 12 |
+
if result is None:
|
| 13 |
+
return "Audio file processing failed."
|
| 14 |
+
|
| 15 |
+
output = f"Predicted Accent: {result['accent']}\n"
|
| 16 |
+
output += f"Confidence Score: {result['confidence']:.2%}\n\n"
|
| 17 |
+
output += "All Probabilities:\n"
|
| 18 |
+
|
| 19 |
+
sorted_probs = sorted(
|
| 20 |
+
result['all_probabilities'].items(),
|
| 21 |
+
key=lambda x: x[1],
|
| 22 |
+
reverse=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
for accent, prob in sorted_probs:
|
| 26 |
+
bar = "█" * int(prob * 20)
|
| 27 |
+
output += f"- {accent}: {prob:.2%} {bar}\n"
|
| 28 |
+
|
| 29 |
+
return output
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error occurred: {str(e)}"
|
| 33 |
+
|
| 34 |
+
# Create Gradio interface
|
| 35 |
+
with gr.Blocks() as interface:
|
| 36 |
+
gr.Markdown("# AI Accent Classifier")
|
| 37 |
+
|
| 38 |
+
with gr.Row():
|
| 39 |
+
with gr.Column():
|
| 40 |
+
audio_input = gr.Audio(
|
| 41 |
+
label="Upload Audio File",
|
| 42 |
+
type="filepath"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
classify_btn = gr.Button("Analyze Accent")
|
| 46 |
+
|
| 47 |
+
with gr.Column():
|
| 48 |
+
output_text = gr.Markdown(
|
| 49 |
+
label="Analysis Results",
|
| 50 |
+
value="Analysis results will appear here..."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
classify_btn.click(
|
| 54 |
+
fn=analyze_audio,
|
| 55 |
+
inputs=audio_input,
|
| 56 |
+
outputs=output_text
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
interface.launch()
|