ALVHB95 commited on
Commit
ed4a174
·
1 Parent(s): 687f0cb
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -49,7 +49,12 @@ image_gradio_app = gr.Interface(
49
  loader = PyPDFDirectoryLoader('pdfs')
50
  data=loader.load()
51
  # split documents
52
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
 
 
 
 
 
53
  docs = text_splitter.split_documents(data)
54
  # define embedding
55
  embeddings = HuggingFaceEmbeddings(model_name='thenlper/gte-small')
@@ -65,7 +70,12 @@ vectordb = Chroma.from_documents(
65
  )
66
  # define retriever
67
  retriever = vectordb.as_retriever(search_type="mmr")
68
- template = """Your name is AngryGreta and you are a recycling chatbot with the objective and poorpose to help people with waste management to improve environmental situation. Use the following pieces of context to answer the question if the question is related with recycling. Answer in the same language of the question. Keep the answer as concise as possible. Always say "thanks for asking!" at the end of the answer.
 
 
 
 
 
69
  context: {context}
70
  chat history: {chat_history}
71
  question: {question}
@@ -92,7 +102,7 @@ llm = HuggingFaceHub(
92
  )
93
  llm_chain = LLMChain(llm=llm, prompt=qa_prompt)
94
 
95
- memory = ConversationBufferMemory(llm=llm, memory_key="chat_history", output_key='answer', return_messages=True)
96
 
97
  qa_chain = ConversationalRetrievalChain.from_llm(
98
  llm = llm,
 
49
  loader = PyPDFDirectoryLoader('pdfs')
50
  data=loader.load()
51
  # split documents
52
+ text_splitter = RecursiveCharacterTextSplitter(
53
+ separator="\n",
54
+ chunk_size=1000,
55
+ chunk_overlap=150,
56
+ length_function=len
57
+ )
58
  docs = text_splitter.split_documents(data)
59
  # define embedding
60
  embeddings = HuggingFaceEmbeddings(model_name='thenlper/gte-small')
 
70
  )
71
  # define retriever
72
  retriever = vectordb.as_retriever(search_type="mmr")
73
+ template = """
74
+ Your name is AngryGreta and you are a recycling chatbot with the objective to anwer questions from user in English or Spanish /
75
+ Use the following pieces of context to answer the question if the question is related with recycling /
76
+ No more than two chunks of context /
77
+ Answer in the same language of the question /
78
+ Always say "thanks for asking!" at the end of the answer.
79
  context: {context}
80
  chat history: {chat_history}
81
  question: {question}
 
102
  )
103
  llm_chain = LLMChain(llm=llm, prompt=qa_prompt)
104
 
105
+ memory = ConversationBufferMemory(llm=llm, memory_key="chat_history", output_key='answer', return_messages=False)
106
 
107
  qa_chain = ConversationalRetrievalChain.from_llm(
108
  llm = llm,