Spaces:
Sleeping
Sleeping
import streamlit as st | |
from langchain.text_splitter import CharacterTextSplitter | |
from langchain_community.document_loaders import TextLoader | |
from langchain.embeddings import OpenAIEmbeddings | |
from langchain.vectorstores import Chroma | |
from langchain.chains import RetrievalQA | |
from langchain.embeddings.sentence_transformer import SentenceTransformerEmbeddings | |
loader = TextLoader('India.txt') | |
documents =loader.load() | |
text_splitter = CharacterTextSplitter (chunk_size=200, | |
chunk_overlap=0) | |
texts= text_splitter.split_documents(documents) | |
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2") | |
db = Chroma.from_documents(texts, embeddings) | |
db._collection.get(include=['embeddings']) | |
retriever = db.as_retriever(search_kwargs={"k": 1}) | |
docs = retriever.get_relevant_documents("What is the capital of india?") | |
st.write("Answer") | |
st.text(docs) | |
# st.write("File content:") | |
# st.text(file_content) |