Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,16 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
-
|
4 |
from PyPDF2 import PdfReader
|
5 |
-
# from langchain import FAISS
|
6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
7 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
8 |
-
|
9 |
-
from langchain.vectorstores import Pinecone
|
10 |
-
import pinecone
|
11 |
from langchain.llms import OpenAI
|
12 |
from langchain.chains.question_answering import load_qa_chain
|
13 |
from langchain.callbacks import get_openai_callback
|
14 |
|
|
|
15 |
# Sidebar contents
|
16 |
with st.sidebar:
|
17 |
st.title('π€π¬ LLM Chat App')
|
@@ -51,28 +50,34 @@ def main():
|
|
51 |
store_name = pdf.name[:-4]
|
52 |
st.write(f'{store_name}')
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
)
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
# Accept user questions/query
|
78 |
query = st.text_input("Ask questions about your PDF file:")
|
|
|
1 |
import streamlit as st
|
2 |
+
# from streamlit_extras.add_vertical_space import add_vertical_space
|
3 |
import os
|
4 |
+
import pickle
|
5 |
from PyPDF2 import PdfReader
|
|
|
6 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
7 |
from langchain.embeddings.openai import OpenAIEmbeddings
|
8 |
+
from langchain.vectorstores import FAISS
|
|
|
|
|
9 |
from langchain.llms import OpenAI
|
10 |
from langchain.chains.question_answering import load_qa_chain
|
11 |
from langchain.callbacks import get_openai_callback
|
12 |
|
13 |
+
|
14 |
# Sidebar contents
|
15 |
with st.sidebar:
|
16 |
st.title('π€π¬ LLM Chat App')
|
|
|
50 |
store_name = pdf.name[:-4]
|
51 |
st.write(f'{store_name}')
|
52 |
|
53 |
+
if os.path.exists(f"{store_name}.pkl"):
|
54 |
+
with open(f"{store_name}.pkl", "rb") as f:
|
55 |
+
VectorStore = pickle.load(f)
|
56 |
+
st.write('Embeddings Loaded from the Disk')
|
57 |
+
else:
|
58 |
+
st.write('Embeddings calculate to the Pinecone')
|
59 |
+
embeddings = OpenAIEmbeddings()
|
60 |
+
VectorStore = FAISS.from_texts(chunks, embedding=embeddings)
|
61 |
+
with open(f"{store_name}.pkl", "wb") as f:
|
62 |
+
pickle.dump(VectorStore, f)
|
63 |
+
st.download_button(
|
64 |
+
label="Download data as pkl",
|
65 |
+
data=f,
|
66 |
+
file_name='{store_name}.pkl',
|
67 |
+
mime='text/text',
|
68 |
+
)
|
69 |
+
|
70 |
+
# PINECONE_API_KEY = os.environ.get('PINECONE_API_KEY', '894d5f1f-df46-4b01-8407-d9977eaee2eb')
|
71 |
+
# PINECONE_API_ENV = os.environ.get('PINECONE_API_ENV',
|
72 |
+
# 'asia-southeast1-gcp-free') # You may need to switch with your env
|
73 |
+
# embeddings = OpenAIEmbeddings()
|
74 |
+
# # initialize pinecone
|
75 |
+
# pinecone.init(
|
76 |
+
# api_key=PINECONE_API_KEY, # find at app.pinecone.io
|
77 |
+
# environment=PINECONE_API_ENV # next to api key in console
|
78 |
+
# )
|
79 |
+
# index_name = "indexer" # put in the name of your pinecone index here
|
80 |
+
# VectorStore = Pinecone.from_texts(chunks, embeddings, index_name=index_name)
|
81 |
|
82 |
# Accept user questions/query
|
83 |
query = st.text_input("Ask questions about your PDF file:")
|