import gradio as gr from scipy.io import wavfile from wav2vec_aligen import speaker_pronunciation_assesment def analyze_audio(audio): # Write the processed audio to a temporary WAV file if audio is None: return 'the audio is missing' temp_filename = 'temp_audio.wav' wavfile.write(temp_filename, audio[0], audio[1]) result = speaker_pronunciation_assesment(temp_filename) accuracy_score = result['pronunciation_accuracy'] fluency_score = result['fluency_score'] total_score = result['total_score'] content_scores = result['content_scores'] result_markdown = f"""|Language Aspect| Score| |---|---| |Pronunciation Accuracy| {accuracy_score}| |Fluency| {fluency_score}| |Total Score| {total_score}| |Content Score| {content_scores}| """ return result_markdown import gradio as gr CHOICES = ['Daibers', 'Carbon', 'Reptiles'] SENTENCES = [ """In Germany, over 100,000 tons of diapers are discarded each year, resulting in the wastage of valuable resources. Diaper liners, which contain special polymers known as superabsorbers, are among the materials that end up in landfills. However, researchers have made significant progress in enhancing the recycling process for these liners, leading to substantial improvements.""", """Across the globe, there is a wide spread effort to explore methods for extracting carbon dioxide from the atmosphere or power plant emissions and transforming it into a valuable resource. Among the various ideas being explored, the concept of converting car bondioxide into a stable fuel shows significant promise.""", """Around 250 million years ago,700 species of reptiles closely related to the modern-day crocodile roamed the earth, now new research reveals how a complex interplay between climate change, species competition and habitat can help explain why just 23 species of crocodile survive today.""" ] PAIRED_TEXT = {k: v for k, v in zip(CHOICES, SENTENCES)} def get_paired_text(value): text = '## ' + PAIRED_TEXT.get(value, '') return text with gr.Blocks() as demo: with gr.Row(): with gr.Column(): with gr.Row(): drp_down = gr.Dropdown(choices=CHOICES, scale=2) show_text_btn = gr.Button("Select", scale=1) read_text = gr.Markdown(label='Read the follwing text') show_text_btn.click(get_paired_text, inputs=drp_down, outputs=read_text) audio_area = gr.Audio(label='Read the sentence') analyize_audio_btn = gr.Button("Submit", scale=1) with gr.Column(): capt_area = gr.Markdown(label='CAPT Scores') analyize_audio_btn.click(analyze_audio, inputs=audio_area, outputs=capt_area) demo.launch()