esg_scraper / app.py
kkawamu1's picture
Add application file
8ee5083
raw
history blame
2.39 kB
import pandas as pd
import gradio as gr
import gradio as gr; print(gr.__version__)
# Replace with path to your ESG data (CSV or other supported format)
data_path = "ESG_data.csv"
company_ratings = [
{"Company Name": "Apple Inc.", "Rating": 4.5},
{"Company Name": "Amazon.com, Inc.", "Rating": 4.2},
{"Company Name": "Microsoft Corporation", "Rating": 4.7},
{"Company Name": "Alphabet Inc. (Google)", "Rating": 4.8},
{"Company Name": "Tesla, Inc.", "Rating": 3.9},
{"Company Name": "Meta Platforms Inc. (Facebook)", "Rating": 3.1},
]
# Load ESG data
esg_data = pd.DataFrame(company_ratings)
import gradio as gr
import pandas as pd
inputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(4,"dynamic"), label="Input Data", interactive=1)]
outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(1, "fixed"), label="Predictions", headers=["Failures"])]
def infer(input_dataframe):
return pd.DataFrame(input_dataframe)
gr.Interface(fn = infer, inputs = inputs, outputs = outputs, examples = [[esg_data.head(2)]]).launch()
# def get_esg_scores(ticker):
# """
# Finds ESG scores for a given ticker symbol in the loaded data.
# Args:
# ticker (str): Ticker symbol of the company.
# Returns:
# pandas.DataFrame: Subset of ESG data for the ticker,
# containing ESG scores if found, or an empty DataFrame
# if not found.
# """
# filtered_data = esg_data[esg_data["Ticker Symbol"] == ticker.upper()]
# return filtered_data if not filtered_data.empty else pd.DataFrame()
# def display_esg_scores(dataframe):
# """
# Displays ESG scores in a table format if a DataFrame is provided,
# otherwise displays a message indicating no data found.
# Args:
# dataframe (pandas.DataFrame): DataFrame containing ESG scores.
# """
# if dataframe.empty:
# return "No ESG data found for this ticker."
# else:
# # Select relevant ESG score columns (adjust based on your data)
# esg_scores = dataframe[["Ticker Symbol", "Governance Score", "Social Score", "Environmental Score"]]
# return gr.DataTable(dataframe=esg_scores.to_dict())
# iface = gr.Interface(
# fn=get_esg_scores,
# inputs=gr.inputs.Textbox(label="Ticker Symbol"),
# outputs=esg_data,
# title="ESG Score Lookup",
# description="Enter a company ticker symbol to view its ESG scores (if available).",
# )
# iface.launch()