Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,12 @@ from PyPDF2 import PdfReader
|
|
4 |
from langchain.text_splitter import CharacterTextSplitter
|
5 |
from langchain_huggingface import HuggingFaceEmbeddings
|
6 |
from langchain_community.vectorstores import FAISS
|
7 |
-
from
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from langchain.chains import ConversationalRetrievalChain
|
10 |
-
from transformers import pipeline # Hugging Face pipeline for using T5 model
|
11 |
import os
|
12 |
|
|
|
13 |
# Access Hugging Face API token from Streamlit secrets
|
14 |
hf_token = st.secrets["huggingface"]["HF_TOKEN"]
|
15 |
|
@@ -44,15 +44,21 @@ def get_vectorstore(text_chunks):
|
|
44 |
|
45 |
# Function to create the conversation chain using T5 from Hugging Face API
|
46 |
def get_conversation_chain(vectorstore):
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
# Create a conversation chain using the
|
54 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
55 |
-
llm=t5_model
|
56 |
retriever=vectorstore.as_retriever(),
|
57 |
memory=memory,
|
58 |
)
|
|
|
4 |
from langchain.text_splitter import CharacterTextSplitter
|
5 |
from langchain_huggingface import HuggingFaceEmbeddings
|
6 |
from langchain_community.vectorstores import FAISS
|
7 |
+
from langchain_huggingface import HuggingFaceHub
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from langchain.chains import ConversationalRetrievalChain
|
|
|
10 |
import os
|
11 |
|
12 |
+
|
13 |
# Access Hugging Face API token from Streamlit secrets
|
14 |
hf_token = st.secrets["huggingface"]["HF_TOKEN"]
|
15 |
|
|
|
44 |
|
45 |
# Function to create the conversation chain using T5 from Hugging Face API
|
46 |
def get_conversation_chain(vectorstore):
|
47 |
+
llm = HuggingFaceHub(
|
48 |
+
repo_id="google/t5-large", # Replace with your Hugging Face model ID
|
49 |
+
temperature=0.7, # Adjust for creativity
|
50 |
+
max_new_tokens=100, # Control response length
|
51 |
+
top_p=0.9, # Nucleus sampling for better variety
|
52 |
+
top_k=50, # Top-k filtering
|
53 |
+
repetition_penalty=1.0 # Default value to prevent repetitive outputs
|
54 |
+
)
|
55 |
+
memory = ConversationBufferMemory(
|
56 |
+
memory_key="chat_history", return_messages=True
|
57 |
+
)
|
58 |
|
59 |
+
# Create a conversation chain using the correct LLM (llm, not t5_model)
|
60 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
61 |
+
llm=llm, # Pass 'llm' instead of 't5_model'
|
62 |
retriever=vectorstore.as_retriever(),
|
63 |
memory=memory,
|
64 |
)
|