Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,13 +151,13 @@ def load_pdf(files, state):
|
|
| 151 |
return "No file uploaded.", state, list(state["files"].keys())
|
| 152 |
|
| 153 |
try:
|
| 154 |
-
# Deduplicate
|
| 155 |
-
unique_files = list(
|
| 156 |
|
| 157 |
for file in unique_files:
|
| 158 |
-
filename = os.path.basename(file
|
| 159 |
|
| 160 |
-
text = read_pdf(file
|
| 161 |
new_chunks = chunk_text(text)
|
| 162 |
|
| 163 |
if not new_chunks:
|
|
@@ -167,13 +167,14 @@ def load_pdf(files, state):
|
|
| 167 |
state["chunks"].extend(new_chunks)
|
| 168 |
state["pdf_count"] += 1
|
| 169 |
|
|
|
|
| 170 |
index, _ = build_vectorstore(state["chunks"])
|
| 171 |
state["index"] = index
|
| 172 |
|
| 173 |
return (
|
| 174 |
f"{state['pdf_count']} PDF(s) loaded. Total chunks: {len(state['chunks'])}",
|
| 175 |
state,
|
| 176 |
-
list(state["files"].keys()) #
|
| 177 |
)
|
| 178 |
|
| 179 |
except Exception as e:
|
|
@@ -182,7 +183,7 @@ def load_pdf(files, state):
|
|
| 182 |
state,
|
| 183 |
list(state["files"].keys())
|
| 184 |
)
|
| 185 |
-
|
| 186 |
def remove_pdf(filename, state):
|
| 187 |
if filename not in state["files"]:
|
| 188 |
return f"{filename} not found.", state, list(state["files"].keys())
|
|
|
|
| 151 |
return "No file uploaded.", state, list(state["files"].keys())
|
| 152 |
|
| 153 |
try:
|
| 154 |
+
# Deduplicate file paths
|
| 155 |
+
unique_files = list(dict.fromkeys(files))
|
| 156 |
|
| 157 |
for file in unique_files:
|
| 158 |
+
filename = os.path.basename(file) # FIX: file is a string path
|
| 159 |
|
| 160 |
+
text = read_pdf(file)
|
| 161 |
new_chunks = chunk_text(text)
|
| 162 |
|
| 163 |
if not new_chunks:
|
|
|
|
| 167 |
state["chunks"].extend(new_chunks)
|
| 168 |
state["pdf_count"] += 1
|
| 169 |
|
| 170 |
+
# Rebuild FAISS
|
| 171 |
index, _ = build_vectorstore(state["chunks"])
|
| 172 |
state["index"] = index
|
| 173 |
|
| 174 |
return (
|
| 175 |
f"{state['pdf_count']} PDF(s) loaded. Total chunks: {len(state['chunks'])}",
|
| 176 |
state,
|
| 177 |
+
list(state["files"].keys()) # dropdown now works
|
| 178 |
)
|
| 179 |
|
| 180 |
except Exception as e:
|
|
|
|
| 183 |
state,
|
| 184 |
list(state["files"].keys())
|
| 185 |
)
|
| 186 |
+
|
| 187 |
def remove_pdf(filename, state):
|
| 188 |
if filename not in state["files"]:
|
| 189 |
return f"{filename} not found.", state, list(state["files"].keys())
|