Biden / app.py
sudhir2016's picture
Update app.py
07e3930
raw
history blame contribute delete
943 Bytes
import gradio as gr
from langchain.vectorstores import Chroma
from langchain import HuggingFaceHub
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.document_loaders import TextLoader
from langchain.chains import RetrievalQA
import os
llm = HuggingFaceHub(repo_id="HuggingFaceH4/zephyr-7b-beta")
embeddings = HuggingFaceEmbeddings()
loader = TextLoader('us.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
texts = text_splitter.split_documents(documents)
db = Chroma.from_documents(texts, embeddings)
retriever = db.as_retriever()
qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)
def answer(query):
out=qa.run(query)
return out
demo = gr.Interface(fn=answer, inputs='text',outputs='text',examples=[['What did the president say about Ketanji Jackson Brown']])
demo.launch()