Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,7 +33,6 @@ def process_files(files):
|
|
| 33 |
# Load Documents
|
| 34 |
docs = []
|
| 35 |
for file_obj in files:
|
| 36 |
-
# Gradio passes file objects, we need their paths
|
| 37 |
docs.extend(load_any(file_obj.name))
|
| 38 |
|
| 39 |
if not docs:
|
|
@@ -43,6 +42,10 @@ def process_files(files):
|
|
| 43 |
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
| 44 |
chunks = splitter.split_documents(docs)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Create Embeddings & Vector Store
|
| 47 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 48 |
db = FAISS.from_documents(chunks, embeddings)
|
|
|
|
| 33 |
# Load Documents
|
| 34 |
docs = []
|
| 35 |
for file_obj in files:
|
|
|
|
| 36 |
docs.extend(load_any(file_obj.name))
|
| 37 |
|
| 38 |
if not docs:
|
|
|
|
| 42 |
splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
|
| 43 |
chunks = splitter.split_documents(docs)
|
| 44 |
|
| 45 |
+
# --- SAFETY CHECK (This fixes the error) ---
|
| 46 |
+
if not chunks:
|
| 47 |
+
return None, "❌ Error: The PDF contains no selectable text. It might be a scanned image. Please convert it to Word/Text first."
|
| 48 |
+
|
| 49 |
# Create Embeddings & Vector Store
|
| 50 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
| 51 |
db = FAISS.from_documents(chunks, embeddings)
|