Manasa1 commited on
Commit
2086e56
·
verified ·
1 Parent(s): 8a5978d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -2
app.py CHANGED
@@ -1,5 +1,52 @@
1
  import gradio as gr
2
  my_theme = gr.Theme.from_hub("gradio/seafoam")
3
 
4
- with gr.Blocks(theme=my_theme) as demo:
5
- print("theme")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  my_theme = gr.Theme.from_hub("gradio/seafoam")
3
 
4
+ import gradio as gr
5
+ import yfinance as yf
6
+ import pandas as pd
7
+
8
+ # Function to fetch ESG data and save it to a CSV file
9
+ def fetch_and_save_esg_data(ticker):
10
+ # Fetch ESG data from Yahoo Finance
11
+ stock = yf.Ticker(ticker)
12
+ esg_data = stock.sustainability
13
+
14
+ # If the data is available, save it to a CSV file
15
+ if esg_data is not None:
16
+ # Convert the ESG data to a pandas DataFrame
17
+ esg_df = pd.DataFrame(esg_data)
18
+
19
+ # Save it to a CSV file
20
+ filename = f"{ticker}_esg_data.csv"
21
+ esg_df.to_csv(filename)
22
+
23
+ return f"ESG data for {ticker} saved to {filename}", filename
24
+ else:
25
+ return f"No ESG data available for {ticker}", None
26
+
27
+ # List of companies (tickers) for dropdown selection
28
+ company_list = ["AAPL", "GOOGL", "MSFT", "AMZN", "TSLA"]
29
+
30
+ # Gradio interface with a dropdown for company selection
31
+ def app_interface():
32
+ with gr.Blocks() as app:
33
+ # Dropdown to select company ticker
34
+ company = gr.Dropdown(label="Select Company", choices=company_list, value="AAPL")
35
+
36
+ # Button to trigger ESG data extraction
37
+ fetch_button = gr.Button("Fetch ESG Data")
38
+
39
+ # Output text and download link
40
+ output_text = gr.Textbox(label="Output")
41
+ download_link = gr.File(label="Download CSV")
42
+
43
+ # Define the action when the button is clicked
44
+ fetch_button.click(fn=fetch_and_save_esg_data,
45
+ inputs=company,
46
+ outputs=[output_text, download_link])
47
+
48
+ return app
49
+
50
+ # Launch the Gradio app
51
+ app = app_interface()
52
+ app.launch()