anktechsol commited on
Commit
e8ae44a
·
verified ·
1 Parent(s): 77fd595

Update app file

Browse files
Files changed (2) hide show
  1. src/app.py +71 -0
  2. src/streamlit_app.py +0 -40
src/app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from compliance_lib import fetch_text, run_check, generate_report, RULES
3
+ import textwrap, json, datetime, os
4
+
5
+ st.set_page_config(page_title="anupalankarta – Compliance Checker",
6
+ layout="wide")
7
+
8
+ st.title("🛡️ Anupalan Karta (अनुपालंकर्ता) – unified compliance self-check")
9
+
10
+ # --- sidebar ---------------------------------------------------------------
11
+ with st.sidebar:
12
+ st.header("📑 Input options")
13
+ mode = st.radio("Choose data source:",
14
+ ("Paste text", "URL of public policy", "Upload file"))
15
+ if mode == "Paste text":
16
+ raw_text = st.text_area("Paste your policy / procedures here")
17
+ elif mode == "URL of public policy":
18
+ url = st.text_input("Public URL (HTTPS)")
19
+ raw_text = fetch_text(url) if url else ""
20
+ else:
21
+ up = st.file_uploader("Upload .txt, .md or .pdf", type=["txt", "md", "pdf"])
22
+ raw_text = up.read().decode("utf-8", errors="ignore") if up else ""
23
+
24
+ st.markdown("---")
25
+ selected_fw = st.multiselect(
26
+ "Frameworks to check",
27
+ list(RULES.keys()),
28
+ default=list(RULES.keys())
29
+ )
30
+ run_btn = st.button("Run compliance check")
31
+
32
+ # --- main body --------------------------------------------------------------
33
+ if run_btn and raw_text.strip():
34
+ with st.spinner("Running rule-based checks…"):
35
+ results = run_check(raw_text)
36
+ st.subheader("📊 Checklist results")
37
+ for fw in selected_fw:
38
+ passed = sum(1 for _, ok in results[fw] if ok)
39
+ total = len(results[fw])
40
+ st.write(f"**{fw}: {passed}/{total} items passed**")
41
+ st.progress(passed / total)
42
+ for label, ok in results[fw]:
43
+ st.write(("✅" if ok else "❌") + " " + label)
44
+ st.markdown("---")
45
+
46
+ # --- AI report section --------------------------------------------------
47
+ st.subheader("📝 Generate narrative report")
48
+ if st.button("Generate AI report via Hugging Face model"):
49
+ with st.spinner("Calling model… this may take ~30 s"):
50
+ bullet = "\n".join(
51
+ f"- {fw}: {sum(ok for _, ok in results[fw])}/{len(results[fw])} passed"
52
+ for fw in selected_fw
53
+ )
54
+ prompt = textwrap.dedent(f"""
55
+ You are a compliance consultant. Summarize the following checklist
56
+ outcomes and give prioritized next steps. Use clear headings, bullet
57
+ points and be brief. Results:
58
+
59
+ {bullet}
60
+
61
+ Write the report for a technical audience.
62
+ """)
63
+ report = generate_report(prompt)
64
+ st.markdown("#### Draft report")
65
+ st.code(report, language="markdown")
66
+ st.download_button("⬇️ Download .md",
67
+ report.encode("utf-8"),
68
+ file_name="anupalankarta_report.md",
69
+ mime="text/markdown")
70
+ else:
71
+ st.info("Awaiting input…")
src/streamlit_app.py DELETED
@@ -1,40 +0,0 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
- import streamlit as st
5
-
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))