""" app.py HIFFI Artist Intelligence - Multi-Platform Executive Dashboard Clean dark-themed design with multi-platform evidence tiers, Spotify & Instagram telemetry, ChartMasters record sales (CSPC/EAS), breakout velocity index, deep-dive scouting dossier, and experimental Commercial Power Index (CPI) simulation engine with sensitivity analysis. """ from pathlib import Path import pandas as pd import plotly.express as px import plotly.graph_objects as go import streamlit as st from core.cpi_engine import CommercialPowerEngine from exporters.excel_workbook import generate_executive_sales_workbook st.set_page_config( page_title="HIFFI | Multi-Platform Intelligence", page_icon="โšก", layout="wide", initial_sidebar_state="expanded", ) DATA_PATH = Path("data/hiffi_multiplatform_500.csv") FALLBACK_DATA_PATH = Path("enriched_artists.csv") # Global CSS Styling st.markdown( """ """, unsafe_allow_html=True, ) @st.cache_data(ttl=60) def load_data(): target = DATA_PATH if DATA_PATH.exists() else FALLBACK_DATA_PATH if not target.exists(): return pd.DataFrame() df = pd.read_csv(target) if "hiffi_xp_published_rank" not in df.columns: df["hiffi_xp_published_rank"] = df.get("hiffi_xp_rank", df.get("hiffi_rank", df.index + 1)) if "hiffi_xp_score" not in df.columns: df["hiffi_xp_score"] = df.get("production_hiffi_score", df.get("hiffi_score", 0.0)) if "platform_evidence_tier" not in df.columns: has_yt = df.get("production_hiffi_score", df.get("hiffi_score")).notna().astype(int) has_sp = df.get("spotify_monthly_listeners", pd.Series(index=df.index)).notna().astype(int) has_ig = df.get("instagram_followers", pd.Series(index=df.index)).notna().astype(int) df["platform_evidence_tier"] = has_yt + has_sp + has_ig numeric_cols = [ "hiffi_xp_published_rank", "hiffi_xp_rank", "hiffi_xp_score", "production_hiffi_rank", "production_hiffi_score", "platform_evidence_tier", "breakout_velocity_index", "subscriber_count", "daily_view_velocity", "momentum_30d", "spotify_monthly_listeners", "spotify_daily_change", "instagram_followers", "confidence_score", "breakout_rank", "chartmasters_sales_rank", "cohort_sales_rank", "pure_album_sales", "physical_singles_sales", "digital_singles_sales", "streaming_eas", "total_eas_cspc", "riaa_certified_album_units", "riaa_certified_singles_units", ] for col in numeric_cols: if col in df.columns: df[col] = pd.to_numeric(df[col], errors="coerce") # Commercial Power Engine engine = CommercialPowerEngine() df["commercial_power_index"] = engine.calculate_cpi(df) if "subgenre" not in df.columns: def infer_subgenre(r): subs = r.get("subscriber_count", 0) or 0 bvi = r.get("breakout_velocity_index", 0) or 0 if bvi >= 70: return "Breakout / Emerging" elif subs >= 15000000: return "Legends" else: return "Trap & Street" df["subgenre"] = df.apply(infer_subgenre, axis=1) return df df = load_data() engine = CommercialPowerEngine() def get_provenance_badge(status: str) -> str: """Format status values into readable provenance labels.""" s = str(status).strip() if s == "VERIFIED_CSPC": return "โœ… VERIFIED (CSPC)" elif s == "VERIFIED_RIAA": return "๐Ÿ… VERIFIED (RIAA)" elif s == "ESTIMATED_SEA": return "๐Ÿ“Š ESTIMATED (SEA)" return "โณ PENDING_INGESTION" # ----------------- Sidebar Controls ----------------- with st.sidebar: st.markdown("### โšก HIFFI Multi-Platform") st.caption("YouTube โ€ข Spotify โ€ข Instagram โ€ข Sales Telemetry") st.markdown("
", unsafe_allow_html=True) if df.empty: st.error("No dataset found. Run pipeline to generate master data.") st.stop() view_mode = st.radio( "Leaderboard Perspective:", [ "๐Ÿ† Published Multi-Platform Rank", "๐Ÿš€ Breakout Velocity (BVI)", "๐Ÿ’ฟ Record Sales (CSPC Methodology)", "๐Ÿงช Commercial Simulation Engine (CPI)", "๐Ÿ” Full Cohort Audit Grid", ], index=0, ) st.markdown("
", unsafe_allow_html=True) catalog_filter = "All Monitored Artists (500)" if view_mode in ("๐Ÿ’ฟ Record Sales (CSPC Methodology)", "๐Ÿงช Commercial Simulation Engine (CPI)"): st.markdown("##### ๐Ÿ” Sales Catalog Scope") catalog_filter = st.radio( "Filter Rows by Sales Telemetry:", ["All Monitored Artists (500)", "Verified Only (321)", "Pure CSPC Only (62)"], index=0, help="Toggle between viewing the full cohort, verified certifications, or only ChartMasters studies.", ) st.markdown("
", unsafe_allow_html=True) sim_weight = 0.15 sim_mode = "matched_only" if view_mode == "๐Ÿงช Commercial Simulation Engine (CPI)": st.markdown("##### ๐Ÿงช Simulation Parameters") sim_mode_choice = st.radio( "Evaluation Scope:", ["๐ŸŽฏ Matched Cohort Only", "๐ŸŒ Global Cohort (N=500, Weight Redistribution)"], index=1 if catalog_filter == "All Monitored Artists (500)" else 0, help="Matched Cohort evaluates cataloged artists in an isolated leaderboard. Global Cohort keeps all artists with normalized weights.", ) sim_mode = "matched_only" if "Matched" in sim_mode_choice else "global_redistribution" sim_weight = st.select_slider( "Commercial Signal Weight:", options=[0.0, 0.05, 0.10, 0.15, 0.20], value=0.15, format_func=lambda x: f"{int(x*100)}% Commercial", help="Blends Commercial Power Index (CPI) with baseline production score.", ) st.caption(f"Baseline Score Weight: **{int((1.0 - sim_weight)*100)}%**") st.markdown("
", unsafe_allow_html=True) st.markdown("##### ๐Ÿ›ก๏ธ Cohort Filters") all_verticals = sorted(df["subgenre"].dropna().unique().tolist()) selected_verticals = st.multiselect("Vertical", options=all_verticals, default=all_verticals) tier_options = sorted(df["platform_evidence_tier"].dropna().unique().astype(int).tolist(), reverse=True) selected_tiers = st.multiselect("Evidence Tier", options=tier_options, default=tier_options) min_xp = st.slider("Min HIFFI-XP Score", 0.0, 100.0, 0.0, 5.0) # Filter logic filtered_df = df[ (df["subgenre"].isin(selected_verticals)) & (df["platform_evidence_tier"].isin(selected_tiers)) & (df["hiffi_xp_score"].fillna(0.0) >= min_xp) ].copy() if catalog_filter == "Pure CSPC Only (62)": filtered_df = filtered_df[filtered_df["sales_data_status"] == "VERIFIED_CSPC"].copy() elif catalog_filter == "Verified Only (321)": filtered_df = filtered_df[filtered_df["sales_data_status"].isin(["VERIFIED_CSPC", "VERIFIED_RIAA"])].copy() # Execute simulation calculations if chosen sim_metrics = {} if view_mode == "๐Ÿงช Commercial Simulation Engine (CPI)": filtered_df = engine.simulate_ranking(filtered_df, commercial_weight=sim_weight, mode=sim_mode) sim_metrics = engine.compute_simulation_metrics(filtered_df) with st.sidebar: st.markdown("
", unsafe_allow_html=True) st.markdown("##### ๐Ÿ’พ Unified Audit Exports") excel_workbook_bytes = generate_executive_sales_workbook(filtered_df, commercial_weight=sim_weight, mode=sim_mode) st.download_button( "๐Ÿ“Š Multi-Tab Audit Excel (.xlsx)", data=excel_workbook_bytes, file_name="hiffi_executive_sales_audit.xlsx", mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", width="stretch", ) csv_payload = filtered_df.to_csv(index=False).encode("utf-8") st.download_button( "๐Ÿ“ฅ Filtered Table CSV", data=csv_payload, file_name="hiffi_multiplatform_filtered.csv", mime="text/csv", width="stretch", ) st.markdown("
", unsafe_allow_html=True) st.caption("Governance: CSPC Methodology โ€ข EAS Units โ€ข Zero-Imputation Compliant") # ----------------- Main Header ----------------- head_col1, head_col2 = st.columns([3, 1]) with head_col1: st.markdown("

HIFFI Multi-Platform Intelligence Hub

", unsafe_allow_html=True) st.markdown("

Multi-platform composite rankings with zero-imputation policy, dynamic weight redistribution, and verified record sales.

", unsafe_allow_html=True) with head_col2: st.markdown( f"
Filtered Cohort: {len(filtered_df)} / {len(df)} artists
", unsafe_allow_html=True, ) # ----------------- Macro KPI Cards ----------------- k1, k2, k3, k4, k5 = st.columns(5) with k1: st.markdown(f'
Tracked Artists
{len(df)}
Monitored Cohort
', unsafe_allow_html=True) with k2: t3_count = len(df[df["platform_evidence_tier"] == 3]) st.markdown(f'
Tier 3 (Complete)
{t3_count}
YouTube + Spotify + Instagram
', unsafe_allow_html=True) with k3: sp_count = df["spotify_monthly_listeners"].notna().sum() st.markdown(f'
Spotify Telemetry
{sp_count}
Verified monthly listeners
', unsafe_allow_html=True) with k4: ig_count = df["instagram_followers"].notna().sum() st.markdown(f'
Instagram Audience
{ig_count}
Verified public followings
', unsafe_allow_html=True) with k5: cataloged_count = df["total_eas_cspc"].fillna(0).gt(0).sum() st.markdown(f'
Catalog Coverage
{cataloged_count}
100% Cohort Cataloged
', unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) # ----------------- Dynamic Telemetry Coverage Banner ----------------- if view_mode in ("๐Ÿ’ฟ Record Sales (CSPC Methodology)", "๐Ÿงช Commercial Simulation Engine (CPI)"): verified_cspc_cnt = int((df["sales_data_status"] == "VERIFIED_CSPC").sum()) verified_riaa_cnt = int((df["sales_data_status"] == "VERIFIED_RIAA").sum()) estimated_sea_cnt = int((df["sales_data_status"] == "ESTIMATED_SEA").sum()) total_active_coverage = verified_cspc_cnt + verified_riaa_cnt + estimated_sea_cnt coverage_pct = (total_active_coverage / len(df)) * 100.0 st.markdown( f"""
๐Ÿ“ก Commercial Telemetry Coverage Progress: {verified_cspc_cnt} CSPC Verified โ€ข {verified_riaa_cnt} RIAA Certified โ€ข {estimated_sea_cnt} Streaming SEA
Active Commercial Coverage: {coverage_pct:.1f}% ({total_active_coverage}/{len(df)})
""", unsafe_allow_html=True, ) # ----------------- Standalone Module Views ----------------- if view_mode == "๐Ÿ’ฟ Record Sales (CSPC Methodology)": st.markdown("### ๐Ÿ’ฟ Global Record Sales & Lifetime Commercial Ranking") st.caption("Standardized on ChartMasters CSPC, verified RIAA certifications, and video/audio streaming equivalent units.") sc1, sc2, sc3, sc4 = st.columns(4) total_sales_volume = filtered_df["total_eas_cspc"].fillna(0).sum() cspc_count = (filtered_df["sales_data_status"] == "VERIFIED_CSPC").sum() riaa_count = (filtered_df["sales_data_status"] == "VERIFIED_RIAA").sum() sea_count = (filtered_df["sales_data_status"] == "ESTIMATED_SEA").sum() with sc1: st.markdown(f'
Tracked Catalog Volume
{total_sales_volume/1e6:.1f}M
Total Equivalent Album Sales (EAS)
', unsafe_allow_html=True) with sc2: st.markdown(f'
CSPC Verified
{cspc_count}
ChartMasters Full Dossiers
', unsafe_allow_html=True) with sc3: st.markdown(f'
RIAA Certified
{riaa_count}
Domestic Certifications
', unsafe_allow_html=True) with sc4: st.markdown(f'
Streaming SEA
{sea_count}
Luminate/Billboard Conversion
', unsafe_allow_html=True) st.markdown("#### ๐Ÿ† All-Time Global Sales Leaderboard") sales_table_df = filtered_df.sort_values(by="total_eas_cspc", ascending=False).copy() sales_table_df["provenance_badge"] = sales_table_df["sales_data_status"].apply(get_provenance_badge) sales_cols = [ "cohort_sales_rank", "chartmasters_sales_rank", "name", "provenance_badge", "total_eas_cspc", "pure_album_sales", "streaming_eas", "physical_singles_sales", "digital_singles_sales", "commercial_power_index", "hiffi_xp_published_rank", ] render_s_cols = [c for c in sales_cols if c in sales_table_df.columns] st.dataframe( sales_table_df[render_s_cols].reset_index(drop=True), width="stretch", height=380, column_config={ "cohort_sales_rank": st.column_config.NumberColumn("Cohort Sales Rank", format="#%d", width="small"), "chartmasters_sales_rank": st.column_config.NumberColumn("All-Time Global Rank", format="#%d", width="small"), "name": st.column_config.TextColumn("Artist", width="medium"), "provenance_badge": st.column_config.TextColumn("Audit Provenance", width="medium"), "total_eas_cspc": st.column_config.NumberColumn("Total EAS Units", format="%,d", width="medium"), "pure_album_sales": st.column_config.NumberColumn("Pure Studio Albums", format="%,d", width="medium"), "streaming_eas": st.column_config.NumberColumn("Streaming EAS", format="%,d", width="medium"), "physical_singles_sales": st.column_config.NumberColumn("Physical Singles", format="%,d", width="small"), "digital_singles_sales": st.column_config.NumberColumn("Digital Downloads", format="%,d", width="small"), "commercial_power_index": st.column_config.ProgressColumn("CPI Score", min_value=0, max_value=100, format="%.1f", width="small"), "hiffi_xp_published_rank": st.column_config.NumberColumn("HIFFI Base Rank", format="#%d", width="small"), }, ) st.markdown("
", unsafe_allow_html=True) c_s1, c_s2 = st.columns(2) with c_s1: top_sellers = sales_table_df[sales_table_df["total_eas_cspc"] > 0].head(12) fig_format = go.Figure() fig_format.add_trace(go.Bar(name="Traditional Albums", x=top_sellers["name"], y=top_sellers["pure_album_sales"], marker_color="#8b5cf6")) fig_format.add_trace(go.Bar(name="Digital Singles", x=top_sellers["name"], y=top_sellers["digital_singles_sales"], marker_color="#38bdf8")) fig_format.add_trace(go.Bar(name="Streaming EAS", x=top_sellers["name"], y=top_sellers["streaming_eas"], marker_color="#10b981")) fig_format.update_layout( barmode="stack", title="Format Contribution: Pure Albums vs Downloads vs Streaming EAS", template="plotly_dark", paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), height=360, margin=dict(l=20, r=20, t=50, b=20), legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1.0), ) st.plotly_chart(fig_format, width="stretch") with c_s2: scatter_data = sales_table_df.dropna(subset=["total_eas_cspc", "hiffi_xp_score"]).copy() fig_quad = px.scatter( scatter_data, x="hiffi_xp_score", y="total_eas_cspc", size="total_eas_cspc", color="provenance_badge", hover_name="name", log_y=True, title="Legacy vs. Velocity Quadrant (All-Time Sales vs HIFFI-XP)", labels={"hiffi_xp_score": "Current Multi-Platform Velocity (HIFFI-XP)", "total_eas_cspc": "Total Lifetime EAS Units (Log Scale)"}, template="plotly_dark", ) fig_quad.update_layout( paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), height=360, margin=dict(l=20, r=20, t=50, b=20), ) st.plotly_chart(fig_quad, width="stretch") else: top3 = filtered_df.sort_values(by="hiffi_xp_published_rank", ascending=True).head(3) if len(top3) >= 3 and view_mode != "๐Ÿงช Commercial Simulation Engine (CPI)": st.markdown("#### ๐Ÿ‘‘ Market Leaders (Published Baseline Rankings)") p1, p2, p3 = st.columns(3) podium_data = [ (p1, top3.iloc[0], "๐Ÿฅ‡ PUBLISHED #1", "podium-gold", "#f59e0b"), (p2, top3.iloc[1], "๐Ÿฅˆ PUBLISHED #2", "podium-silver", "#94a3b8"), (p3, top3.iloc[2], "๐Ÿฅ‰ PUBLISHED #3", "podium-bronze", "#f97316"), ] for col, row_data, rank_label, css_class, accent_color in podium_data: tier_val = int(row_data.get("platform_evidence_tier", 1)) sp_str = f"{int(row_data['spotify_monthly_listeners']):,}" if pd.notna(row_data.get("spotify_monthly_listeners")) else "NaN" ig_str = f"{int(row_data['instagram_followers']):,}" if pd.notna(row_data.get("instagram_followers")) else "NaN" with col: st.markdown( f"""
{rank_label} Tier {tier_val} Evidence
{row_data['name']}
{row_data.get('channel_title', '')}
HIFFI-XP
{row_data['hiffi_xp_score']:.2f}
Spotify Monthly
{sp_str}
IG Followers
{ig_str}
""", unsafe_allow_html=True, ) st.markdown("
", unsafe_allow_html=True) if view_mode == "๐Ÿงช Commercial Simulation Engine (CPI)": st.markdown("#### ๐Ÿงช Simulation Impact & Decision Summary") sm1, sm2, sm3, sm4 = st.columns(4) g_delta = f"+{sim_metrics.get('top_gainer_delta', 0)}" if sim_metrics.get('top_gainer_delta', 0) > 0 else f"{sim_metrics.get('top_gainer_delta', 0)}" l_delta = f"{sim_metrics.get('top_loser_delta', 0)}" with sm1: st.markdown(f'
Top Gainer
{sim_metrics.get("top_gainer_name", "None")} (โ–ฒ {g_delta})
', unsafe_allow_html=True) with sm2: st.markdown(f'
Top Loser
{sim_metrics.get("top_loser_name", "None")} (โ–ผ {l_delta})
', unsafe_allow_html=True) with sm3: st.markdown(f'
Mean Absolute Shift
ยฑ {sim_metrics.get("mean_abs_delta", 0.0)} positions
', unsafe_allow_html=True) with sm4: st.markdown(f'
Simulation Scope
{sim_metrics.get("matched_coverage", 0)} / {len(filtered_df)} ({sim_mode})
', unsafe_allow_html=True) st.caption(f"๐Ÿ’ก **Executive Takeaway:** At **{int(sim_weight*100)}% commercial weight**, the average cataloged artist moves **ยฑ{sim_metrics.get('mean_abs_delta', 0.0)} positions**.") st.markdown("
", unsafe_allow_html=True) st.markdown(f"#### ๐Ÿ“‹ {view_mode}") if view_mode == "๐Ÿ† Published Multi-Platform Rank": table_df = filtered_df.sort_values(by="hiffi_xp_published_rank", ascending=True).copy() cols = ["hiffi_xp_published_rank", "hiffi_xp_rank", "name", "platform_evidence_tier", "hiffi_xp_score", "spotify_monthly_listeners", "instagram_followers", "effective_weights", "anomaly_flags"] elif view_mode == "๐Ÿš€ Breakout Velocity (BVI)": table_df = filtered_df[filtered_df["breakout_velocity_index"].notna()].sort_values(by="breakout_velocity_index", ascending=False).copy() cols = ["name", "breakout_velocity_index", "hiffi_xp_published_rank", "daily_view_velocity", "momentum_30d", "subscriber_count", "subgenre"] elif view_mode == "๐Ÿงช Commercial Simulation Engine (CPI)": table_df = filtered_df.sort_values(by="simulated_rank", ascending=True).copy() def format_rank_delta(val): if pd.isna(val): return "N/A" ival = int(val) if ival > 0: return f"โ–ฒ +{ival} (Up)" elif ival < 0: return f"โ–ผ {ival} (Down)" else: return "โ€” 0 (Equal)" table_df["rank_shift_indicator"] = table_df["simulation_rank_delta"].apply(format_rank_delta) comp_rank = "baseline_matched_rank" if sim_mode == "matched_only" else "hiffi_xp_published_rank" cols = [ "simulated_rank", comp_rank, "rank_shift_indicator", "name", "simulated_hiffi_score", "hiffi_xp_score", "commercial_power_index", "total_eas_cspc", "sales_data_status", ] else: table_df = filtered_df.sort_values(by="hiffi_xp_published_rank", ascending=True).copy() cols = ["hiffi_xp_published_rank", "name", "production_hiffi_rank", "hiffi_xp_rank", "rank_delta", "platform_evidence_tier", "hiffi_xp_score", "spotify_monthly_listeners", "instagram_followers", "total_eas_cspc", "sales_data_status", "evidence_exclusions", "anomaly_flags"] display_table = table_df.copy() if "sales_data_status" in display_table.columns: display_table["sales_data_status"] = display_table["sales_data_status"].apply(get_provenance_badge) render_cols = [c for c in cols if c in display_table.columns] st.dataframe( display_table[render_cols].reset_index(drop=True), width="stretch", height=340, column_config={ "hiffi_xp_published_rank": st.column_config.NumberColumn("Published Rank", format="%d", width="small"), "baseline_matched_rank": st.column_config.NumberColumn("Baseline Match Rank", format="%d", width="small"), "simulated_rank": st.column_config.NumberColumn("Simulated Rank", format="%d", width="small"), "rank_shift_indicator": st.column_config.TextColumn("Simulated ฮ” (Movement)", width="medium"), "simulated_hiffi_score": st.column_config.ProgressColumn("Simulated Score", format="%.2f", min_value=0, max_value=100, width="medium"), "hiffi_xp_score": st.column_config.ProgressColumn("HIFFI-XP Score", format="%.2f", min_value=0, max_value=100, width="medium"), "commercial_power_index": st.column_config.ProgressColumn("Commercial Power Index", format="%.1f", min_value=0, max_value=100, width="medium"), "total_eas_cspc": st.column_config.NumberColumn("Total Equivalent Album Sales", format="%,d", width="medium"), "pure_album_sales": st.column_config.NumberColumn("Traditional Album Sales", format="%,d", width="medium"), "streaming_eas": st.column_config.NumberColumn("Streaming-Equivalent Album Sales", format="%,d", width="medium"), "sales_data_status": st.column_config.TextColumn("Sales Audit Status", width="medium"), }, ) st.markdown("
", unsafe_allow_html=True) if view_mode == "๐Ÿงช Commercial Simulation Engine (CPI)": c_sim1, c_sim2 = st.columns(2) with c_sim1: sim_delta_df = filtered_df.dropna(subset=["simulation_rank_delta"]).sort_values(by="total_eas_cspc", ascending=False).head(15).copy() if not sim_delta_df.empty: fig_delta = px.bar( sim_delta_df, x="name", y="simulation_rank_delta", color="simulation_rank_delta", color_continuous_scale="RdYlGn", title=f"Simulated Rank Movement at {int(sim_weight*100)}% Commercial Weight (Top 15 Sellers)", labels={"simulation_rank_delta": "Rank Movement (โ–ฒ Positive / โ–ผ Negative)", "name": "Artist"}, template="plotly_dark", ) fig_delta.update_layout( paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), margin=dict(l=20, r=20, t=50, b=20), height=350, ) st.plotly_chart(fig_delta, width="stretch") with c_sim2: sensitivity_df = engine.run_sensitivity_matrix(filtered_df, mode=sim_mode).head(15) fig_sens = go.Figure() for idx, r in sensitivity_df.head(6).iterrows(): fig_sens.add_trace(go.Scatter( x=["0%", "5%", "10%", "15%", "20%"], y=[r["rank_0pct"], r["rank_5pct"], r["rank_10pct"], r["rank_15pct"], r["rank_20pct"]], mode="lines+markers", name=r["name"], )) fig_sens.update_layout( title="Weight Sensitivity: Rank Trajectories Across Weights (Top Volatile Acts)", yaxis=dict(autorange="reversed", title="Simulated Rank (Lower is Better)"), xaxis=dict(title="Commercial Signal Weight (%)"), template="plotly_dark", paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), margin=dict(l=20, r=20, t=50, b=20), height=350, ) st.plotly_chart(fig_sens, width="stretch") else: c_left, c_right = st.columns(2) with c_left: chart_df = filtered_df.dropna(subset=["spotify_monthly_listeners", "instagram_followers", "hiffi_xp_score"]).copy() if not chart_df.empty: fig_scatter = px.scatter( chart_df, x="spotify_monthly_listeners", y="instagram_followers", size="hiffi_xp_score", color="platform_evidence_tier", hover_name="name", log_x=True, log_y=True, title="Spotify Monthly Listeners vs. Instagram Followers", labels={"spotify_monthly_listeners": "Spotify Monthly Listeners (Log Scale)", "instagram_followers": "Instagram Followers (Log Scale)", "platform_evidence_tier": "Tier"}, template="plotly_dark", ) fig_scatter.update_layout( paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), margin=dict(l=20, r=20, t=40, b=20), height=320, ) st.plotly_chart(fig_scatter, width="stretch") with c_right: tier_counts = filtered_df["platform_evidence_tier"].value_counts().reset_index() tier_counts.columns = ["Tier", "Count"] fig_pie = px.pie(tier_counts, values="Count", names="Tier", title="Evidence Tier Cohort Distribution", template="plotly_dark", color="Tier", color_discrete_map={3: "#10b981", 2: "#38bdf8", 1: "#f59e0b", 0: "#ef4444"}) fig_pie.update_layout( paper_bgcolor="#111827", plot_bgcolor="#111827", font=dict(color="#9ca3af"), margin=dict(l=20, r=20, t=40, b=20), height=320, ) st.plotly_chart(fig_pie, width="stretch") # ----------------- Deep Dive Scouting Dossier ----------------- st.markdown("
", unsafe_allow_html=True) st.markdown("#### ๐Ÿ”Ž Artist Dossier") selected_name = st.selectbox("Inspect Artist Details:", df["name"].unique(), label_visibility="collapsed") row = df[df["name"] == selected_name].iloc[0] d1, d2, d3, d4, d5 = st.columns(5) with d1: h_val = row.get("hiffi_xp_score") st.metric("HIFFI-XP Score", f"{h_val:.2f}" if pd.notna(h_val) else "N/A") with d2: pub_rank = row.get("hiffi_xp_published_rank") st.metric("Published Rank", f"#{int(pub_rank)}" if pd.notna(pub_rank) else "Unranked") with d3: sp_l = row.get("spotify_monthly_listeners") st.metric("Spotify Listeners", f"{int(sp_l):,}" if pd.notna(sp_l) else "Unindexed (NaN)") with d4: ig_f = row.get("instagram_followers") st.metric("Instagram Followers", f"{int(ig_f):,}" if pd.notna(ig_f) else "Unindexed (NaN)") with d5: sales_val = row.get("total_eas_cspc") st.metric("Total EAS Sales", f"{int(sales_val):,}" if pd.notna(sales_val) else "Awaiting Ingestion") st.markdown( f"""
Artist: {row['name']}
Evidence Tier: Tier {int(row.get('platform_evidence_tier', 1))}
Global Sales Rank: {f"#{int(row.get('chartmasters_sales_rank'))}" if pd.notna(row.get('chartmasters_sales_rank')) else "Unranked"}
Cohort Sales Rank: {f"#{int(row.get('cohort_sales_rank'))}" if pd.notna(row.get('cohort_sales_rank')) else "Uncataloged"}
Commercial Power Index: {f"{row.get('commercial_power_index'):.1f}" if pd.notna(row.get('commercial_power_index')) else "Awaiting Audit"}
Traditional Albums: {f"{int(row.get('pure_album_sales')):,}" if pd.notna(row.get('pure_album_sales')) else "N/A"}
Streaming-Equivalent EAS: {f"{int(row.get('streaming_eas')):,}" if pd.notna(row.get('streaming_eas')) else "N/A"}
Sales Status: {get_provenance_badge(row.get('sales_data_status', ''))}
Effective Weights: {row.get('effective_weights', 'N/A')}
Anomaly Flags: {row.get('anomaly_flags', 'CLEAN')}
""", unsafe_allow_html=True, )