Spaces:
Runtime error
Runtime error
import gradio as gr | |
from css import custom_css | |
import pandas as pd | |
from gradio_modal import Modal | |
import os | |
import yaml | |
folder_path = 'configs' | |
# List to store data from YAML files | |
data_list = [] | |
metadata_dict = {} | |
# Iterate over each file in the folder | |
for filename in os.listdir(folder_path): | |
if filename.endswith('.yaml'): | |
# Read YAML file | |
file_path = os.path.join(folder_path, filename) | |
with open(file_path, 'r') as yamlfile: | |
yaml_data = yaml.safe_load(yamlfile) | |
# Append YAML data to list | |
data_list.append(yaml_data) | |
metadata_dict['<u>'+yaml_data['Link']+'</u>'] = yaml_data | |
globaldf = pd.DataFrame(data_list) | |
globaldf['Link'] = '<u>'+globaldf['Link']+'</u>' | |
# Define the desired order of categories | |
modality_order = ["Text", "Image", "Audio", "Video"] | |
type_order = ["Model", "Dataset", "Output", "Taxonomy"] | |
# Convert Modality and Type columns to categorical with specified order | |
globaldf['Modality'] = pd.Categorical(globaldf['Modality'], categories=modality_order, ordered=True) | |
globaldf['Type'] = pd.Categorical(globaldf['Type'], categories=type_order, ordered=True) | |
# Sort DataFrame by Modality and Type | |
globaldf.sort_values(by=['Modality', 'Type'], inplace=True) | |
# create a gradio page with tabs and accordions | |
# Path: taxonomy.py | |
def filter_modality(filteredtable, modality_filter): | |
filteredtable = filteredtable[filteredtable['Modality'].isin(modality_filter)] | |
return filteredtable | |
def filter_type(filteredtable, modality_filter): | |
filteredtable = filteredtable[filteredtable['Type'].isin(modality_filter)] | |
return filteredtable | |
def showmodal(evt: gr.SelectData): | |
print(evt.value, evt.index, evt.target) | |
modal = Modal(visible=False) | |
titlemd = gr.Markdown("",visible=False) | |
authormd = gr.Markdown("",visible=False) | |
tagsmd = gr.Markdown("",visible=False) | |
abstractmd = gr.Markdown("",visible=False) | |
gallery = gr.Gallery([],visible=False) | |
if evt.index[1] == 5: | |
modal = Modal(visible=True) | |
itemdic = metadata_dict[evt.value] | |
tags = itemdic['Hashtags'] | |
if isinstance(tags, list): | |
if len(tags) > 0: | |
tagstr = ''.join(['<span class="tag">#'+tag+'</span> ' for tag in tags]) | |
tagsmd = gr.Markdown(tagstr, visible=True) | |
titlemd = gr.Markdown('# ['+itemdic['Link']+']('+itemdic['URL']+')',visible=True) | |
if pd.notnull(itemdic['Authors']): | |
authormd = gr.Markdown('## '+itemdic['Authors'],visible=True) | |
if pd.notnull(itemdic['Abstract']): | |
abstractmd = gr.Markdown(itemdic['Abstract'],visible=True) | |
screenshots = itemdic['Screenshots'] | |
if isinstance(screenshots, list): | |
if len(screenshots) > 0: | |
gallery = gr.Gallery(screenshots, visible=True) | |
return [modal, titlemd, authormd, tagsmd, abstractmd, gallery] | |
with gr.Blocks(title = "Social Impact Measurement V2", css=custom_css) as demo: #theme=gr.themes.Soft(), | |
# create tabs for the app, moving the current table to one titled "rewardbench" and the benchmark_text to a tab called "About" | |
with gr.Row(): | |
gr.Markdown(""" | |
# Social Impact Measurement | |
## A taxonomy of the social impacts of AI models and measurement techniques. | |
""") | |
with gr.Row(): | |
gr.Markdown(""" | |
#### Technical Base System Evaluations: | |
Below we list the aspects possible to evaluate in a generative system. Context-absent evaluations only provide narrow insights into the described aspects of the type of generative AI system. The depth of literature and research on evaluations differ by modality with some modalities having sparse or no relevant literature, but the themes for evaluations can be applied to most systems. | |
The following categories are high-level, non-exhaustive, and present a synthesis of the findings across different modalities. They refer solely to what can be evaluated in a base technical system: | |
""") | |
with gr.Tabs(elem_classes="tab-buttons") as tabs1: | |
with gr.TabItem("Bias/Stereotypes"): | |
fulltable = globaldf[globaldf['Group'] == 'BiasEvals'] | |
fulltable = fulltable[['Modality','Type', 'Suggested Evaluation', 'What it is evaluating', 'Considerations', 'Link']] | |
gr.Markdown(""" | |
Generative AI systems can perpetuate harmful biases from various sources, including systemic, human, and statistical biases. These biases, also known as "fairness" considerations, can manifest in the final system due to choices made throughout the development process. They include harmful associations and stereotypes related to protected classes, such as race, gender, and sexuality. Evaluating biases involves assessing correlations, co-occurrences, sentiment, and toxicity across different modalities, both within the model itself and in the outputs of downstream tasks. | |
""") | |
with gr.Row(): | |
modality_filter = gr.CheckboxGroup(["Text", "Image", "Audio", "Video"], | |
value=["Text", "Image", "Audio", "Video"], | |
label="Modality", | |
show_label=True, | |
# info="Which modality to show." | |
) | |
type_filter = gr.CheckboxGroup(["Model", "Dataset", "Output", "Taxonomy"], | |
value=["Model", "Dataset", "Output", "Taxonomy"], | |
label="Type", | |
show_label=True, | |
# info="Which modality to show." | |
) | |
with gr.Row(): | |
biastable_full = gr.DataFrame(value=fulltable, wrap=True, datatype="markdown", visible=False, interactive=False) | |
biastable_filtered = gr.DataFrame(value=fulltable, wrap=True, datatype="markdown", visible=True, interactive=False) | |
modality_filter.change(filter_modality, inputs=[biastable_filtered, modality_filter], outputs=biastable_filtered) | |
type_filter.change(filter_type, inputs=[biastable_filtered, type_filter], outputs=biastable_filtered) | |
with Modal(visible=False) as modal: | |
titlemd = gr.Markdown(visible=False) | |
authormd = gr.Markdown(visible=False) | |
tagsmd = gr.Markdown(visible=False) | |
abstractmd = gr.Markdown(visible=False) | |
gallery = gr.Gallery(visible=False) | |
biastable_filtered.select(showmodal, None, [modal, titlemd, authormd, tagsmd, abstractmd, gallery]) | |
with gr.TabItem("Cultural Values/Sensitive Content"): | |
with gr.Row(): | |
gr.Image() | |
# with gr.TabItem("Disparate Performance"): | |
# with gr.Row(): | |
# gr.Image() | |
with gr.TabItem("Privacy/Data Protection"): | |
with gr.Row(): | |
gr.Image() | |
# with gr.TabItem("Financial Costs"): | |
# with gr.Row(): | |
# gr.Image() | |
with gr.TabItem("Environmental Costs"): | |
with gr.Row(): | |
gr.Image() | |
# with gr.TabItem("Data and Content Moderation Labor"): | |
# with gr.Row(): | |
# gr.Image() | |
# with gr.Row(): | |
# gr.Markdown(""" | |
# #### B: People and Society Impact Evaluations: | |
# Long-term effects of systems embedded in society, such as economic or labor impact, largely require ideation of generative AI systems’ possible use cases and have fewer available general evaluations. The following categories heavily depend on how generative AI systems are deployed, including sector and application. In the broader ecosystem, methods of deployment affect social impact. | |
# The following categories are high-level, non-exhaustive, and present a synthesis of the findings across different modalities. They refer solely to what can be evaluated in people and society: | |
# """) | |
# with gr.Tabs(elem_classes="tab-buttons") as tabs2: | |
# with gr.TabItem("Trustworthiness and Autonomy"): | |
# with gr.Accordion("Trust in Media and Information", open=False): | |
# gr.Image() | |
# with gr.Accordion("Overreliance on Outputs", open=False): | |
# gr.Image() | |
# with gr.Accordion("Personal Privacy and Sense of Self", open=False): | |
# gr.Image() | |
# with gr.TabItem("Inequality, Marginalization, and Violence"): | |
# with gr.Accordion("Community Erasure", open=False): | |
# gr.Image() | |
# with gr.Accordion("Long-term Amplifying Marginalization by Exclusion (and Inclusion)", open=False): | |
# gr.Image() | |
# with gr.Accordion("Abusive or Violent Content", open=False): | |
# gr.Image() | |
# with gr.TabItem("Concentration of Authority"): | |
# with gr.Accordion("Militarization, Surveillance, and Weaponization", open=False): | |
# gr.Image() | |
# with gr.Accordion("Imposing Norms and Values", open=False): | |
# gr.Image() | |
# with gr.TabItem("Labor and Creativity"): | |
# with gr.Accordion("Intellectual Property and Ownership", open=False): | |
# gr.Image() | |
# with gr.Accordion("Economy and Labor Market", open=False): | |
# gr.Image() | |
# with gr.TabItem("Ecosystem and Environment"): | |
# with gr.Accordion("Widening Resource Gaps", open=False): | |
# gr.Image() | |
# with gr.Accordion("Environmental Impacts", open=False): | |
# gr.Image() | |
with gr.Row(): | |
with gr.Accordion("📚 Citation", open=False): | |
citation_button = gr.Textbox( | |
value=r"""BOOK CHAPTER CITE GOES HERE""", | |
lines=7, | |
label="Copy the following to cite this work.", | |
elem_id="citation-button", | |
show_copy_button=True, | |
) | |
demo.launch(debug=True) |