Spaces:
Paused
Paused
Improve URL input handling
#3
by
anmol11p
- opened
- src/app.py +99 -61
src/app.py
CHANGED
|
@@ -1,17 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from compliance_lib import
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
st.set_page_config(page_title="Anupalan Karta – Compliance Checker",
|
| 6 |
layout="wide")
|
| 7 |
-
|
| 8 |
-
st.
|
| 9 |
-
|
| 10 |
-
st.subheader("Unified compliance self-check Tool")
|
| 11 |
-
|
| 12 |
-
# --- introduction and how-to guide ------------------------------------------
|
| 13 |
st.markdown("""
|
| 14 |
-
## Introduction
|
| 15 |
|
| 16 |
**Anupalan Karta** (अनुपालंकर्ता) is a simple tool to help business owners, data architects, and data owners quickly check if their policies and procedures meet important regulations like GDPR, EU AI Act, and ISO 27001.
|
| 17 |
|
|
@@ -45,58 +40,101 @@ Visit [anktechsol.com](https://anktechsol.com) for professional compliance consu
|
|
| 45 |
|
| 46 |
---
|
| 47 |
""")
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
with st.sidebar:
|
| 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 |
st.markdown("---")
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
mime="text/markdown")
|
| 101 |
-
else:
|
| 102 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from compliance_lib import *
|
| 3 |
+
import PyPDF2
|
|
|
|
| 4 |
st.set_page_config(page_title="Anupalan Karta – Compliance Checker",
|
| 5 |
layout="wide")
|
| 6 |
+
st.title('🛡️ Anupalan Karta (अनुपालंकर्ता)')
|
| 7 |
+
st.subheader('Unified compliance self-check Tool')
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
st.markdown("""
|
| 9 |
+
## Introduction
|
| 10 |
|
| 11 |
**Anupalan Karta** (अनुपालंकर्ता) is a simple tool to help business owners, data architects, and data owners quickly check if their policies and procedures meet important regulations like GDPR, EU AI Act, and ISO 27001.
|
| 12 |
|
|
|
|
| 40 |
|
| 41 |
---
|
| 42 |
""")
|
| 43 |
+
|
| 44 |
+
# default state
|
| 45 |
+
if "check_run" not in st.session_state:
|
| 46 |
+
st.session_state.check_run = False
|
| 47 |
+
st.session_state.raw_text = ""
|
| 48 |
+
|
| 49 |
+
# ------ side bar ----
|
| 50 |
with st.sidebar:
|
| 51 |
+
st.subheader('📥 Input options')
|
| 52 |
+
option = st.radio('Choose data source:',['Paste text','URL of public policy','Upload file'])
|
| 53 |
+
raw_text=""
|
| 54 |
+
if(option=='Paste text'):
|
| 55 |
+
raw_text= st.text_area('Paste your policy / procedures here')
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
elif option == 'URL of public policy':
|
| 59 |
+
Url = st.text_area("Public URL (HTTPS)", key="input_text")
|
| 60 |
+
raw_text = fetchText(Url) if Url else st.warning
|
| 61 |
+
if Url:
|
| 62 |
+
raw_text, error = fetchText(Url)
|
| 63 |
+
if error:
|
| 64 |
+
st.warning(error)
|
| 65 |
+
else:
|
| 66 |
+
raw_text = ""
|
| 67 |
+
# print(raw_text)
|
| 68 |
+
else:
|
| 69 |
+
fileUpload = st.file_uploader("Upload .txt, .md or .pdf", ['txt', 'md', 'pdf'])
|
| 70 |
+
if fileUpload:
|
| 71 |
+
file_type = fileUpload.name.split('.')[-1].lower()
|
| 72 |
+
|
| 73 |
+
if file_type in ["txt", "md"]:
|
| 74 |
+
raw_text = fileUpload.read().decode("utf-8", errors="ignore")
|
| 75 |
+
|
| 76 |
+
elif file_type=="pdf":
|
| 77 |
+
try:
|
| 78 |
+
pdf_reader = PyPDF2.PdfReader(fileUpload)
|
| 79 |
+
for page in pdf_reader.pages:
|
| 80 |
+
raw_text += page.extract_text() or ""
|
| 81 |
+
except Exception as e:
|
| 82 |
+
st.error(f"Error reading PDF: {e}")
|
| 83 |
+
if raw_text and st.session_state.get("last_input") != raw_text:
|
| 84 |
+
st.session_state.check_run = False
|
| 85 |
+
st.session_state.last_input = raw_text
|
| 86 |
+
|
| 87 |
+
# "Framework to Check", ["GDPR", "EU_AI_ACT", "ISO_27001"]
|
| 88 |
+
selectedFw=st.multiselect('Framework to Check',list(RULES.keys()),default=list(RULES.keys()))
|
| 89 |
st.markdown("---")
|
| 90 |
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
# ------- side bar end -----
|
| 94 |
+
|
| 95 |
+
# <====== main code =====>
|
| 96 |
+
# strip removes all the leading and trailing whitespace characters from a stringif run_btn and raw_text.strip():
|
| 97 |
+
if "results" not in st.session_state:
|
| 98 |
+
st.session_state.results = None
|
| 99 |
+
st.session_state.selectedFw=[]
|
| 100 |
+
|
| 101 |
+
if st.sidebar.button("Run Compliance Check") and raw_text.strip():
|
| 102 |
+
# reset_results()
|
| 103 |
+
with st.spinner("Running rule-based checks…."):
|
| 104 |
+
st.session_state.results=run_check(raw_text, selectedFw)
|
| 105 |
+
st.session_state.selectedFw=selectedFw
|
| 106 |
+
st.session_state.check_run=True
|
| 107 |
+
if st.session_state.get("check_run"):
|
| 108 |
+
results = st.session_state.results
|
| 109 |
+
selectedFw = st.session_state.selectedFw
|
| 110 |
+
# 📊 Checklist results
|
| 111 |
+
st.subheader('📊 Checklist results')
|
| 112 |
+
for fw in selectedFw:
|
| 113 |
+
# Count how many rules passed for that framework
|
| 114 |
+
passed = sum(1 for _, ok in results[fw] if ok) # _ is unused, ok is True/False
|
| 115 |
+
total = len(results[fw])
|
| 116 |
+
|
| 117 |
+
st.write(f"**{fw}: {passed}/{total} items passed**") # Example: EU_AI_ACT: 0/2 items passed
|
| 118 |
+
st.progress(passed / total)
|
| 119 |
+
|
| 120 |
+
for label, ok in results[fw]:
|
| 121 |
+
st.write(("✅" if ok else "❌") + " " + label) # Example: ❌ Lawful basis documented
|
| 122 |
+
st.markdown("---")
|
| 123 |
+
|
| 124 |
+
# 📝 Generate narrative report
|
| 125 |
+
|
| 126 |
+
st.subheader('📝 Generate narrative report')
|
| 127 |
+
if st.button('Generate AI report'):
|
| 128 |
+
with st.spinner("Calling model… this may take ~30 s"):
|
| 129 |
+
bullet = "\n".join(
|
| 130 |
+
f"- {fw}: {sum(ok for _, ok in results[fw])}/{len(results[fw])} passed"
|
| 131 |
+
for fw in selectedFw
|
| 132 |
+
)
|
| 133 |
+
prompt=AI_REPORT_PROMPT.format(bullet=bullet)
|
| 134 |
+
report=generate_report(prompt)
|
| 135 |
+
st.markdown("#### Draft report")
|
| 136 |
+
st.code(report, language="markdown")
|
| 137 |
+
st.download_button("⬇️ Download .md",report.encode('utf-8'),file_name="anupalan_karta_report.md",
|
| 138 |
mime="text/markdown")
|
| 139 |
+
else:
|
| 140 |
+
st.info("Awaiting input…")
|