Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
from groq import Groq
|
| 4 |
-
from
|
| 5 |
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 7 |
from PyPDF2 import PdfReader
|
| 8 |
import streamlit as st
|
| 9 |
from tempfile import NamedTemporaryFile
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Initialize Groq client
|
| 12 |
-
client = Groq(api_key=os.environ
|
| 13 |
|
| 14 |
# Function to extract text from a PDF
|
| 15 |
def extract_text_from_pdf(pdf_file_path):
|
|
@@ -89,8 +93,11 @@ for idx, link in enumerate(doc_links):
|
|
| 89 |
if pdf_path:
|
| 90 |
text = extract_text_from_pdf(pdf_path)
|
| 91 |
chunks = chunk_text(text)
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
| 94 |
else:
|
| 95 |
st.error(f"β Failed to download or process PDF from Link {idx + 1}")
|
| 96 |
|
|
|
|
| 1 |
import os
|
| 2 |
import requests
|
| 3 |
from groq import Groq
|
| 4 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 5 |
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 7 |
from PyPDF2 import PdfReader
|
| 8 |
import streamlit as st
|
| 9 |
from tempfile import NamedTemporaryFile
|
| 10 |
+
from dotenv import load_dotenv
|
| 11 |
+
|
| 12 |
+
# Load environment variables
|
| 13 |
+
load_dotenv()
|
| 14 |
|
| 15 |
# Initialize Groq client
|
| 16 |
+
client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
|
| 17 |
|
| 18 |
# Function to extract text from a PDF
|
| 19 |
def extract_text_from_pdf(pdf_file_path):
|
|
|
|
| 93 |
if pdf_path:
|
| 94 |
text = extract_text_from_pdf(pdf_path)
|
| 95 |
chunks = chunk_text(text)
|
| 96 |
+
if chunks:
|
| 97 |
+
vector_db = create_embeddings_and_store(chunks, vector_db=vector_db)
|
| 98 |
+
st.success(f"β
Processed document {idx + 1}")
|
| 99 |
+
else:
|
| 100 |
+
st.warning(f"β οΈ No text extracted from document {idx + 1}")
|
| 101 |
else:
|
| 102 |
st.error(f"β Failed to download or process PDF from Link {idx + 1}")
|
| 103 |
|