Spaces:
Running
Running
Download src/cli/progress.py from jcudit/voice-tools: direct link, hf CLI and curl.
- Browser
- Download file 3.86 kB
-
https://huggingface.co/spaces/jcudit/voice-tools/resolve/main/src/cli/progress.py
- Command line
-
hf download hf://spaces/jcudit/voice-tools/src/cli/progress.py
-
curl -L -o progress.py https://huggingface.co/spaces/jcudit/voice-tools/resolve/main/src/cli/progress.py
3.86 kB
| """ | |
| Progress reporting and statistics display for CLI. | |
| Uses Rich library for beautiful terminal output with progress bars, | |
| tables, and formatted statistics. | |
| """ | |
| from typing import Dict, List | |
| from rich import box | |
| from rich.console import Console | |
| from rich.panel import Panel | |
| from rich.table import Table | |
| console = Console() | |
| def display_header(title: str): | |
| """ | |
| Display a formatted header. | |
| Args: | |
| title: Header title | |
| """ | |
| console.print() | |
| console.print(Panel.fit(f"[bold cyan]{title}[/bold cyan]", border_style="cyan")) | |
| console.print() | |
| def display_success(message: str): | |
| """ | |
| Display a success message. | |
| Args: | |
| message: Success message | |
| """ | |
| console.print(f"[green]β[/green] {message}") | |
| def display_warning(message: str): | |
| """ | |
| Display a warning message. | |
| Args: | |
| message: Warning message | |
| """ | |
| console.print(f"[yellow]β [/yellow] {message}") | |
| def display_error(message: str): | |
| """ | |
| Display an error message. | |
| Args: | |
| message: Error message | |
| """ | |
| console.print(f"[red]β[/red] {message}") | |
| def display_info(message: str): | |
| """ | |
| Display an info message. | |
| Args: | |
| message: Info message | |
| """ | |
| console.print(f"[blue]βΉ[/blue] {message}") | |
| def display_segment_details(segments: List[Dict]): | |
| """ | |
| Display extracted segment details in a table. | |
| Args: | |
| segments: List of segment dictionaries | |
| """ | |
| if not segments: | |
| return | |
| table = Table(title="Extracted Segments", box=box.ROUNDED) | |
| table.add_column("#", style="cyan", no_wrap=True) | |
| table.add_column("Start", style="white") | |
| table.add_column("End", style="white") | |
| table.add_column("Duration", style="white") | |
| table.add_column("Type", style="green") | |
| table.add_column("Confidence", style="yellow") | |
| table.add_column("Quality", style="magenta") | |
| for i, segment in enumerate(segments, 1): | |
| segment_type = segment.get("segment_type", "unknown") | |
| confidence = segment.get("confidence", 0) | |
| snr = segment.get("snr") | |
| # Format quality indicator | |
| if snr is not None: | |
| quality = "β" if snr >= 15 else "β" | |
| else: | |
| quality = "?" | |
| table.add_row( | |
| str(i), | |
| f"{segment['start']:.2f}s", | |
| f"{segment['end']:.2f}s", | |
| f"{segment['duration']:.2f}s", | |
| segment_type.value if hasattr(segment_type, "value") else str(segment_type), | |
| f"{confidence:.2f}", | |
| quality, | |
| ) | |
| # Show first 20 segments, with note if more | |
| if len(segments) > 20: | |
| console.print(table) | |
| console.print(f"[dim]Showing first 20 of {len(segments)} segments[/dim]") | |
| else: | |
| console.print(table) | |
| console.print() | |
| def display_quality_report(quality_metrics: Dict): | |
| """ | |
| Display quality metrics report. | |
| Args: | |
| quality_metrics: Quality metrics dictionary | |
| """ | |
| table = Table(title="Quality Metrics", box=box.ROUNDED, show_header=False) | |
| table.add_column("Metric", style="cyan", no_wrap=True) | |
| table.add_column("Value", style="white") | |
| table.add_column("Status", style="green") | |
| if "snr" in quality_metrics: | |
| snr = quality_metrics["snr"] | |
| status = "β Pass" if snr >= 15 else "β Fail" | |
| table.add_row("SNR (Signal-to-Noise Ratio)", f"{snr:.2f} dB", status) | |
| if "stoi" in quality_metrics: | |
| stoi = quality_metrics["stoi"] | |
| status = "β Pass" if stoi >= 0.70 else "β Fail" | |
| table.add_row("STOI (Intelligibility)", f"{stoi:.2f}", status) | |
| if "pesq" in quality_metrics: | |
| pesq = quality_metrics["pesq"] | |
| status = "β Pass" if pesq >= 2.0 else "β Fail" | |
| table.add_row("PESQ (Perceptual Quality)", f"{pesq:.2f}", status) | |
| console.print(table) | |
| console.print() | |