Spaces:
Sleeping
Sleeping
import gradio as gr | |
from detect import SimpleOfflineAccentClassifier | |
def analyze_audio(audio_file): | |
if audio_file is None: | |
return "Please upload an audio file." | |
try: | |
classifier = SimpleOfflineAccentClassifier() | |
result = classifier.predict_accent(audio_file) | |
if result is None: | |
return "Audio file processing failed." | |
output = f"Predicted Accent: {result['accent']}\n" | |
output += f"Confidence Score: {result['confidence']:.2%}\n\n" | |
output += "All Probabilities:\n" | |
sorted_probs = sorted( | |
result['all_probabilities'].items(), | |
key=lambda x: x[1], | |
reverse=True | |
) | |
for accent, prob in sorted_probs: | |
bar = "█" * int(prob * 20) | |
output += f"- {accent}: {prob:.2%} {bar}\n" | |
return output | |
except Exception as e: | |
return f"Error occurred: {str(e)}" | |
# Create Gradio interface | |
with gr.Blocks() as interface: | |
gr.Markdown("# AI Accent Classifier") | |
with gr.Row(): | |
with gr.Column(): | |
audio_input = gr.Audio( | |
label="Upload Audio File", | |
type="filepath" | |
) | |
classify_btn = gr.Button("Analyze Accent") | |
with gr.Column(): | |
output_text = gr.Markdown( | |
label="Analysis Results", | |
value="Analysis results will appear here..." | |
) | |
classify_btn.click( | |
fn=analyze_audio, | |
inputs=audio_input, | |
outputs=output_text | |
) | |
# Launch the interface | |
interface.launch(server_name="0.0.0.0", server_port=7860) |