Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
@@ -3,6 +3,17 @@ import numpy as np
|
|
3 |
import plotly.graph_objects as go
|
4 |
import gradio as gr
|
5 |
from io import StringIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Embed the CSV data directly in the code
|
8 |
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
|
@@ -26,11 +37,16 @@ csv_data = '''cik,institution,final_score,long_term_performance_score,conviction
|
|
26 |
# Load the data from the embedded CSV string
|
27 |
df = pd.read_csv(StringIO(csv_data))
|
28 |
|
|
|
|
|
29 |
# Clean the data
|
30 |
df = df.dropna(subset=['final_score'])
|
31 |
df = df.assign(institution=df['institution'].str.strip())
|
32 |
|
|
|
|
|
33 |
def create_radar_chart(institution):
|
|
|
34 |
# Get the data for the selected institution
|
35 |
inst_data = df[df['institution'] == institution].iloc[0]
|
36 |
|
@@ -66,6 +82,7 @@ def create_radar_chart(institution):
|
|
66 |
return fig
|
67 |
|
68 |
def create_bar_chart(institution):
|
|
|
69 |
# Get the data for the selected institution
|
70 |
inst_data = df[df['institution'] == institution].iloc[0]
|
71 |
|
@@ -97,6 +114,7 @@ def create_bar_chart(institution):
|
|
97 |
return fig
|
98 |
|
99 |
def update_dashboard(institution):
|
|
|
100 |
radar_chart = create_radar_chart(institution)
|
101 |
bar_chart = create_bar_chart(institution)
|
102 |
|
@@ -109,6 +127,8 @@ def update_dashboard(institution):
|
|
109 |
radar_chart,
|
110 |
bar_chart)
|
111 |
|
|
|
|
|
112 |
# Create the Gradio interface
|
113 |
iface = gr.Interface(
|
114 |
fn=update_dashboard,
|
@@ -123,5 +143,14 @@ iface = gr.Interface(
|
|
123 |
description="Select an institution to view its performance metrics and scores."
|
124 |
)
|
125 |
|
|
|
|
|
126 |
# For Hugging Face Spaces deployment
|
127 |
-
iface.launch(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import plotly.graph_objects as go
|
4 |
import gradio as gr
|
5 |
from io import StringIO
|
6 |
+
import os
|
7 |
+
import logging
|
8 |
+
|
9 |
+
# Set up logging
|
10 |
+
logging.basicConfig(level=logging.INFO)
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
|
13 |
+
# Force CPU-only mode
|
14 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = ''
|
15 |
+
|
16 |
+
logger.info("Starting application setup")
|
17 |
|
18 |
# Embed the CSV data directly in the code
|
19 |
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
|
|
|
37 |
# Load the data from the embedded CSV string
|
38 |
df = pd.read_csv(StringIO(csv_data))
|
39 |
|
40 |
+
logger.info(f"Data loaded. Shape: {df.shape}")
|
41 |
+
|
42 |
# Clean the data
|
43 |
df = df.dropna(subset=['final_score'])
|
44 |
df = df.assign(institution=df['institution'].str.strip())
|
45 |
|
46 |
+
logger.info(f"Data cleaned. Shape after cleaning: {df.shape}")
|
47 |
+
|
48 |
def create_radar_chart(institution):
|
49 |
+
logger.info(f"Creating radar chart for {institution}")
|
50 |
# Get the data for the selected institution
|
51 |
inst_data = df[df['institution'] == institution].iloc[0]
|
52 |
|
|
|
82 |
return fig
|
83 |
|
84 |
def create_bar_chart(institution):
|
85 |
+
logger.info(f"Creating bar chart for {institution}")
|
86 |
# Get the data for the selected institution
|
87 |
inst_data = df[df['institution'] == institution].iloc[0]
|
88 |
|
|
|
114 |
return fig
|
115 |
|
116 |
def update_dashboard(institution):
|
117 |
+
logger.info(f"Updating dashboard for {institution}")
|
118 |
radar_chart = create_radar_chart(institution)
|
119 |
bar_chart = create_bar_chart(institution)
|
120 |
|
|
|
127 |
radar_chart,
|
128 |
bar_chart)
|
129 |
|
130 |
+
logger.info("Creating Gradio interface")
|
131 |
+
|
132 |
# Create the Gradio interface
|
133 |
iface = gr.Interface(
|
134 |
fn=update_dashboard,
|
|
|
143 |
description="Select an institution to view its performance metrics and scores."
|
144 |
)
|
145 |
|
146 |
+
logger.info("Launching Gradio interface")
|
147 |
+
|
148 |
# For Hugging Face Spaces deployment
|
149 |
+
iface.launch(
|
150 |
+
share=False, # Disable sharing as it's not needed in Spaces
|
151 |
+
debug=True, # Enable debug mode for more detailed error messages
|
152 |
+
show_error=True, # Show full error stack traces
|
153 |
+
enable_queue=False # Disable queueing to avoid any potential GPU-related queueing issues
|
154 |
+
)
|
155 |
+
|
156 |
+
logger.info("Application setup complete")
|