File size: 5,459 Bytes
1c8fe13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "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": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "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
}