import streamlit as st from PIL import Image import pandas as pd import os import json import csv st.header("Practice Section") # Replace this with the directory containing the sample audio files PRACTICE_AUDIO_DIR = 'audio/' # Replace this with the excel file (converted to csv) that contains the answers. practice_data = pd.read_csv('practice-quiz.csv') for practice in practice_data.index: ann_id = practice_data.loc[practice, 'naijavoices_audio_filename'] # st.write(f'## Practice Audio: {practice_data.loc[practice, "text"]}') with st.expander(f'Click to view evaluation task'): with st.form(key=f'practice-{ann_id}'): st.caption(":red[Instruction: first read the transcript carefully. Then listen to the audio thoroughly (can listen multiple times), before proceeding to answer the following questions. While answering the questions, come back to listen to the audio again as needed.]") st.write(f'## {practice_data.loc[practice, "text"]}') path = os.path.join(PRACTICE_AUDIO_DIR+f'{practice_data.loc[practice, "language"]}', practice_data.loc[practice, 'naijavoices_audio_filename']) print(path) st.audio(path) score = 0 min_score = 10 if practice_data.loc[practice, "Marker"] == 'Alignment': alignment = st.radio( "Select the option that best describes the alignment of the audio and transcript", options=["Audio contains EXTRA words not in the transcript", "Audio is MISSING words that are in the transcript", "Audio is MISSING words AND includes EXTRA words", "No missing or extra words"], index=None, key=f'{ann_id}-alignment' ) submit_practice_button = st.form_submit_button(label='Submit') if submit_practice_button: if alignment == practice_data.loc[practice, "correct_alignment"]: feedback = "Alignment: ✅ Correct" score +=1 else: feedback = f"Alignment: ❌ Incorrect. Correct answer: {practice_data.loc[practice, 'correct_alignment']}" st.write("### Feedback") st.write(feedback) elif practice_data.loc[practice, "Marker"] == 'Pronunciation': pronunciation = st.radio( "How accurate is the pronunciation?", options=["1: Very Inaccurate", "2: Inaccurate", "3: Neutral", "4: Accurate", "5: Very Accurate"], index=None, key=f'{ann_id}-pronunciation' ) submit_practice_button = st.form_submit_button(label='Submit') if submit_practice_button: if pronunciation == practice_data.loc[practice, "correct_pronunciation"]: feedback = "Pronunciation: ✅ Correct" score += 1 else: feedback = f"Pronunciation: ❌ Incorrect. Correct answer: {practice_data.loc[practice, 'correct_pronunciation']}" st.write("### Feedback") st.write(feedback) elif practice_data.loc[practice, "Marker"] == 'Naturalness': naturalness = st.radio( "How natural does the audio sound?", options=["1: Very Unnatural", "2: Unnatural", "3: Neutral", "4: Natural", "5: Extremely Natural"], index=None, key=f'{ann_id}-naturalness' ) submit_practice_button = st.form_submit_button(label='Submit') if submit_practice_button: if naturalness == practice_data.loc[practice, "correct_naturalness"]: feedback = "Naturalness: ✅ Correct" score += 1 else: feedback = f"Naturalness: ❌ Incorrect. Correct answer: {practice_data.loc[practice, 'correct_naturalness']}" st.write("### Feedback") st.write(feedback) elif practice_data.loc[practice, "Marker"] == 'Emotion': emotion = st.radio( "How expressive is the audio?", options=["1: No Emotional Expressiveness", "2: Slightly Expressive", "3: Moderately Expressive", "4: Expressive", "5: Highly Expressive and Appropriate"], index=None, key=f'{ann_id}-emotion' ) submit_practice_button = st.form_submit_button(label='Submit') if submit_practice_button: if emotion == practice_data.loc[practice, "correct_emotion"]: feedback ="Emotion: ✅ Correct" score += 1 else: feedback = f"Emotion: ❌ Incorrect. Correct answer: {practice_data.loc[practice, 'correct_emotion']}" st.write("### Feedback") st.write(feedback) # Check if the evaluator passes the practice if score >= min_score: st.write(f'✅ Practice Passed! Your Score: {score}/{len(practice_data)}') passed_practice = True else: st.write(f'⚠️ Your score is {score}/{len(practice_data)}. Please retry the evaluations again before proceeding.')