Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import fitz # PyMuPDF for PDF parsing
|
|
5 |
import numpy as np
|
6 |
import faiss
|
7 |
from sentence_transformers import SentenceTransformer # Hugging Face transformer
|
|
|
8 |
|
9 |
# Initialize the Hugging Face model and Groq API client
|
10 |
model = SentenceTransformer('all-MiniLM-L6-v2') # Model for generating embeddings
|
@@ -13,7 +14,7 @@ client = Groq(api_key="GROQ_API_KEY")
|
|
13 |
|
14 |
# Function to extract text from a PDF
|
15 |
def extract_text_from_pdf(file):
|
16 |
-
doc = fitz.open(file) # Use the file
|
17 |
text = ""
|
18 |
for page in doc:
|
19 |
text += page.get_text()
|
|
|
5 |
import numpy as np
|
6 |
import faiss
|
7 |
from sentence_transformers import SentenceTransformer # Hugging Face transformer
|
8 |
+
from io import BytesIO # To handle file upload correctly
|
9 |
|
10 |
# Initialize the Hugging Face model and Groq API client
|
11 |
model = SentenceTransformer('all-MiniLM-L6-v2') # Model for generating embeddings
|
|
|
14 |
|
15 |
# Function to extract text from a PDF
|
16 |
def extract_text_from_pdf(file):
|
17 |
+
doc = fitz.open(stream=file.read(), filetype="pdf") # Use the stream and specify file type
|
18 |
text = ""
|
19 |
for page in doc:
|
20 |
text += page.get_text()
|