import streamlit as st from compliance_lib import * import PyPDF2 st.set_page_config(page_title="Anupalan Karta – Compliance Checker", layout="wide") st.title('🛡️ Anupalan Karta (अनुपालंकर्ता)') st.subheader('Unified compliance self-check Tool') st.markdown(""" ## Introduction **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. ### Why is this important? - Regulations protect your business from legal risks, fines, and reputational harm. - Checking compliance early helps you fix gaps before audits or problems arise. - Anupalan Karta gives you a fast, automated review and clear feedback, so you know where you stand. ## How to use 1. **Choose your input:** On the left, either paste your policy text, enter a public website link, or upload a file (.txt, .md, .pdf). 2. **Select frameworks:** Pick which compliance standards you want to check (you can select more than one). 3. **Run the check:** Click "Run compliance check" to see which requirements you meet and which need attention. 4. **Get your report:** Optionally, generate a summary report with next steps, and download it as a Markdown file. **Who is this for?** This tool is designed for business owners, data architects, and anyone responsible for data and compliance in their organization. No technical expertise is needed—just your policy documents. --- **Need a deeper compliance review or expert guidance?** Visit [anktechsol.com](https://anktechsol.com) for professional compliance consulting, detailed policy analysis, and tailored solutions for your business. --- """) # default state if "check_run" not in st.session_state: st.session_state.check_run = False st.session_state.raw_text = "" # ------ side bar ---- with st.sidebar: st.subheader('📥 Input options') option = st.radio('Choose data source:',['Paste text','URL of public policy','Upload file']) raw_text="" if(option=='Paste text'): raw_text= st.text_area('Paste your policy / procedures here') elif option == 'URL of public policy': Url = st.text_area("Public URL (HTTPS)", key="input_text") raw_text = fetchText(Url) if Url else st.warning if Url: raw_text, error = fetchText(Url) if error: st.warning(error) else: raw_text = "" # print(raw_text) else: fileUpload = st.file_uploader("Upload .txt, .md or .pdf", ['txt', 'md', 'pdf']) if fileUpload: file_type = fileUpload.name.split('.')[-1].lower() if file_type in ["txt", "md"]: raw_text = fileUpload.read().decode("utf-8", errors="ignore") elif file_type=="pdf": try: pdf_reader = PyPDF2.PdfReader(fileUpload) for page in pdf_reader.pages: raw_text += page.extract_text() or "" except Exception as e: st.error(f"Error reading PDF: {e}") if raw_text and st.session_state.get("last_input") != raw_text: st.session_state.check_run = False st.session_state.last_input = raw_text # "Framework to Check", ["GDPR", "EU_AI_ACT", "ISO_27001"] selectedFw=st.multiselect('Framework to Check',list(RULES.keys()),default=list(RULES.keys())) st.markdown("---") # ------- side bar end ----- # <====== main code =====> # strip removes all the leading and trailing whitespace characters from a stringif run_btn and raw_text.strip(): if "results" not in st.session_state: st.session_state.results = None st.session_state.selectedFw=[] if st.sidebar.button("Run Compliance Check") and raw_text.strip(): # reset_results() with st.spinner("Running rule-based checks…."): st.session_state.results=run_check(raw_text, selectedFw) st.session_state.selectedFw=selectedFw st.session_state.check_run=True if st.session_state.get("check_run"): results = st.session_state.results selectedFw = st.session_state.selectedFw # 📊 Checklist results st.subheader('📊 Checklist results') for fw in selectedFw: # Count how many rules passed for that framework passed = sum(1 for _, ok in results[fw] if ok) # _ is unused, ok is True/False total = len(results[fw]) st.write(f"**{fw}: {passed}/{total} items passed**") # Example: EU_AI_ACT: 0/2 items passed st.progress(passed / total) for label, ok in results[fw]: st.write(("✅" if ok else "❌") + " " + label) # Example: ❌ Lawful basis documented st.markdown("---") # 📝 Generate narrative report st.subheader('📝 Generate narrative report') if st.button('Generate AI report'): with st.spinner("Calling model… this may take ~30 s"): bullet = "\n".join( f"- {fw}: {sum(ok for _, ok in results[fw])}/{len(results[fw])} passed" for fw in selectedFw ) prompt=AI_REPORT_PROMPT.format(bullet=bullet) report=generate_report(prompt) st.markdown("#### Draft report") st.code(report, language="markdown") st.download_button("⬇️ Download .md",report.encode('utf-8'),file_name="anupalan_karta_report.md", mime="text/markdown") else: st.info("Awaiting input…")