import os import gradio as gr import yaml import json from pathlib import Path from compliance_analysis import check_overall_compliance # def process_files(files): # results = [] # for file in files: # with open(file.name, 'r') as f: # content = f.read() # if Path(file.name).name == "project_cc.yaml": # project_cc_yaml = yaml.safe_load(content) # msg = run_compliance_analysis_on_project(project_cc_yaml) # results.append(msg) # # if Path(file.name).name == "data_cc.yaml": # # data_cc_yaml = yaml.safe_load(content) # # msg = run_compliance_analysis_on_data(data_cc_yaml) # # results.append(msg) # # if Path(file.name).name == "model_cc.yaml": # # model_cc_yaml = yaml.safe_load(content) # # msg = run_compliance_analysis_on_model(model_cc_yaml) # # results.append(msg) # return results # def extract_properties(files): # for file in files: # with open(file.name, 'r') as f: # content = f.read() # project_cc_yaml = yaml.safe_load(content) # project_cc = [key for key in project_cc_yaml] # return project_cc # def sentence_builder(countries): # return f"{countries}" # # # Gradio interface # with gr.Blocks() as demo: # file_input = gr.File(label="Upload Files", file_count="multiple") # output = gr.Textbox(label="Output", lines=10) # submit_button = gr.Button("Process Files") # submit_button.click(process_files, inputs=file_input, outputs=output) # # Create the CheckboxGroup (initially empty) # checkbox_group = gr.CheckboxGroup(choices=[], label="", interactive=True) # # Create the output Textbox # output = gr.Textbox() # # Function to update the CheckboxGroup when files are uploaded # def update_checkboxes(files): # choices = extract_properties(files) # return gr.CheckboxGroup(choices=choices, label="", interactive=True) # # Create a Button to trigger the sentence builder # submit_button = gr.Button("Submit") # # Set up the interaction for file input and updating checkboxes # file_input.change(update_checkboxes, inputs=file_input, outputs=checkbox_group) # gr.CheckboxGroup.change(update_checkboxes) # output = gr.Textbox() # submit_button = gr.Button("Submit") # submit_button.click(sentence_builder, inputs=checkbox_group, outputs=output) # if __name__ == "__main__": # demo.launch() import streamlit as st import yaml from pathlib import Path import pandas as pd def load_data(files): cards = [] for file in files: content = file.read().decode("utf-8") if Path(file.name).name == "project_cc.yaml": project_cc_yaml = yaml.safe_load(content) data = project_cc_yaml card_type = "project" cards.append((card_type, data)) if Path(file.name).name == "data_cc.yaml": data_cc_yaml = yaml.safe_load(content) data = data_cc_yaml card_type = "data" cards.append((card_type, data)) if Path(file.name).name == "model_cc.yaml": model_cc_yaml = yaml.safe_load(content) data = model_cc_yaml card_type = "model" cards.append((card_type, data)) return cards # def process_files(files): # results = [] # for file in files: # content = file.read().decode("utf-8") # if Path(file.name).name == "project_cc.yaml": # project_cc_yaml = yaml.safe_load(content) # if project_cc_yaml: # msg = run_compliance_analysis_on_project(project_cc_yaml) # results.append(msg) # return results # def process_files(data): # results = [] # msg = run_compliance_analysis_on_project(yaml.safe_load(data)) # results.append(msg) # return results # def extract_properties(data): # flattened_data = [] # for category, items in data.items(): # for item, attributes in items.items(): # flattened_data.append({ # "Category": category, # "Item": item, # "Verbose": attributes["verbose"], # "Value": attributes["value"] # }) # df = pd.DataFrame(flattened_data) # return df def gather_cards(files): cards = {} cards['project_file'] = '' cards['data_files'] = [] cards['model_files'] = [] for file in files: file_path = os.path.join('/tmp', file.name) with open(file_path, 'wb') as f: f.write(file.getbuffer()) with open(file_path, 'r') as file_path: content = yaml.safe_load(file_path.read()) if content['card_type'] == 'project': cards['project_file'] = file_path.name if content['card_type'] == "data": cards['data_files'].append(file_path.name) if content['card_type'] == "model": cards['model_files'].append(file_path.name) return cards def compliance_analysis(cards): results = [] dispositive_variables = check_overall_compliance(cards) results.append(dispositive_variables)#['msg']) return results # Streamlit app # st.set_page_config(page_title="AI", layout="wide") # st.markdown( # """ #