import pandas as pd import numpy as np import plotly.graph_objects as go import gradio as gr from io import StringIO # Embed the CSV data directly in the code csv_data = '''cik,institution,final_score,long_term_performance_score,conviction_and_strategy_score,research_quality_and_adaptability_score,influence_and_governance_score,top_holdings_performance_score 0001843237,CEPHEI CAPITAL MANAGEMENT (HONG KONG) LTD,36,14,11,7,3,1 0001407024,NNS HOLDING,24,5,8,5,4,2 0001451928,SAC CAPITAL ADVISORS LP,50,20,10,12,6,2 0001905393,"PCG WEALTH ADVISORS, LLC",68,25,15,14,11,3 0001425362,"WHITE RIVER INVESTMENT PARTNERS, LLC",31,7,10,8,4,2 0001730210,"TRH FINANCIAL, LLC",72,28,16,15,10,3 0001165880,MONTPELIER RE HOLDINGS LTD,68,25,18,12,10,3 0001352776,REGIS MANAGEMENT CO LLC,73,28,17,14,11,3 0001582272,"BATTERY GLOBAL ADVISORS, LLC",65,22,16,14,10,3 0001466715,TRISHIELD CAPITAL MANAGEMENT LLC,59,18,,,, 0001092688,IBBOTSON ASSOCIATES INC,69,28,16,12,10,3 0001054880,HUTCHENS INVESTMENT MANAGEMENT INC,69,25,,,,3 0001650781,AXAR CAPITAL MANAGEMENT L.P.,51,16,14,12,6,3 0001425160,MERCHANTS' GATE CAPITAL LP,55,23,12,10,8,2 0001921487,"BEACON CAPITAL MANAGEMENT, LLC",78,25,22,15,12,4 ''' # Load the data from the embedded CSV string df = pd.read_csv(StringIO(csv_data)) # Clean the data df = df.dropna(subset=['final_score']) df = df.assign(institution=df['institution'].str.strip()) def create_radar_chart(institution): # Get the data for the selected institution inst_data = df[df['institution'] == institution].iloc[0] # Prepare the data for the radar chart categories = ['Long-term Performance', 'Conviction & Strategy', 'Research Quality', 'Influence & Governance', 'Top Holdings Performance'] values = [inst_data['long_term_performance_score'], inst_data['conviction_and_strategy_score'], inst_data['research_quality_and_adaptability_score'], inst_data['influence_and_governance_score'], inst_data['top_holdings_performance_score']] # Create the radar chart fig = go.Figure() fig.add_trace(go.Scatterpolar( r=values, theta=categories, fill='toself', name=institution )) fig.update_layout( polar=dict( radialaxis=dict( visible=True, range=[0, max(values)] )), showlegend=False, title=f"{institution} Performance Metrics" ) return fig def create_bar_chart(institution): # Get the data for the selected institution inst_data = df[df['institution'] == institution].iloc[0] # Prepare the data for the bar chart categories = ['Final Score', 'Long-term Performance', 'Conviction & Strategy', 'Research Quality', 'Influence & Governance', 'Top Holdings Performance'] values = [inst_data['final_score'], inst_data['long_term_performance_score'], inst_data['conviction_and_strategy_score'], inst_data['research_quality_and_adaptability_score'], inst_data['influence_and_governance_score'], inst_data['top_holdings_performance_score']] # Create the bar chart fig = go.Figure(go.Bar( x=categories, y=values, text=values, textposition='auto', )) fig.update_layout( title=f"{institution} Scores Comparison", xaxis_title="Metrics", yaxis_title="Score", yaxis=dict(range=[0, 100]) ) return fig def update_dashboard(institution): radar_chart = create_radar_chart(institution) bar_chart = create_bar_chart(institution) inst_data = df[df['institution'] == institution].iloc[0] cik = inst_data['cik'] final_score = inst_data['final_score'] return (f"CIK: {cik}", f"Final Score: {final_score:.2f}", radar_chart, bar_chart) # Create the Gradio interface iface = gr.Interface( fn=update_dashboard, inputs=gr.Dropdown(choices=sorted(df['institution'].unique()), label="Select an Institution"), outputs=[ gr.Textbox(label="CIK"), gr.Textbox(label="Final Score"), gr.Plot(label="Performance Metrics Radar Chart"), gr.Plot(label="Scores Comparison Bar Chart") ], title="Institution Performance Dashboard", description="Select an institution to view its performance metrics and scores." ) # For Hugging Face Spaces deployment iface.launch()