autoace / app.py
edwixx's picture
Fix starlette/gradio_client version-mismatch crash on launch
8897472 verified
Raw
History Blame Contribute Delete
2.81 kB
import json
import os
import tempfile
import gradio as gr
import gradio_client.utils as gc_utils
import pandas as pd
from src import batch
_orig_json_schema_to_python_type = gc_utils._json_schema_to_python_type
def _safe_json_schema_to_python_type(schema, defs):
if isinstance(schema, bool):
return "Any"
return _orig_json_schema_to_python_type(schema, defs)
gc_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
RESULT_COLUMNS = [
"name",
"emotional_tone",
"emotional_intensity",
"background_noise_present",
"background_noise_type",
"background_noise_severity",
"audio_quality",
"speaker_overlap_present",
"long_silence_present",
"confidence",
]
def run_batch(file, progress=gr.Progress()):
if file is None:
return pd.DataFrame(columns=RESULT_COLUMNS), pd.DataFrame(columns=["file", "error"]), None, None
def on_progress(done, total, name):
progress(done / max(total, 1), desc=f"Analyzing {name} ({done}/{total})")
results_df, errors = batch.process_batch(file.name, on_progress=on_progress)
if results_df.empty:
results_df = pd.DataFrame(columns=RESULT_COLUMNS)
errors_df = pd.DataFrame(errors) if errors else pd.DataFrame(columns=["file", "error"])
out_dir = tempfile.mkdtemp()
csv_path = os.path.join(out_dir, "results.csv")
json_path = os.path.join(out_dir, "results.json")
results_df.to_csv(csv_path, index=False)
with open(json_path, "w") as f:
json.dump(results_df.to_dict(orient="records"), f, indent=2)
return results_df, errors_df, csv_path, json_path
with gr.Blocks(title="AutoAce Voice Tone & Background Noise") as demo:
gr.Markdown(
"# AutoAce Voice Tone & Background Noise Dashboard\n"
"Upload a `.zip` containing the audio files and a `labels.csv` / manifest "
"at the root (manifest is optional for unlabeled batches). "
"Supported audio: wav, mp3, ogg, flac, m4a."
)
upload = gr.File(label="Evaluation batch (.zip)", file_types=[".zip"])
run_btn = gr.Button("Run analysis", variant="primary")
results_table = gr.Dataframe(label="Results", headers=RESULT_COLUMNS, wrap=True)
errors_table = gr.Dataframe(label="Errors / skipped files", headers=["file", "error"], wrap=True)
with gr.Row():
csv_out = gr.File(label="Download results.csv")
json_out = gr.File(label="Download results.json")
run_btn.click(run_batch, inputs=[upload], outputs=[results_table, errors_table, csv_out, json_out])
if __name__ == "__main__":
user = os.environ.get("AUTOACE_USER", "autoace")
password = os.environ.get("AUTOACE_PASSWORD")
auth = (user, password) if password else None
demo.queue().launch(auth=auth, server_name="0.0.0.0", show_api=False)