Download controllers/views/analysis_view.py from seba3y/SpeakLab: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/seba3y/SpeakLab/resolve/main/controllers/views/analysis_view.py
- Command line
-
hf download hf://spaces/seba3y/SpeakLab/controllers/views/analysis_view.py
-
curl -L -o analysis_view.py https://huggingface.co/spaces/seba3y/SpeakLab/resolve/main/controllers/views/analysis_view.py
1.55 kB
| """ | |
| AnalysisView — renders the analysis result panel (scores + transcript). | |
| """ | |
| from models.session_models import AnalysisResult | |
| def _score_css(v: int | None) -> str: | |
| if v is None: | |
| return "sc-na" | |
| return "sc-good" if v >= 80 else ("sc-ok" if v >= 55 else "sc-poor") | |
| def _card(label: str, display: str, css: str) -> str: | |
| return ( | |
| f'<div class="score-card">' | |
| f'<div class="sc-label">{label}</div>' | |
| f'<div class="sc-value {css}">{display}</div>' | |
| f'</div>' | |
| ) | |
| def render_analysis_html(result: AnalysisResult | None = None) -> str: | |
| if result is None: | |
| result = AnalysisResult() | |
| pron_disp = f"{result.pronunciation}/100" if result.pronunciation is not None else "–" | |
| flu_disp = f"{result.fluency}/100" if result.fluency is not None else "–" | |
| if result.error: | |
| tx_html = f'<div class="transcript-box"><span class="placeholder">{result.error}</span></div>' | |
| elif result.transcript: | |
| tx_html = f'<div class="transcript-box">{result.transcript}</div>' | |
| else: | |
| tx_html = '<div class="transcript-box"><span class="placeholder">Transcript will appear here after analysis…</span></div>' | |
| return f""" | |
| <div class="analysis-box"> | |
| <h3>📊 Analysis Results</h3> | |
| <div class="score-row"> | |
| {_card("Pronunciation", pron_disp, _score_css(result.pronunciation))} | |
| {_card("Fluency", flu_disp, _score_css(result.fluency))} | |
| </div> | |
| <div class="sc-label" style="margin-bottom:6px">Transcript</div> | |
| {tx_html} | |
| </div>""" | |