Spaces:
Build error
Build error
Jack Sambath commited on
Commit ·
e577c1e
1
Parent(s): bc99b82
new cache
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from langchain.text_splitter import RecursiveCharacterTextSplitter
|
|
| 6 |
from langchain.chains.question_answering import load_qa_chain
|
| 7 |
import streamlit as st
|
| 8 |
from langchain.chains import RetrievalQA
|
|
|
|
| 9 |
@st.cache_resource
|
| 10 |
def llm():
|
| 11 |
return HuggingFaceHub(repo_id="google/flan-t5-small", model_kwargs={"temperature":0,"max_length":200}, huggingfacehub_api_token="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") # type: ignore
|
|
@@ -18,8 +19,8 @@ def qa(query):
|
|
| 18 |
texts = text_splitter.split_documents(docs)
|
| 19 |
embeddings = HuggingFaceEmbeddings()
|
| 20 |
vectordb = Chroma.from_documents(documents=texts,embedding=embeddings)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
st.write(result["
|
| 25 |
-
|
|
|
|
| 6 |
from langchain.chains.question_answering import load_qa_chain
|
| 7 |
import streamlit as st
|
| 8 |
from langchain.chains import RetrievalQA
|
| 9 |
+
query = st.text_input("Ask a question: ")
|
| 10 |
@st.cache_resource
|
| 11 |
def llm():
|
| 12 |
return HuggingFaceHub(repo_id="google/flan-t5-small", model_kwargs={"temperature":0,"max_length":200}, huggingfacehub_api_token="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") # type: ignore
|
|
|
|
| 19 |
texts = text_splitter.split_documents(docs)
|
| 20 |
embeddings = HuggingFaceEmbeddings()
|
| 21 |
vectordb = Chroma.from_documents(documents=texts,embedding=embeddings)
|
| 22 |
+
qa = RetrievalQA.from_chain_type(llm=llm(), chain_type="stuff",retriever=vectordb.as_retriever(search_type="mmr", search_kwargs={'fetch_k': 30}), return_source_documents=True)
|
| 23 |
+
result = qa({"query": query})
|
| 24 |
+
st.write(result["result"])
|
| 25 |
+
st.write(result["source_documents"][0])
|
| 26 |
+
qa(query)
|