Spaces:
Runtime error
Runtime error
File size: 2,059 Bytes
a85a5e9 5368a96 a85a5e9 91f4a96 a85a5e9 91f4a96 a85a5e9 91f4a96 a85a5e9 ab8868f a85a5e9 91f4a96 5368a96 ab8868f 5368a96 91f4a96 ab8868f 91f4a96 ab8868f 91f4a96 ab8868f a85a5e9 91f4a96 ab8868f |
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 |
import gradio as gr
import pandas as pd
# Initialize total counts
total_yes_count = 0
total_count = 0
def calculate_percentage(*answers):
"""
Calculate the percentage of 'yes' answers.
:param answers: Iterable containing the answers.
:returns: Percentage of 'yes' answers.
"""
global total_yes_count, total_count
yes_count = sum(answers)
total_yes_count += yes_count
total_count += len(answers)
percentage = yes_count / len(answers) * 100
return f"{percentage}%"
def calculate_overall_percentage():
"""
Calculate the overall percentage of 'yes' answers.
:returns: Overall percentage of 'yes' answers.
"""
global total_yes_count, total_count
if total_count != 100:
return "Make sure you have submitted your answers in all the tabs."
overall_percentage = total_yes_count
return f"{overall_percentage}%"
# Load data
df = pd.read_csv("fmti_indicators.csv")
grouped = df.groupby(["Category", "Subcategory"])
# Create an interface per group of indicators
interfaces = []
tab_names = []
for (category, subcategory), group in grouped:
questions = group["Definition"].tolist()
inputs = [gr.Checkbox(label=question) for question in questions]
output = gr.Textbox(label="Subcategory Percentage")
iface = gr.Interface(
fn=calculate_percentage,
inputs=inputs,
outputs=output,
title=f"{category} - {subcategory}",
allow_flagging="never",
)
interfaces.append(iface)
tab_names.append(subcategory)
# Add overall percentage button
overall_button = gr.Interface(
fn=calculate_overall_percentage,
inputs=[],
outputs=gr.Textbox(label="Overall Percentage"),
title="Transparency Score",
allow_flagging="never",
)
interfaces.append(overall_button)
tab_names.append("Total Transparency Score")
# Create the tabbed interface
tabbed_interface = gr.TabbedInterface(
interface_list=interfaces,
tab_names=tab_names,
title="The Foundation Model Transparency Index",
)
tabbed_interface.launch()
|