Update app.py
Browse files
app.py
CHANGED
|
@@ -17,41 +17,48 @@ def submit(intelligibility, naturalness, expressiveness):
|
|
| 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 |
-
|
| 40 |
# Add headers if file is new
|
| 41 |
if not file_exists:
|
| 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)
|
|
@@ -63,20 +70,20 @@ def submit(intelligibility, naturalness, expressiveness):
|
|
| 63 |
with gr.Blocks() as demo:
|
| 64 |
gr.Markdown("# 🎧 MOS Evaluation")
|
| 65 |
gr.Markdown("Compare Audio A and Audio B, then rate them below.")
|
| 66 |
-
|
| 67 |
with gr.Row():
|
| 68 |
with gr.Column():
|
| 69 |
gr.Audio(audio_a_path, label="Audio A", type="filepath")
|
| 70 |
with gr.Column():
|
| 71 |
gr.Audio(audio_b_path, label="Audio B", type="filepath")
|
| 72 |
-
|
| 73 |
intelligibility = gr.Slider(1, 5, value=3, step=1, label="Intelligibility")
|
| 74 |
naturalness = gr.Slider(1, 5, value=3, step=1, label="Naturalness")
|
| 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=
|
| 79 |
-
|
| 80 |
submit_btn.click(fn=submit, inputs=[intelligibility, naturalness, expressiveness], outputs=output)
|
| 81 |
-
|
| 82 |
demo.launch()
|
|
|
|
| 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 |
+
|
| 40 |
# Add headers if file is new
|
| 41 |
if not file_exists:
|
| 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 |
+
# Read and display CSV content
|
| 54 |
+
csv_content = ""
|
| 55 |
+
if os.path.isfile(csv_file_path):
|
| 56 |
+
with open(csv_file_path, "r") as f:
|
| 57 |
+
csv_content = f.read()
|
| 58 |
+
debug_info.append(f"\nCSV Content:\n{csv_content}")
|
| 59 |
+
|
| 60 |
return "Thank you for your feedback! Data saved successfully.\n\nDebug info:\n" + "\n".join(debug_info)
|
| 61 |
+
|
| 62 |
except Exception as e:
|
| 63 |
exc_type, exc_value, exc_traceback = sys.exc_info()
|
| 64 |
tb_str = traceback.format_exception(exc_type, exc_value, exc_traceback)
|
|
|
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
gr.Markdown("# 🎧 MOS Evaluation")
|
| 72 |
gr.Markdown("Compare Audio A and Audio B, then rate them below.")
|
| 73 |
+
|
| 74 |
with gr.Row():
|
| 75 |
with gr.Column():
|
| 76 |
gr.Audio(audio_a_path, label="Audio A", type="filepath")
|
| 77 |
with gr.Column():
|
| 78 |
gr.Audio(audio_b_path, label="Audio B", type="filepath")
|
| 79 |
+
|
| 80 |
intelligibility = gr.Slider(1, 5, value=3, step=1, label="Intelligibility")
|
| 81 |
naturalness = gr.Slider(1, 5, value=3, step=1, label="Naturalness")
|
| 82 |
expressiveness = gr.Slider(1, 5, value=3, step=1, label="Expressiveness")
|
| 83 |
+
|
| 84 |
submit_btn = gr.Button("Submit")
|
| 85 |
+
output = gr.Textbox(label="Status", lines=15) # Increased size for debug and CSV output
|
| 86 |
+
|
| 87 |
submit_btn.click(fn=submit, inputs=[intelligibility, naturalness, expressiveness], outputs=output)
|
| 88 |
+
|
| 89 |
demo.launch()
|