Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,17 +25,19 @@ with st.sidebar:
|
|
| 25 |
|
| 26 |
# Fetch collection names for dropdown
|
| 27 |
try:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
st.stop()
|
| 40 |
|
| 41 |
is_grant_app = st.toggle("Is this a Grant Application?", value=False)
|
|
@@ -50,10 +52,14 @@ if uploaded_file:
|
|
| 50 |
st.success(f"Uploaded `{uploaded_file.name}`")
|
| 51 |
|
| 52 |
modified_time = datetime.now().isoformat()
|
| 53 |
-
collection = db[
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
else:
|
| 58 |
st.write("⏳ Processing with DocumentChunker...")
|
| 59 |
chunker = DocumentChunker()
|
|
@@ -61,6 +67,7 @@ if uploaded_file:
|
|
| 61 |
|
| 62 |
if chunks:
|
| 63 |
for chunk in chunks:
|
|
|
|
| 64 |
chunk['metadata'].update({
|
| 65 |
"title": uploaded_file.name,
|
| 66 |
"uploaded_at": modified_time,
|
|
@@ -68,7 +75,7 @@ if uploaded_file:
|
|
| 68 |
})
|
| 69 |
collection.insert_one(chunk)
|
| 70 |
|
| 71 |
-
st.success(f"✅ {len(chunks)} chunks inserted into `{
|
| 72 |
|
| 73 |
# Show a few previews
|
| 74 |
for i, c in enumerate(chunks[:3]):
|
|
|
|
| 25 |
|
| 26 |
# Fetch collection names for dropdown
|
| 27 |
try:
|
| 28 |
+
existing_categories = db["final_chunks"].distinct("collection_category") or []
|
| 29 |
+
except Exception:
|
| 30 |
+
existing_categories = []
|
| 31 |
+
existing_categories=sorted([c for c in existing_categories if c])+["Create New Category"]
|
| 32 |
+
selected_category = st.selectbox(
|
| 33 |
+
"Choose Category (collection_category)",
|
| 34 |
+
existing_categories,
|
| 35 |
+
index=existing_categories.index("Create New Category") if "Create New Category" in existing_categories else 0
|
| 36 |
+
)
|
| 37 |
+
if selected_category == "Create New Category":
|
| 38 |
+
selected_category = st.sidebar.text_input("Enter Category Name:")
|
| 39 |
+
if not selected_category:
|
| 40 |
+
st.warning("⚠️ Enter a category name to proceed.")
|
| 41 |
st.stop()
|
| 42 |
|
| 43 |
is_grant_app = st.toggle("Is this a Grant Application?", value=False)
|
|
|
|
| 52 |
st.success(f"Uploaded `{uploaded_file.name}`")
|
| 53 |
|
| 54 |
modified_time = datetime.now().isoformat()
|
| 55 |
+
collection = db['final_chunks']
|
| 56 |
+
already = final_col.find_one({
|
| 57 |
+
"metadata.title": uploaded_file.name,
|
| 58 |
+
"collection_category": selected_category
|
| 59 |
+
})
|
| 60 |
+
|
| 61 |
+
if already:
|
| 62 |
+
st.warning(f"⚠️ `{uploaded_file.name}` already exists in category `{selected_category}`. Skipping…")
|
| 63 |
else:
|
| 64 |
st.write("⏳ Processing with DocumentChunker...")
|
| 65 |
chunker = DocumentChunker()
|
|
|
|
| 67 |
|
| 68 |
if chunks:
|
| 69 |
for chunk in chunks:
|
| 70 |
+
chunk['collection_category']=selected_category
|
| 71 |
chunk['metadata'].update({
|
| 72 |
"title": uploaded_file.name,
|
| 73 |
"uploaded_at": modified_time,
|
|
|
|
| 75 |
})
|
| 76 |
collection.insert_one(chunk)
|
| 77 |
|
| 78 |
+
st.success(f"✅ {len(chunks)} chunks inserted into `final_chunks` (category: `{selected_category}`)")
|
| 79 |
|
| 80 |
# Show a few previews
|
| 81 |
for i, c in enumerate(chunks[:3]):
|