Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -61,7 +61,7 @@ def create_3d_correlation_matrix(df):
|
|
61 |
xaxis=dict(title='Variables'),
|
62 |
yaxis=dict(title='Variables'),
|
63 |
zaxis=dict(title='Correlation')))
|
64 |
-
return fig
|
65 |
|
66 |
# Gradio function
|
67 |
def visualize_correlation(selected_series):
|
@@ -69,29 +69,40 @@ def visualize_correlation(selected_series):
|
|
69 |
series_ids = [series for series in series_options if series_options[series] in selected_series]
|
70 |
|
71 |
if not series_ids:
|
72 |
-
return "
|
73 |
|
74 |
# Fetch and process data
|
75 |
df = fetch_fred_data(series_ids)
|
76 |
if df.empty:
|
77 |
-
return "
|
78 |
|
79 |
standardized_df = standardize_data(df)
|
80 |
-
|
81 |
-
return
|
82 |
|
83 |
-
# Gradio Interface
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
# Launch the app
|
97 |
-
|
|
|
61 |
xaxis=dict(title='Variables'),
|
62 |
yaxis=dict(title='Variables'),
|
63 |
zaxis=dict(title='Correlation')))
|
64 |
+
return fig
|
65 |
|
66 |
# Gradio function
|
67 |
def visualize_correlation(selected_series):
|
|
|
69 |
series_ids = [series for series in series_options if series_options[series] in selected_series]
|
70 |
|
71 |
if not series_ids:
|
72 |
+
return None, "Please select at least one indicator."
|
73 |
|
74 |
# Fetch and process data
|
75 |
df = fetch_fred_data(series_ids)
|
76 |
if df.empty:
|
77 |
+
return None, "Failed to fetch data for the selected indicators."
|
78 |
|
79 |
standardized_df = standardize_data(df)
|
80 |
+
plot = create_3d_correlation_matrix(standardized_df)
|
81 |
+
return plot, None
|
82 |
|
83 |
+
# Gradio Blocks Interface
|
84 |
+
with gr.Blocks() as demo:
|
85 |
+
gr.Markdown("# 3D Correlation Matrix Visualization with FRED Data")
|
86 |
+
|
87 |
+
with gr.Row():
|
88 |
+
with gr.Column():
|
89 |
+
series_selector = gr.CheckboxGroup(
|
90 |
+
choices=list(series_options.values()),
|
91 |
+
label="Select Economic Indicators",
|
92 |
+
info="Choose one or more indicators to include in the correlation matrix.",
|
93 |
+
)
|
94 |
+
submit_button = gr.Button("Generate Matrix")
|
95 |
+
|
96 |
+
with gr.Column():
|
97 |
+
plot_output = gr.Plot(label="3D Correlation Matrix")
|
98 |
+
error_message = gr.Markdown("", visible=False)
|
99 |
+
|
100 |
+
# Event handler
|
101 |
+
submit_button.click(
|
102 |
+
fn=visualize_correlation,
|
103 |
+
inputs=[series_selector],
|
104 |
+
outputs=[plot_output, error_message],
|
105 |
+
)
|
106 |
|
107 |
# Launch the app
|
108 |
+
demo.launch(debug=True)
|