Spaces:
Runtime error
Runtime error
| # Created: 2026-03-07 | |
| # Purpose: Horizontal bar chart for 7 forensic audio features | |
| # Dependencies: plotly, numpy | |
| """Horizontal bar chart visualization for 7 forensic audio features.""" | |
| import plotly.graph_objects as go | |
| def plot_feature_bars(feature_stats: dict) -> go.Figure: | |
| """7๊ฐ ํฌ๋ ์ ํผ์ฒ๋ฅผ horizontal bar chart๋ก ์๊ฐํ. | |
| Args: | |
| feature_stats: Dict with feature names as keys and normalized values (0-1) | |
| Returns: | |
| plotly Figure (horizontal bar chart) | |
| """ | |
| # 7๊ฐ ํฌ๋ ์ ํผ์ฒ (์งง์ ๋ ์ด๋ธ) | |
| features = [ | |
| "Spectral Flux", | |
| "H/P Ratio", | |
| "Temporal Accel", | |
| "Temporal Delta", | |
| "Percussive", | |
| "Harmonic", | |
| "Residual Energy", | |
| ] | |
| # ๊ธฐ๋ณธ๊ฐ (feature_stats๊ฐ ์์ผ๋ฉด ์ค๊ฐ๊ฐ) | |
| if not feature_stats: | |
| values = [0.5] * 7 | |
| else: | |
| values = [ | |
| feature_stats.get("spectral_flux", 0.5), | |
| feature_stats.get("hp_ratio", 0.5), | |
| feature_stats.get("temporal_accel", 0.5), | |
| feature_stats.get("temporal_delta", 0.5), | |
| feature_stats.get("percussive_strength", 0.5), | |
| feature_stats.get("harmonic_strength", 0.5), | |
| feature_stats.get("residual_energy", 0.5), | |
| ] | |
| # AI ๊ฐ๋ฅ์ฑ ๊ธฐ์ค: ๋์์๋ก AI ์๊ทธ๋์ฒ | |
| # Residual Energy, H/P Ratio๋ ๋์์๋ก AI | |
| # Temporal Delta/Accel๋ ๋ฎ์์๋ก AI (๋ถ๋๋ฌ์ด ๋ณํ) | |
| # Harmonic/Percussive๋ ํน์ ๋น์จ๋ก ์๋ ด | |
| # Spectral Flux๋ ๋ฎ์์๋ก AI (์ผ๊ด์ ๋ณํ) | |
| # AI ์๊ทธ๋์ฒ ๊ฐ๋์ ๋ฐ๋ผ ์์ ๊ฒฐ์ | |
| colors = [] | |
| for i, (feat, val) in enumerate(zip(features, values)): | |
| if "Residual" in feat or "H/P" in feat: | |
| # ๋์์๋ก AI | |
| if val >= 0.7: | |
| colors.append('#ff4757') # AI (red) | |
| elif val >= 0.4: | |
| colors.append('#ffa502') # Uncertain (orange) | |
| else: | |
| colors.append('#2ed573') # Human (green) | |
| elif "Temporal" in feat or "Spectral" in feat: | |
| # ๋ฎ์์๋ก AI | |
| if val <= 0.3: | |
| colors.append('#ff4757') # AI (red) | |
| elif val <= 0.6: | |
| colors.append('#ffa502') # Uncertain (orange) | |
| else: | |
| colors.append('#2ed573') # Human (green) | |
| else: | |
| # Harmonic/Percussive๋ ์ค๋ฆฝ | |
| colors.append('#5f9ea0') # Neutral (cyan) | |
| fig = go.Figure(go.Bar( | |
| x=values, | |
| y=features, | |
| orientation='h', | |
| marker=dict( | |
| color=colors, | |
| line=dict(color='#fff', width=1) | |
| ), | |
| text=[f"{v:.2f}" for v in values], | |
| textposition='inside', | |
| textfont=dict(size=11, color='white', family='monospace'), | |
| hovertemplate="<b>%{y}</b><br>Score: %{x:.3f}<extra></extra>", | |
| )) | |
| fig.update_layout( | |
| xaxis=dict( | |
| title="Feature Strength", | |
| range=[0, 1], | |
| tickfont=dict(size=10, color='#aaa'), | |
| gridcolor='#333', | |
| ), | |
| yaxis=dict( | |
| tickfont=dict(size=11, color='white'), | |
| ), | |
| plot_bgcolor='#1a1a2e', | |
| paper_bgcolor='#1a1a2e', | |
| font=dict(color='white'), | |
| margin=dict(l=140, r=20, t=40, b=40), | |
| height=300, | |
| showlegend=False, | |
| title=dict( | |
| text="Forensic Feature Strength", | |
| font=dict(size=13), | |
| x=0.5, xanchor='center' | |
| ) | |
| ) | |
| return fig | |