Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -183,8 +183,37 @@ def display_collection_sidebar():
|
|
| 183 |
with st.sidebar:
|
| 184 |
st.title("📚 Document Manager")
|
| 185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
# Upload Section
|
| 187 |
-
st.header("Upload Documents"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
uploaded_files = st.file_uploader(
|
| 189 |
"Upload PDF documents",
|
| 190 |
type=['pdf'],
|
|
@@ -192,63 +221,8 @@ def display_collection_sidebar():
|
|
| 192 |
help="Limit 200MB per file • PDF"
|
| 193 |
)
|
| 194 |
|
| 195 |
-
# Collection Selection
|
| 196 |
-
st.header("Collections")
|
| 197 |
-
collections = get_collections(st.session_state.db_conn)
|
| 198 |
-
|
| 199 |
-
# Create New Collection button
|
| 200 |
-
if st.button("➕ Create New Collection"):
|
| 201 |
-
st.session_state.show_collection_dialog = True
|
| 202 |
-
|
| 203 |
-
# Collection selector
|
| 204 |
-
collection_options = ["All Documents"] + [c['name'] for c in collections]
|
| 205 |
-
selected_collection = st.selectbox(
|
| 206 |
-
"Select Collection",
|
| 207 |
-
collection_options,
|
| 208 |
-
index=0,
|
| 209 |
-
key="collection_selector"
|
| 210 |
-
)
|
| 211 |
-
|
| 212 |
-
# Update current collection in session state
|
| 213 |
-
if selected_collection != "All Documents":
|
| 214 |
-
st.session_state.current_collection = next(
|
| 215 |
-
(c for c in collections if c['name'] == selected_collection),
|
| 216 |
-
None
|
| 217 |
-
)
|
| 218 |
-
else:
|
| 219 |
-
st.session_state.current_collection = None
|
| 220 |
-
|
| 221 |
-
# Process uploads automatically when files are selected
|
| 222 |
if uploaded_files:
|
| 223 |
-
|
| 224 |
-
with st.spinner("Processing documents..."):
|
| 225 |
-
collection_id = st.session_state.current_collection['id'] if st.session_state.current_collection else None
|
| 226 |
-
# Create a dictionary with the collection_id
|
| 227 |
-
upload_params = {'collection_id': collection_id} if collection_id else {}
|
| 228 |
-
|
| 229 |
-
# Pass the parameters as a dictionary to handle_document_upload
|
| 230 |
-
handle_document_upload(uploaded_files, **upload_params)
|
| 231 |
-
st.session_state.processed_files = uploaded_files
|
| 232 |
-
st.session_state.chat_ready = True
|
| 233 |
-
# Switch to chat interface
|
| 234 |
-
st.rerun()
|
| 235 |
-
|
| 236 |
-
# Display current collection info
|
| 237 |
-
if st.session_state.current_collection:
|
| 238 |
-
st.header("Collection Info")
|
| 239 |
-
collection = st.session_state.current_collection
|
| 240 |
-
documents = get_collection_documents(st.session_state.db_conn, collection['id'])
|
| 241 |
-
|
| 242 |
-
st.markdown(f"""
|
| 243 |
-
**Collection:** {collection['name']}
|
| 244 |
-
**Documents:** {len(documents)}
|
| 245 |
-
**Created:** {collection['created_at']}
|
| 246 |
-
""")
|
| 247 |
-
|
| 248 |
-
if documents:
|
| 249 |
-
st.subheader("Documents in Collection")
|
| 250 |
-
for doc in documents:
|
| 251 |
-
st.write(f"📄 {doc['name']}")
|
| 252 |
|
| 253 |
def display_collection_dialog():
|
| 254 |
"""Display the create collection dialog."""
|
|
|
|
| 183 |
with st.sidebar:
|
| 184 |
st.title("📚 Document Manager")
|
| 185 |
|
| 186 |
+
# Collection Creation Section
|
| 187 |
+
st.header("Collections")
|
| 188 |
+
if st.button("➕ Create New Collection"):
|
| 189 |
+
show_collection_creation_dialog()
|
| 190 |
+
|
| 191 |
+
# Collection Selection
|
| 192 |
+
collections = get_collections(st.session_state.db_conn)
|
| 193 |
+
if collections:
|
| 194 |
+
selected_collection = st.selectbox(
|
| 195 |
+
"Select Collection",
|
| 196 |
+
options=["All Documents"] + [c['name'] for c in collections],
|
| 197 |
+
key="collection_selector"
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
if selected_collection != "All Documents":
|
| 201 |
+
current_collection = next(
|
| 202 |
+
(c for c in collections if c['name'] == selected_collection),
|
| 203 |
+
None
|
| 204 |
+
)
|
| 205 |
+
if current_collection:
|
| 206 |
+
st.session_state.current_collection = current_collection
|
| 207 |
+
show_collection_details(current_collection)
|
| 208 |
+
|
| 209 |
# Upload Section
|
| 210 |
+
st.header("Upload Documents")
|
| 211 |
+
upload_to = st.selectbox(
|
| 212 |
+
"Upload to",
|
| 213 |
+
options=["New Collection"] + [c['name'] for c in collections],
|
| 214 |
+
key="upload_destination"
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
uploaded_files = st.file_uploader(
|
| 218 |
"Upload PDF documents",
|
| 219 |
type=['pdf'],
|
|
|
|
| 221 |
help="Limit 200MB per file • PDF"
|
| 222 |
)
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
if uploaded_files:
|
| 225 |
+
handle_uploads(uploaded_files, upload_to)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
def display_collection_dialog():
|
| 228 |
"""Display the create collection dialog."""
|