zaursamedov1 commited on
Commit
1bd76f4
·
verified ·
1 Parent(s): 0073807

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +107 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import plotly.graph_objects as go
4
+ import gradio as gr
5
+
6
+ # Load the data
7
+ df = pd.read_csv('/content/INSTITUTIONAL_INVESTORS_SCORE.csv')
8
+
9
+ # Clean the data
10
+ df = df.dropna(subset=['final_score'])
11
+ df = df.assign(institution=df['institution'].str.strip())
12
+
13
+ def create_radar_chart(institution):
14
+ # Get the data for the selected institution
15
+ inst_data = df[df['institution'] == institution].iloc[0]
16
+
17
+ # Prepare the data for the radar chart
18
+ categories = ['Long-term Performance', 'Conviction & Strategy', 'Research Quality',
19
+ 'Influence & Governance', 'Top Holdings Performance']
20
+ values = [inst_data['long_term_performance_score'],
21
+ inst_data['conviction_and_strategy_score'],
22
+ inst_data['research_quality_and_adaptability_score'],
23
+ inst_data['influence_and_governance_score'],
24
+ inst_data['top_holdings_performance_score']]
25
+
26
+ # Create the radar chart
27
+ fig = go.Figure()
28
+
29
+ fig.add_trace(go.Scatterpolar(
30
+ r=values,
31
+ theta=categories,
32
+ fill='toself',
33
+ name=institution
34
+ ))
35
+
36
+ fig.update_layout(
37
+ polar=dict(
38
+ radialaxis=dict(
39
+ visible=True,
40
+ range=[0, max(values)]
41
+ )),
42
+ showlegend=False,
43
+ title=f"{institution} Performance Metrics"
44
+ )
45
+
46
+ return fig
47
+
48
+ def create_bar_chart(institution):
49
+ # Get the data for the selected institution
50
+ inst_data = df[df['institution'] == institution].iloc[0]
51
+
52
+ # Prepare the data for the bar chart
53
+ categories = ['Final Score', 'Long-term Performance', 'Conviction & Strategy', 'Research Quality',
54
+ 'Influence & Governance', 'Top Holdings Performance']
55
+ values = [inst_data['final_score'],
56
+ inst_data['long_term_performance_score'],
57
+ inst_data['conviction_and_strategy_score'],
58
+ inst_data['research_quality_and_adaptability_score'],
59
+ inst_data['influence_and_governance_score'],
60
+ inst_data['top_holdings_performance_score']]
61
+
62
+ # Create the bar chart
63
+ fig = go.Figure(go.Bar(
64
+ x=categories,
65
+ y=values,
66
+ text=values,
67
+ textposition='auto',
68
+ ))
69
+
70
+ fig.update_layout(
71
+ title=f"{institution} Scores Comparison",
72
+ xaxis_title="Metrics",
73
+ yaxis_title="Score",
74
+ yaxis=dict(range=[0, 100])
75
+ )
76
+
77
+ return fig
78
+
79
+ def update_dashboard(institution):
80
+ radar_chart = create_radar_chart(institution)
81
+ bar_chart = create_bar_chart(institution)
82
+
83
+ inst_data = df[df['institution'] == institution].iloc[0]
84
+ cik = inst_data['cik']
85
+ final_score = inst_data['final_score']
86
+
87
+ return (f"CIK: {cik}",
88
+ f"Final Score: {final_score:.2f}",
89
+ radar_chart,
90
+ bar_chart)
91
+
92
+ # Create the Gradio interface
93
+ iface = gr.Interface(
94
+ fn=update_dashboard,
95
+ inputs=gr.Dropdown(choices=sorted(df['institution'].unique()), label="Select an Institution"),
96
+ outputs=[
97
+ gr.Textbox(label="CIK"),
98
+ gr.Textbox(label="Final Score"),
99
+ gr.Plot(label="Performance Metrics Radar Chart"),
100
+ gr.Plot(label="Scores Comparison Bar Chart")
101
+ ],
102
+ title="Institution Performance Dashboard",
103
+ description="Select an institution to view its performance metrics and scores."
104
+ )
105
+
106
+ # For Hugging Face Spaces deployment
107
+ iface.launch()