File size: 2,393 Bytes
8ee5083
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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()