Manasa1 commited on
Commit
51a15a5
·
verified ·
1 Parent(s): 2de254e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -27
app.py CHANGED
@@ -20,12 +20,12 @@ def fetch_esg_data(company_name):
20
  if esg_data is not None and not esg_data.empty:
21
  esg_df = pd.DataFrame(esg_data)
22
  esg_scores = esg_df.loc[["environmentScore", "socialScore", "governanceScore"], :].dropna().astype(float)
23
-
24
  plot_df = pd.DataFrame({
25
  "ESG Category": ["Environment", "Social", "Governance"],
26
  "Score": esg_scores.squeeze().values
27
  })
28
-
29
  # Save the ESG data to a CSV file
30
  csv_filename = f"{ticker}_esg_data.csv"
31
  esg_df.to_csv(csv_filename)
@@ -34,37 +34,50 @@ def fetch_esg_data(company_name):
34
  else:
35
  return pd.DataFrame(), None
36
 
37
- # Gradio interface
38
  def app_interface():
39
  with gr.Blocks() as app:
40
- # Dropdown to select company name
41
- company = gr.Dropdown(
42
- label="Select Company",
43
- choices=list(company_dict.keys()),
44
- value="Apple", # Default value
45
- interactive=True # Make it interactive
46
- )
47
-
48
- # Button to fetch and plot ESG data
49
- plot_button = gr.Button("Generate ESG Plot")
50
-
51
- # LinePlot component for displaying the ESG data
52
- line_plot = gr.LinePlot(label="ESG Scores Line Plot", x="ESG Category", y="Score", overlay_point=True)
53
-
54
- # ScatterPlot component for displaying the ESG data
55
- scatter_plot = gr.ScatterPlot(label="ESG Scores Scatter Plot", x="ESG Category", y="Score", overlay_point=True)
56
-
57
- # File output for CSV download
58
- csv_output = gr.File(label="Download CSV")
59
-
60
- # Define the action when the "Generate ESG Plot" button is clicked
61
- plot_button.click(fn=fetch_esg_data, inputs=company, outputs=[line_plot, csv_output, scatter_plot])
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  return app
64
 
65
  # Launch the Gradio app
66
  app = app_interface()
67
- app.launch()
68
-
69
 
70
 
 
20
  if esg_data is not None and not esg_data.empty:
21
  esg_df = pd.DataFrame(esg_data)
22
  esg_scores = esg_df.loc[["environmentScore", "socialScore", "governanceScore"], :].dropna().astype(float)
23
+
24
  plot_df = pd.DataFrame({
25
  "ESG Category": ["Environment", "Social", "Governance"],
26
  "Score": esg_scores.squeeze().values
27
  })
28
+
29
  # Save the ESG data to a CSV file
30
  csv_filename = f"{ticker}_esg_data.csv"
31
  esg_df.to_csv(csv_filename)
 
34
  else:
35
  return pd.DataFrame(), None
36
 
37
+ # Gradio interface with multiple tabs
38
  def app_interface():
39
  with gr.Blocks() as app:
40
+ gr.Markdown("# ESG Data Explorer")
41
+
42
+ with gr.Tab("ESG Data"):
43
+ # Dropdown to select company name
44
+ company = gr.Dropdown(
45
+ label="Select Company",
46
+ choices=list(company_dict.keys()),
47
+ value="Apple", # Default value
48
+ interactive=True # Make it interactive
49
+ )
50
+
51
+ # Button to fetch and plot ESG data
52
+ plot_button = gr.Button("Generate ESG Plot")
53
+
54
+ # Dataframe for ESG scores
55
+ line_plot = gr.LinePlot(label="ESG Scores Line Plot", x="ESG Category", y="Score", overlay_point=True)
56
+ scatter_plot = gr.ScatterPlot(label="ESG Scores Scatter Plot", x="ESG Category", y="Score", overlay_point=True)
57
+
58
+ # File output for CSV download
59
+ csv_output = gr.File(label="Download CSV")
60
+
61
+ # Define the action when the "Generate ESG Plot" button is clicked
62
+ plot_button.click(fn=fetch_esg_data, inputs=company, outputs=[line_plot, csv_output, scatter_plot])
63
+
64
+ with gr.Tab("Tab 2"):
65
+ gr.Markdown("Content for Tab 2 goes here.")
66
+ # Add more components relevant to Tab 2
67
+
68
+ with gr.Tab("Tab 3"):
69
+ gr.Markdown("Content for Tab 3 goes here.")
70
+ # Add more components relevant to Tab 3
71
+
72
+ with gr.Tab("Tab 4"):
73
+ gr.Markdown("Content for Tab 4 goes here.")
74
+ # Add more components relevant to Tab 4
75
 
76
  return app
77
 
78
  # Launch the Gradio app
79
  app = app_interface()
80
+ if __name__ == "__main__":
81
+ app.launch()
82
 
83