Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,39 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import csv
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Audio file paths
|
| 6 |
audio_a_path = "audio/audio_a.wav"
|
| 7 |
audio_b_path = "audio/audio_b.wav"
|
| 8 |
|
| 9 |
-
# Use
|
| 10 |
-
csv_dir = "mos-eval"
|
| 11 |
csv_file_path = os.path.join(csv_dir, "mos_scores.csv")
|
| 12 |
|
| 13 |
def submit(intelligibility, naturalness, expressiveness):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
try:
|
| 15 |
# Create directory if it doesn't exist
|
|
|
|
| 16 |
os.makedirs(csv_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Check if file exists to add headers if new
|
| 19 |
file_exists = os.path.isfile(csv_file_path)
|
|
|
|
| 20 |
|
|
|
|
|
|
|
| 21 |
with open(csv_file_path, "a", newline="") as f:
|
| 22 |
writer = csv.writer(f)
|
| 23 |
|
|
@@ -26,10 +42,23 @@ def submit(intelligibility, naturalness, expressiveness):
|
|
| 26 |
writer.writerow(["Audio A", "Audio B", "Intelligibility", "Naturalness", "Expressiveness"])
|
| 27 |
|
| 28 |
writer.writerow([audio_a_path, audio_b_path, intelligibility, naturalness, expressiveness])
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
except Exception as e:
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
with gr.Blocks() as demo:
|
| 35 |
gr.Markdown("# 🎧 MOS Evaluation")
|
|
@@ -46,7 +75,7 @@ with gr.Blocks() as demo:
|
|
| 46 |
expressiveness = gr.Slider(1, 5, value=3, step=1, label="Expressiveness")
|
| 47 |
|
| 48 |
submit_btn = gr.Button("Submit")
|
| 49 |
-
output = gr.Textbox(label="Status")
|
| 50 |
|
| 51 |
submit_btn.click(fn=submit, inputs=[intelligibility, naturalness, expressiveness], outputs=output)
|
| 52 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import csv
|
| 3 |
import os
|
| 4 |
+
import sys
|
| 5 |
+
import traceback
|
| 6 |
|
| 7 |
# Audio file paths
|
| 8 |
audio_a_path = "audio/audio_a.wav"
|
| 9 |
audio_b_path = "audio/audio_b.wav"
|
| 10 |
|
| 11 |
+
# Use absolute paths that are definitely writable
|
| 12 |
+
csv_dir = os.path.join(os.getcwd(), "mos-eval")
|
| 13 |
csv_file_path = os.path.join(csv_dir, "mos_scores.csv")
|
| 14 |
|
| 15 |
def submit(intelligibility, naturalness, expressiveness):
|
| 16 |
+
debug_info = []
|
| 17 |
+
debug_info.append(f"Current working directory: {os.getcwd()}")
|
| 18 |
+
debug_info.append(f"Target directory: {csv_dir}")
|
| 19 |
+
debug_info.append(f"Target file: {csv_file_path}")
|
| 20 |
+
|
| 21 |
try:
|
| 22 |
# Create directory if it doesn't exist
|
| 23 |
+
debug_info.append("Trying to create directory...")
|
| 24 |
os.makedirs(csv_dir, exist_ok=True)
|
| 25 |
+
debug_info.append(f"Directory created or already exists: {os.path.exists(csv_dir)}")
|
| 26 |
+
|
| 27 |
+
# List directory contents
|
| 28 |
+
if os.path.exists(csv_dir):
|
| 29 |
+
debug_info.append(f"Directory contents: {os.listdir(csv_dir)}")
|
| 30 |
|
| 31 |
# Check if file exists to add headers if new
|
| 32 |
file_exists = os.path.isfile(csv_file_path)
|
| 33 |
+
debug_info.append(f"File exists: {file_exists}")
|
| 34 |
|
| 35 |
+
# Try writing to the file
|
| 36 |
+
debug_info.append("Attempting to write to file...")
|
| 37 |
with open(csv_file_path, "a", newline="") as f:
|
| 38 |
writer = csv.writer(f)
|
| 39 |
|
|
|
|
| 42 |
writer.writerow(["Audio A", "Audio B", "Intelligibility", "Naturalness", "Expressiveness"])
|
| 43 |
|
| 44 |
writer.writerow([audio_a_path, audio_b_path, intelligibility, naturalness, expressiveness])
|
| 45 |
+
f.flush() # Force write to disk
|
| 46 |
+
os.fsync(f.fileno()) # Ensure it's written to the physical disk
|
| 47 |
|
| 48 |
+
# Verify the file was written
|
| 49 |
+
debug_info.append(f"File exists after write: {os.path.isfile(csv_file_path)}")
|
| 50 |
+
if os.path.isfile(csv_file_path):
|
| 51 |
+
debug_info.append(f"File size: {os.path.getsize(csv_file_path)} bytes")
|
| 52 |
+
|
| 53 |
+
return "Thank you for your feedback! Data saved successfully.\n\nDebug info:\n" + "\n".join(debug_info)
|
| 54 |
+
|
| 55 |
except Exception as e:
|
| 56 |
+
exc_type, exc_value, exc_traceback = sys.exc_info()
|
| 57 |
+
tb_str = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
| 58 |
+
debug_info.append(f"Error: {e}")
|
| 59 |
+
debug_info.append("Traceback:")
|
| 60 |
+
debug_info.append("".join(tb_str))
|
| 61 |
+
return "Error occurred. Debug info:\n" + "\n".join(debug_info)
|
| 62 |
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
gr.Markdown("# 🎧 MOS Evaluation")
|
|
|
|
| 75 |
expressiveness = gr.Slider(1, 5, value=3, step=1, label="Expressiveness")
|
| 76 |
|
| 77 |
submit_btn = gr.Button("Submit")
|
| 78 |
+
output = gr.Textbox(label="Status", lines=10) # Increased size for debug output
|
| 79 |
|
| 80 |
submit_btn.click(fn=submit, inputs=[intelligibility, naturalness, expressiveness], outputs=output)
|
| 81 |
|