{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import streamlit as st\n", "\n", "from streamlit_jupyter import StreamlitPatcher, tqdm\n", "\n", "StreamlitPatcher().jupyter() # register streamlit with jupyter-compatible wrappers" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/markdown": [ "# AI" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "2024-08-13 14:11:32.399 \n", " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n", " command:\n", "\n", " streamlit run /mnt/wsl/PHYSICALDRIVE1p1/@home/non/.venv/lib/python3.10/site-packages/ipykernel_launcher.py [ARGUMENTS]\n" ] } ], "source": [ "import yaml\n", "from pathlib import Path\n", "from compliance_analysis import run_compliance_analysis_on_project, run_compliance_analysis_on_data, run_compliance_analysis_on_model\n", "\n", "# def process_files(files):\n", "# results = []\n", "# for file in files:\n", "# with open(file.name, 'r') as f:\n", "# content = f.read()\n", "# if Path(file.name).name == \"project_cc.yaml\":\n", "# project_cc_yaml = yaml.safe_load(content)\n", "# msg = run_compliance_analysis_on_project(project_cc_yaml)\n", "# results.append(msg) \n", "# # if Path(file.name).name == \"data_cc.yaml\":\n", "# # data_cc_yaml = yaml.safe_load(content)\n", "# # msg = run_compliance_analysis_on_data(data_cc_yaml)\n", "# # results.append(msg) \n", "# # if Path(file.name).name == \"model_cc.yaml\":\n", "# # model_cc_yaml = yaml.safe_load(content)\n", "# # msg = run_compliance_analysis_on_model(model_cc_yaml)\n", "# # results.append(msg)\n", " \n", "# return results\n", "\n", "import yaml\n", "from pathlib import Path\n", "import pandas as pd\n", "\n", "\n", "def process_files(files):\n", " results = []\n", " for file in files:\n", " content = file.read().decode(\"utf-8\")\n", " if Path(file.name).name == \"project_cc.yaml\":\n", " project_cc_yaml = yaml.safe_load(content)\n", " if project_cc_yaml:\n", " msg = run_compliance_analysis_on_project(project_cc_yaml)\n", " results.append(msg) \n", " return results\n", "\n", "def extract_properties(files):\n", " properties = []\n", " for file in files:\n", " content = file.read().decode(\"utf-8\")\n", " project_cc_yaml = yaml.safe_load(content)\n", " if project_cc_yaml:\n", " properties.extend([key for key in project_cc_yaml])\n", " return properties\n", "\n", "def sentence_builder(keys):\n", " return f\"Selected options: {', '.join(keys)}\"\n", "\n", "# Streamlit app\n", "st.title(\"AI\")\n", "\n", "uploaded_files = st.file_uploader(\"Upload YAML Files\", type=\"yaml\", accept_multiple_files=True)\n", "\n", "if uploaded_files:\n", " # Process the files and display the output\n", " if st.button(\"Process Files\"):\n", " results = process_files(uploaded_files)\n", " for result in results:\n", " st.text(result)\n", " \n", " # Extract properties\n", " properties = extract_properties(uploaded_files)\n", " \n", " # Create a DataFrame with properties and a checkbox column\n", " df = pd.DataFrame({\n", " \"Property\": properties,\n", " \"Select\": [False] * len(properties) # Default to unchecked\n", " })\n", "\n", " # Display DataFrame with checkboxes using st.column_config.CheckboxColumn\n", " edited_df = st.data_editor(\n", " df,\n", " column_config={\n", " \"Select\": st.column_config.CheckboxColumn(\"Select\"),\n", " },\n", " key=\"data_editor\"\n", " )\n", "\n", " # Get selected properties\n", " selected_properties = edited_df[edited_df[\"Select\"]][\"Property\"].tolist()\n", " \n", " # Build the sentence based on selected properties\n", " if selected_properties:\n", " sentence = sentence_builder(selected_properties)\n", " st.text(sentence)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }