|
|
import gradio as gr |
|
|
import csv |
|
|
import os |
|
|
import sys |
|
|
import traceback |
|
|
|
|
|
|
|
|
audio_a_path = "audio/audio_a.wav" |
|
|
audio_b_path = "audio/audio_b.wav" |
|
|
|
|
|
|
|
|
csv_dir = os.path.join(os.getcwd(), "mos-eval") |
|
|
csv_file_path = os.path.join(csv_dir, "mos_scores.csv") |
|
|
|
|
|
def submit(intelligibility, naturalness, expressiveness): |
|
|
debug_info = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
|
os.makedirs(csv_dir, exist_ok=True) |
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(csv_dir): |
|
|
debug_info.append(f"Directory contents: {os.listdir(csv_dir)}") |
|
|
|
|
|
|
|
|
file_exists = os.path.isfile(csv_file_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with open(csv_file_path, "a", newline="") as f: |
|
|
writer = csv.writer(f) |
|
|
|
|
|
|
|
|
if not file_exists: |
|
|
writer.writerow(["Audio A", "Audio B", "Intelligibility", "Naturalness", "Expressiveness"]) |
|
|
|
|
|
writer.writerow([audio_a_path, audio_b_path, intelligibility, naturalness, expressiveness]) |
|
|
f.flush() |
|
|
os.fsync(f.fileno()) |
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(csv_file_path): |
|
|
debug_info.append(f"File size: {os.path.getsize(csv_file_path)} bytes") |
|
|
|
|
|
|
|
|
csv_content = "" |
|
|
if os.path.isfile(csv_file_path): |
|
|
with open(csv_file_path, "r") as f: |
|
|
csv_content = f.read() |
|
|
|
|
|
|
|
|
return "Thank you for your feedback! Data saved successfully.\n\nDebug info:\n" + "\n".join(debug_info) |
|
|
|
|
|
except Exception as e: |
|
|
exc_type, exc_value, exc_traceback = sys.exc_info() |
|
|
tb_str = traceback.format_exception(exc_type, exc_value, exc_traceback) |
|
|
debug_info.append(f"Error: {e}") |
|
|
debug_info.append("Traceback:") |
|
|
debug_info.append("".join(tb_str)) |
|
|
return "Error occurred. Debug info:\n" + "\n".join(debug_info) |
|
|
|
|
|
|
|
|
def get_csv_data(): |
|
|
if os.path.exists(csv_file_path): |
|
|
|
|
|
return csv_file_path |
|
|
return None |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 🎧 MOS Evaluation") |
|
|
gr.Markdown("Compare Audio A and Audio B, then rate them below.") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
gr.Audio(audio_a_path, label="Audio A", type="filepath") |
|
|
with gr.Column(): |
|
|
gr.Audio(audio_b_path, label="Audio B", type="filepath") |
|
|
|
|
|
intelligibility = gr.Slider(1, 5, value=3, step=1, label="Intelligibility") |
|
|
naturalness = gr.Slider(1, 5, value=3, step=1, label="Naturalness") |
|
|
expressiveness = gr.Slider(1, 5, value=3, step=1, label="Expressiveness") |
|
|
|
|
|
submit_btn = gr.Button("Submit") |
|
|
output = gr.Textbox(label="Status", lines=15) |
|
|
|
|
|
submit_btn.click(fn=submit, inputs=[intelligibility, naturalness, expressiveness], outputs=output) |
|
|
|
|
|
|
|
|
gr.Markdown("## Download Results") |
|
|
download_btn = gr.Button("Download Results CSV") |
|
|
csv_output = gr.File(label="CSV File") |
|
|
download_btn.click(fn=get_csv_data, inputs=[], outputs=csv_output) |
|
|
|
|
|
demo.launch() |