Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import yfinance as yf
|
3 |
import pandas as pd
|
4 |
-
import random
|
5 |
|
6 |
# Mapping company names to their ticker symbols
|
7 |
company_dict = {
|
@@ -34,12 +33,16 @@ def fetch_esg_data(company_name):
|
|
34 |
"Score": esg_scores.squeeze().values
|
35 |
})
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
else:
|
39 |
-
# Return an empty DataFrame if no data is available
|
40 |
-
return pd.DataFrame()
|
41 |
|
42 |
-
# Gradio interface with a dropdown for company selection
|
43 |
def app_interface():
|
44 |
with gr.Blocks() as app:
|
45 |
# Dropdown to select company name
|
@@ -51,10 +54,16 @@ def app_interface():
|
|
51 |
# LinePlot component for displaying the ESG data
|
52 |
plot_output = gr.LinePlot(label="ESG Scores Plot", x="ESG Category", y="Score", overlay_point=True)
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
# Define the action when the "Generate ESG Plot" button is clicked
|
55 |
plot_button.click(fn=fetch_esg_data,
|
56 |
inputs=company,
|
57 |
-
outputs=plot_output)
|
58 |
|
59 |
return app
|
60 |
|
|
|
1 |
import gradio as gr
|
2 |
import yfinance as yf
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
# Mapping company names to their ticker symbols
|
6 |
company_dict = {
|
|
|
33 |
"Score": esg_scores.squeeze().values
|
34 |
})
|
35 |
|
36 |
+
# Save the ESG data to a CSV file
|
37 |
+
csv_filename = f"{ticker}_esg_data.csv"
|
38 |
+
esg_df.to_csv(csv_filename)
|
39 |
+
|
40 |
+
return plot_df, csv_filename # Return the plot DataFrame and the CSV filename
|
41 |
else:
|
42 |
+
# Return an empty DataFrame and None if no data is available
|
43 |
+
return pd.DataFrame(), None
|
44 |
|
45 |
+
# Gradio interface with a dropdown for company selection, line plot visualization, and CSV download
|
46 |
def app_interface():
|
47 |
with gr.Blocks() as app:
|
48 |
# Dropdown to select company name
|
|
|
54 |
# LinePlot component for displaying the ESG data
|
55 |
plot_output = gr.LinePlot(label="ESG Scores Plot", x="ESG Category", y="Score", overlay_point=True)
|
56 |
|
57 |
+
# Textbox to display messages
|
58 |
+
message = gr.Textbox(label="Message", interactive=False)
|
59 |
+
|
60 |
+
# File output for CSV download
|
61 |
+
csv_output = gr.File(label="Download CSV")
|
62 |
+
|
63 |
# Define the action when the "Generate ESG Plot" button is clicked
|
64 |
plot_button.click(fn=fetch_esg_data,
|
65 |
inputs=company,
|
66 |
+
outputs=[plot_output, csv_output])
|
67 |
|
68 |
return app
|
69 |
|