cryogenic22 commited on
Commit
1764969
·
verified ·
1 Parent(s): c878d9c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -0
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from document_manager import DocumentManager, ChatInterface
3
+
4
+ def main():
5
+ st.set_page_config(page_title="RFP Analyzer", layout="wide")
6
+
7
+ # Initialize document manager
8
+ if 'doc_manager' not in st.session_state:
9
+ st.session_state.doc_manager = DocumentManager()
10
+
11
+ # Sidebar for document management
12
+ with st.sidebar:
13
+ st.title("📁 Document Management")
14
+
15
+ # Collection management
16
+ st.subheader("Collections")
17
+
18
+ # Create new collection
19
+ new_collection = st.text_input("New Collection Name")
20
+ if st.button("Create Collection") and new_collection:
21
+ collection_id = st.session_state.doc_manager.create_collection(new_collection)
22
+ st.success(f"Created collection: {new_collection}")
23
+ st.rerun()
24
+
25
+ # Collection selection
26
+ collections = st.session_state.doc_manager.get_collections()
27
+ collection_options = ["All Documents"] + [c['name'] for c in collections]
28
+ selected_collection = st.selectbox("Select Collection", collection_options)
29
+
30
+ # Document upload
31
+ st.subheader("Upload Documents")
32
+ uploaded_files = st.file_uploader(
33
+ "Upload PDF documents",
34
+ type=['pdf'],
35
+ accept_multiple_files=True
36
+ )
37
+
38
+ if uploaded_files:
39
+ collection_id = None
40
+ if selected_collection != "All Documents":
41
+ collection_id = next(c['id'] for c in collections if c['name'] == selected_collection)
42
+
43
+ doc_ids = st.session_state.doc_manager.upload_documents(uploaded_files, collection_id)
44
+ if doc_ids:
45
+ st.success(f"Uploaded {len(doc_ids)} documents")
46
+ st.rerun()
47
+
48
+ # Main content area
49
+ st.title("RFP Analyzer")
50
+
51
+ # Document selection for chat
52
+ if selected_collection != "All Documents":
53
+ collection_id = next(c['id'] for c in collections if c['name'] == selected_collection)
54
+ documents = st.session_state.doc_manager.get_collection_documents(collection_id)
55
+ else:
56
+ documents = st.session_state.doc_manager.get_collection_documents()
57
+
58
+ if documents:
59
+ st.subheader("Available Documents")
60
+ selected_docs = st.multiselect(
61
+ "Select documents for analysis",
62
+ options=[doc['id'] for doc in documents],
63
+ format_func=lambda x: next(doc['name'] for doc in documents if doc['id'] == x)
64
+ )
65
+
66
+ if selected_docs:
67
+ if st.button("Start Chat"):
68
+ vector_store = st.session_state.doc_manager.initialize_chat(selected_docs)
69
+ if vector_store:
70
+ st.session_state.chat_interface = ChatInterface(vector_store)
71
+ st.session_state.chat_active = True
72
+ st.rerun()
73
+
74
+ # Chat interface
75
+ if st.session_state.get('chat_active'):
76
+ st.divider()
77
+ st.subheader("Chat Interface")
78
+ st.session_state.chat_interface.display()
79
+
80
+ if __name__ == "__main__":
81
+ main()