Gita / app.py
sudhir2016's picture
Create app.py
3e1059d
raw
history blame
948 Bytes
import gradio as gr
from langchain.vectorstores import Chroma
docsearch = Chroma.from_texts(texts, embeddings,persist_directory=persist_directory)
def answer(question):
out=chain.run(question)
return out
demo = gr.Interface(fn=answer, inputs='text',outputs='text',examples=[['What is the capital of India ?']])
demo.launch()
from langchain.docstore.document import Document
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.text_splitter import CharacterTextSplitter
embeddings = HuggingFaceEmbeddings()
with open('Gita full.txt') as f:
gita = f.read()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_text(gita)
docsearch = Chroma.from_texts(texts, embeddings)
def answer(query):
docs = docsearch.similarity_search(query)
out=docs[0].page_content
return out
demo = gr.Interface(fn=answer, inputs='text',outputs='text',examples=[['song celestial']])
demo.launch()