Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
from PyPDF2 import PdfReader
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
import os
|
5 |
-
from langchain_community.embeddings import HuggingFaceEmbeddings
|
6 |
from langchain.vectorstores import FAISS
|
7 |
from langchain_groq import ChatGroq
|
8 |
from langchain.chains.question_answering import load_qa_chain
|
@@ -31,7 +31,7 @@ def get_text_chunks(text):
|
|
31 |
|
32 |
def get_vector_store(text_chunks):
|
33 |
"""Creates and saves a FAISS vector store from text chunks."""
|
34 |
-
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
35 |
vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)
|
36 |
vector_store.save_local("faiss_index")
|
37 |
|
@@ -52,22 +52,21 @@ def get_conversational_chain():
|
|
52 |
|
53 |
model = ChatGroq(
|
54 |
temperature=0.3,
|
55 |
-
model_name="deepseek-r1-distill-llama-70b",
|
56 |
groq_api_key=os.getenv("GROQ_API_KEY")
|
57 |
)
|
58 |
prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
59 |
chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
|
60 |
return chain
|
61 |
-
|
62 |
def eliminar_texto_entre_tags(texto):
|
63 |
patron = r'<think>.*?</think>'
|
64 |
-
texto_limpio = re.sub(patron, '', texto)
|
65 |
return texto_limpio
|
66 |
|
67 |
-
|
68 |
def user_input(user_question):
|
69 |
"""Handles user queries by retrieving answers from the vector store."""
|
70 |
-
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
71 |
|
72 |
new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
73 |
docs = new_db.similarity_search(user_question)
|
@@ -109,7 +108,8 @@ def main():
|
|
109 |
|
110 |
st.sidebar.header("Upload & Process PDF Files")
|
111 |
st.sidebar.markdown(
|
112 |
-
"Using DeepSeek R1 model for advanced conversational capabilities."
|
|
|
113 |
|
114 |
with st.sidebar:
|
115 |
pdf_docs = st.file_uploader(
|
|
|
2 |
from PyPDF2 import PdfReader
|
3 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
4 |
import os
|
5 |
+
from langchain_community.embeddings import HuggingFaceEmbeddings
|
6 |
from langchain.vectorstores import FAISS
|
7 |
from langchain_groq import ChatGroq
|
8 |
from langchain.chains.question_answering import load_qa_chain
|
|
|
31 |
|
32 |
def get_vector_store(text_chunks):
|
33 |
"""Creates and saves a FAISS vector store from text chunks."""
|
34 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
35 |
vector_store = FAISS.from_texts(text_chunks, embedding=embeddings)
|
36 |
vector_store.save_local("faiss_index")
|
37 |
|
|
|
52 |
|
53 |
model = ChatGroq(
|
54 |
temperature=0.3,
|
55 |
+
model_name="deepseek-r1-distill-llama-70b",
|
56 |
groq_api_key=os.getenv("GROQ_API_KEY")
|
57 |
)
|
58 |
prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
59 |
chain = load_qa_chain(model, chain_type="stuff", prompt=prompt)
|
60 |
return chain
|
61 |
+
|
62 |
def eliminar_texto_entre_tags(texto):
|
63 |
patron = r'<think>.*?</think>'
|
64 |
+
texto_limpio = re.sub(patron, '', texto, flags=re.DOTALL)
|
65 |
return texto_limpio
|
66 |
|
|
|
67 |
def user_input(user_question):
|
68 |
"""Handles user queries by retrieving answers from the vector store."""
|
69 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
70 |
|
71 |
new_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
72 |
docs = new_db.similarity_search(user_question)
|
|
|
108 |
|
109 |
st.sidebar.header("Upload & Process PDF Files")
|
110 |
st.sidebar.markdown(
|
111 |
+
"Using DeepSeek R1 model for advanced conversational capabilities."
|
112 |
+
)
|
113 |
|
114 |
with st.sidebar:
|
115 |
pdf_docs = st.file_uploader(
|