Spaces:
Sleeping
Sleeping
File size: 6,141 Bytes
bcfaedb | 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | import gradio as gr
from ui.state import STATE
#Filter SDG
SDG_IMAGE_DIR = "assets/sdg_icons"
sdg_icons = {
i: f"{SDG_IMAGE_DIR}/E_PRINT_{i:02d}.jpg"
for i in range(1, 18)
}
sdg_images = [sdg_icons[i] for i in range(1, 18)]
def filter_sdg(evt: gr.SelectData):
df = STATE.get("df")
sdg_num = evt.index + 1
pattern = f"SDG_{sdg_num}:"
filtered = df[df["17 SDG Alignment"].astype(str).str.contains(pattern, na=False)]
title = f"Showing results for SDG {sdg_num}"
return filtered, title
#Filter GRI
GRI_IMAGE_DIR = "assets/gri_icons"
gri_topics = ["General", "Economic", "Environmental", "Social"]
gri_images = [
f"{GRI_IMAGE_DIR}/General.PNG",
f"{GRI_IMAGE_DIR}/Economic.PNG",
f"{GRI_IMAGE_DIR}/Environmental.PNG",
f"{GRI_IMAGE_DIR}/Social.PNG"
]
def filter_gri(evt: gr.SelectData):
df = STATE.get("df")
selected_idx = evt.index
topic = gri_topics[selected_idx] # Social / Economic / ...
filtered = df[df["GRI Topic Alignment"].astype(str) == topic]
title = f"Showing results for GRI Topic: {topic}"
return filtered, title
# TOGGLE FILTERS
def toggle_filters(tasks):
if tasks is None:
tasks = []
if isinstance(tasks, str):
tasks = [tasks]
show_sdg = "17 SDG Alignment" in tasks
show_gri = "GRI Topic Alignment" in tasks
return (
gr.update(visible=show_sdg),
gr.update(visible=show_gri)
)
# Filter QUALITY Disclosure
QUALITY_IMAGE_DIR = "assets/quality_icons"
quality_icons = {
"Informative": f"{QUALITY_IMAGE_DIR}/Informative.PNG",
"Non-informative/Vague": f"{QUALITY_IMAGE_DIR}/Vague.PNG",
"Qualitative": f"{QUALITY_IMAGE_DIR}/Qul.PNG",
"Quantitative": f"{QUALITY_IMAGE_DIR}/Qun.PNG",
"High Potential Greenwashing": f"{QUALITY_IMAGE_DIR}/HPG.PNG",
"Low Potential Greenwashing": f"{QUALITY_IMAGE_DIR}/LPG.PNG"
}
quality_task_1_gallery = [quality_icons["Informative"], quality_icons["Non-informative/Vague"]]
quality_task_2_gallery = [quality_icons["Qualitative"], quality_icons["Quantitative"]]
quality_task_3_gallery = [quality_icons["High Potential Greenwashing"], quality_icons["Low Potential Greenwashing"]]
def filter_quality_1(evt: gr.SelectData):
df = STATE.get("df")
label = "Informative" if evt.index == 0 else "Non-informative/Vague"
filtered = df[df["Informative & Non-Informative/Vague Sustainability Text Identification"].astype(str) == label]
title = f"Showing results: {label}"
return filtered, title
def filter_quality_2(evt: gr.SelectData):
df = STATE.get("df")
label = "Qualitative" if evt.index == 0 else "Quantitative"
filtered = df[df["Qualitative & Quantitative Sustainability Text Identification"].astype(str) == label]
title = f"Showing results: {label}"
return filtered, title
def filter_quality_3(evt: gr.SelectData):
df = STATE.get("df")
label = "High Potential Greenwashing" if evt.index == 0 else "Low Potential Greenwashing"
filtered = df[df["High Potential Greenwashing Detection"].astype(str) == label]
title = f"Showing results: {label}"
return filtered, title
# TOGGLE FILTERS
def toggle_quality_filters(tasks):
if tasks is None:
tasks = []
if isinstance(tasks, str):
tasks = [tasks]
show_info = (
"Informative & Non-Informative/Vague Sustainability Text Identification"
in tasks
)
show_qq = (
"Qualitative & Quantitative Sustainability Text Identification"
in tasks
)
show_gw = (
"High Potential Greenwashing Detection"
in tasks
)
return (
gr.update(visible=show_info),
gr.update(visible=show_qq),
gr.update(visible=show_gw)
)
# Filter Climate
CLIMATE_DIR = "assets/climate_icons"
climate_icons = {
"Climate": f"{CLIMATE_DIR}/C.PNG",
"Non-Climate": f"{CLIMATE_DIR}/NC.PNG"
}
gri_climate_icons = {
"GRI 101": f"{CLIMATE_DIR}/GRI101.PNG",
"GRI 2": f"{CLIMATE_DIR}/GRI102.PNG",
"GRI 201": f"{CLIMATE_DIR}/GRI201.PNG",
"GRI 302": f"{CLIMATE_DIR}/GRI302.PNG",
"GRI 303": f"{CLIMATE_DIR}/GRI303.PNG",
"GRI 305": f"{CLIMATE_DIR}/GRI305.PNG",
"GRI 306": f"{CLIMATE_DIR}/GRI306.PNG",
}
sdg13_icons = {
"Climate Action (SDG13)": f"{CLIMATE_DIR}/CA.PNG",
"Non-Climate Action": f"{CLIMATE_DIR}/NCA.PNG"
}
gri_sdg13_icons = {
"Economical Aspect (GRI 201)": f"{CLIMATE_DIR}/EcCA.PNG",
"Environmental Aspect (GRI 305)": f"{CLIMATE_DIR}/EnCA.PNG",
"General Aspect (GRI 2)": f"{CLIMATE_DIR}/GCA.PNG"
}
climate_images = list(climate_icons.values())
gri_climate_images = list(gri_climate_icons.values())
sdg13_images = list(sdg13_icons.values())
gri_sdg13_images = list(gri_sdg13_icons.values())
def filter_climate(evt: gr.SelectData):
df = STATE.get("df")
label = list(climate_icons.keys())[evt.index]
filtered = df[df["Climate Alignment"].astype(str) == label]
return filtered, f"Showing: {label}"
def filter_gri_climate(evt: gr.SelectData):
df = STATE.get("df")
label = list(gri_climate_icons.keys())[evt.index]
filtered = df[df["GRI Climate Alignment"].astype(str) == label]
return filtered, f"Showing: {label}"
def filter_sdg13(evt: gr.SelectData):
df = STATE.get("df")
label = list(sdg13_icons.keys())[evt.index]
filtered = df[df["Climate Action (SDG13) Alignment"].astype(str) == label]
return filtered, f"Showing: {label}"
def filter_gri_sdg13(evt: gr.SelectData):
df = STATE.get("df")
label = list(gri_sdg13_icons.keys())[evt.index]
filtered = df[df["GRI Climate Action (SDG13) Alignment"].astype(str) == label]
return filtered, f"Showing: {label}"
# TOGGLE FILTERS
def toggle_climate(tasks):
if tasks is None:
tasks = []
if isinstance(tasks, str):
tasks = [tasks]
return (
gr.update(visible="Climate Alignment" in tasks),
gr.update(visible="GRI Climate Alignment" in tasks),
gr.update(visible="Climate Action (SDG13) Alignment" in tasks),
gr.update(visible="GRI Climate Action (SDG13) Alignment" in tasks)
)
|