forked from IammSwanand/Inscribe.AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
104 lines (88 loc) · 3.45 KB
/
app.py
File metadata and controls
104 lines (88 loc) · 3.45 KB
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
# app.py
import streamlit as st
from ingest import ingest_file
from search import answer_query
import os
from dotenv import load_dotenv
import chromadb
# Load environment variables
load_dotenv()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
CHROMA_DIR = os.getenv("CHROMA_PERSIST_DIR", "./chroma_db")
COLLECTION_NAME = "legal_docs"
# Configure Streamlit page
st.set_page_config(page_title="Inscribe.AI", layout="centered")
st.title("Inscribe.AI")
# Simple password gate (for dev only)
if "authorized" not in st.session_state:
st.session_state.authorized = False
if not st.session_state.authorized:
pwd = st.text_input("Enter password to access (for dev only)", type="password")
if st.button("Enter"):
if pwd == "devpass": # change to something secure
st.session_state.authorized = True
else:
st.error("Wrong password")
st.stop()
# ---------------- File Upload ----------------
st.header("Upload files")
uploaded_files = st.file_uploader("PDF / DOCX / TXT", accept_multiple_files=True)
uploader_name = st.text_input("Uploader name (optional)")
agree = st.checkbox("I agree to giving consent to Inscribe.AI to process my documents")
if agree:
st.info("please check the box to agree before uploading")
else:
st.warning("You must agree before uploading")
if st.button("Ingest files"):
if not uploaded_files:
st.warning("Please choose files")
else:
status_area = st.empty()
for f in uploaded_files:
if agree:
b = f.read()
status_area.text(f"Ingesting {f.name}...")
res = ingest_file(f.name, b, uploader=uploader_name or "unknown")
status_area.text(f"Ingested {res['file']}: {res['added']} chunks")
else:
st.error("You must agree to the consent checkbox to upload")
st.success("Done ingesting")
# ---------------- Clear Database ----------------
st.header("Manage Database")
if st.button("Clear all documents from the database"):
client = chromadb.PersistentClient(path=CHROMA_DIR)
if COLLECTION_NAME in [c.name for c in client.list_collections()]:
st.text("Clearing collection...")
client.delete_collection(COLLECTION_NAME)
st.success("Database cleared! You can now upload new documents.")
# ---------------- Query Section ----------------
st.header("Query")
q = st.text_area("Ask a question about your ingested documents")
if st.button("Search"):
if not q:
st.warning("Type a question")
else:
if not GROQ_API_KEY:
st.error("Set GROQ_API_KEY in .env to run retrieval + LLM")
else:
with st.spinner("Searching..."):
res = answer_query(q)
if isinstance(res, dict) and "result" in res:
st.markdown("### Answer")
st.write(res["result"])
else:
st.write(res)
tab1, tab2 = st.sidebar.tabs(["About Us", "Contact Us"])
with tab1:
st.write("""
# About Inscribe.AI
Inscribe.AI is a demo application that allows users to upload legal documents and query them using natural language.
It leverages Groq's LLM capabilities and ChromaDB for vector storage.
## Features
- Upload multiple documents (PDF, DOCX, TXT)
- Ingest and process documents into vector embeddings
- Query documents with natural language questions
- Get structured answers with source citations
""")
with tab2:
st.write("📧 contact@inscribe.ai")