Spaces:
Runtime error
Runtime error
File size: 5,295 Bytes
1bd76f4 401c3ed f347152 752029d 401c3ed 752029d 401c3ed 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 1bd76f4 f347152 da2b354 f347152 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
import pandas as pd
import numpy as np
import plotly.graph_objects as go
import gradio as gr
from io import StringIO
import os
import logging
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Force CPU-only mode
os.environ['CUDA_VISIBLE_DEVICES'] = ''
logger.info("Starting application setup")
# 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))
logger.info(f"Data loaded. Shape: {df.shape}")
# Clean the data
df = df.dropna(subset=['final_score'])
df = df.assign(institution=df['institution'].str.strip())
logger.info(f"Data cleaned. Shape after cleaning: {df.shape}")
def create_radar_chart(institution):
logger.info(f"Creating radar chart for {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):
logger.info(f"Creating bar chart for {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):
logger.info(f"Updating dashboard for {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)
logger.info("Creating Gradio interface")
# 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."
)
logger.info("Launching Gradio interface")
# For Hugging Face Spaces deployment
iface.launch(
share=False, # Disable sharing as it's not needed in Spaces
debug=True # Enable debug mode for more detailed error messages
)
logger.info("Application setup complete")
|