Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import streamlit as st
|
|
| 2 |
from streamlit_option_menu import option_menu
|
| 3 |
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader
|
| 4 |
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
| 5 |
-
from
|
| 6 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 7 |
from langchain.chains import create_retrieval_chain
|
| 8 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
|
@@ -87,7 +87,7 @@ def pdf_rag_page():
|
|
| 87 |
docs = loader.load()
|
| 88 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 89 |
splits = text_splitter.split_documents(docs)
|
| 90 |
-
vectorstore =
|
| 91 |
retriever = vectorstore.as_retriever()
|
| 92 |
system_prompt = (
|
| 93 |
"You are an assistant for question-answering tasks. "
|
|
@@ -142,7 +142,7 @@ def web_rag_page():
|
|
| 142 |
documents = loader.load()
|
| 143 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200, add_start_index=True)
|
| 144 |
all_splits = text_splitter.split_documents(documents)
|
| 145 |
-
vectorstore =
|
| 146 |
retriever = vectorstore.as_retriever()
|
| 147 |
system_prompt = (
|
| 148 |
"You are an assistant for question-answering tasks. "
|
|
@@ -196,7 +196,7 @@ def text_document_rag_page():
|
|
| 196 |
content = file.read().decode('utf-8')
|
| 197 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 198 |
splits = text_splitter.split_text(content)
|
| 199 |
-
vectorstore =
|
| 200 |
retriever = vectorstore.as_retriever()
|
| 201 |
system_prompt = (
|
| 202 |
"You are an assistant for question-answering tasks. "
|
|
@@ -259,7 +259,7 @@ def audio_rag_page():
|
|
| 259 |
text = recognizer.recognize_google(audio)
|
| 260 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 261 |
splits = text_splitter.split_text(text)
|
| 262 |
-
vectorstore =
|
| 263 |
retriever = vectorstore.as_retriever()
|
| 264 |
system_prompt = (
|
| 265 |
"You are an assistant for question-answering tasks. "
|
|
@@ -315,7 +315,7 @@ def database_rag_page():
|
|
| 315 |
df = pd.read_sql_table(table_name, engine)
|
| 316 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 317 |
splits = text_splitter.split_text(df.to_string())
|
| 318 |
-
vectorstore =
|
| 319 |
retriever = vectorstore.as_retriever()
|
| 320 |
system_prompt = (
|
| 321 |
"You are an assistant for question-answering tasks. "
|
|
@@ -370,7 +370,7 @@ def api_rag_page():
|
|
| 370 |
data = response.json()
|
| 371 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 372 |
splits = text_splitter.split_text(str(data))
|
| 373 |
-
vectorstore =
|
| 374 |
retriever = vectorstore.as_retriever()
|
| 375 |
system_prompt = (
|
| 376 |
"You are an assistant for question-answering tasks. "
|
|
@@ -443,4 +443,4 @@ feedback = st.sidebar.text_area("Provide your feedback here:")
|
|
| 443 |
if st.sidebar.button("Submit Feedback"):
|
| 444 |
with open("feedback.txt", "a") as f:
|
| 445 |
f.write(f"Feedback: {feedback}\n")
|
| 446 |
-
st.sidebar.success("Feedback submitted successfully!")
|
|
|
|
| 2 |
from streamlit_option_menu import option_menu
|
| 3 |
from langchain_community.document_loaders import PyPDFLoader, WebBaseLoader
|
| 4 |
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
| 5 |
+
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 7 |
from langchain.chains import create_retrieval_chain
|
| 8 |
from langchain.chains.combine_documents import create_stuff_documents_chain
|
|
|
|
| 87 |
docs = loader.load()
|
| 88 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 89 |
splits = text_splitter.split_documents(docs)
|
| 90 |
+
vectorstore = FAISS.from_documents(documents=splits, embedding=OpenAIEmbeddings())
|
| 91 |
retriever = vectorstore.as_retriever()
|
| 92 |
system_prompt = (
|
| 93 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 142 |
documents = loader.load()
|
| 143 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200, add_start_index=True)
|
| 144 |
all_splits = text_splitter.split_documents(documents)
|
| 145 |
+
vectorstore = FAISS.from_documents(documents=all_splits, embedding=OpenAIEmbeddings())
|
| 146 |
retriever = vectorstore.as_retriever()
|
| 147 |
system_prompt = (
|
| 148 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 196 |
content = file.read().decode('utf-8')
|
| 197 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 198 |
splits = text_splitter.split_text(content)
|
| 199 |
+
vectorstore = FAISS.from_texts(texts=splits, embedding=OpenAIEmbeddings())
|
| 200 |
retriever = vectorstore.as_retriever()
|
| 201 |
system_prompt = (
|
| 202 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 259 |
text = recognizer.recognize_google(audio)
|
| 260 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 261 |
splits = text_splitter.split_text(text)
|
| 262 |
+
vectorstore = FAISS.from_texts(texts=splits, embedding=OpenAIEmbeddings())
|
| 263 |
retriever = vectorstore.as_retriever()
|
| 264 |
system_prompt = (
|
| 265 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 315 |
df = pd.read_sql_table(table_name, engine)
|
| 316 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 317 |
splits = text_splitter.split_text(df.to_string())
|
| 318 |
+
vectorstore = FAISS.from_texts(texts=splits, embedding=OpenAIEmbeddings())
|
| 319 |
retriever = vectorstore.as_retriever()
|
| 320 |
system_prompt = (
|
| 321 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 370 |
data = response.json()
|
| 371 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
| 372 |
splits = text_splitter.split_text(str(data))
|
| 373 |
+
vectorstore = FAISS.from_texts(texts=splits, embedding=OpenAIEmbeddings())
|
| 374 |
retriever = vectorstore.as_retriever()
|
| 375 |
system_prompt = (
|
| 376 |
"You are an assistant for question-answering tasks. "
|
|
|
|
| 443 |
if st.sidebar.button("Submit Feedback"):
|
| 444 |
with open("feedback.txt", "a") as f:
|
| 445 |
f.write(f"Feedback: {feedback}\n")
|
| 446 |
+
st.sidebar.success("Feedback submitted successfully!")
|