Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -5,27 +5,17 @@ import sqlite3
|
|
5 |
import pdfplumber
|
6 |
from langchain_community.vectorstores import FAISS
|
7 |
from langchain_openai import OpenAIEmbeddings
|
8 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
9 |
|
10 |
-
# Initialize system
|
11 |
@st.cache_resource
|
12 |
def init_system():
|
13 |
-
# 1. Process PDF
|
14 |
process_pdf("Q1FY24.pdf")
|
15 |
-
|
16 |
-
# 2. Load embeddings with secure API key
|
17 |
-
embeddings = OpenAIEmbeddings(
|
18 |
-
openai_api_key=os.getenv("OPENAI_API_KEY"),
|
19 |
-
model="text-embedding-ada-002"
|
20 |
-
)
|
21 |
-
|
22 |
-
# 3. Load vector store
|
23 |
vector_store = FAISS.load_local("faiss_index", embeddings)
|
24 |
-
|
25 |
-
# 4. Connect SQL
|
26 |
conn = sqlite3.connect('metric_table.db')
|
27 |
return vector_store, conn
|
28 |
|
|
|
29 |
def process_pdf(pdf_path):
|
30 |
# Structured Data Extraction
|
31 |
conn = sqlite3.connect('metric_table.db')
|
|
|
5 |
import pdfplumber
|
6 |
from langchain_community.vectorstores import FAISS
|
7 |
from langchain_openai import OpenAIEmbeddings
|
8 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter # Now works
|
9 |
|
|
|
10 |
@st.cache_resource
|
11 |
def init_system():
|
|
|
12 |
process_pdf("Q1FY24.pdf")
|
13 |
+
embeddings = OpenAIEmbeddings(openai_api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
vector_store = FAISS.load_local("faiss_index", embeddings)
|
|
|
|
|
15 |
conn = sqlite3.connect('metric_table.db')
|
16 |
return vector_store, conn
|
17 |
|
18 |
+
|
19 |
def process_pdf(pdf_path):
|
20 |
# Structured Data Extraction
|
21 |
conn = sqlite3.connect('metric_table.db')
|