Spaces:
Runtime error
Runtime error
File size: 1,345 Bytes
f698ede 4af7d90 f698ede 8f0f959 f698ede 4af7d90 f698ede 8f0f959 4b2f3f8 8f0f959 4b2f3f8 f698ede 8f0f959 f698ede 8f0f959 f698ede |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import os, gradio
from langchain.document_loaders import UnstructuredPDFLoader
from langchain.indexes import VectorstoreIndexCreator
import glob
os.environ['OPENAI_API_KEY'] = os.getenv("OPENAI_API_KEY")
loaders = [UnstructuredPDFLoader(glob.glob("*.pdf"))]
# Create the index, if it does not exist, and save it
if not os.path.isfile('chroma-embeddings.parquet'):
from langchain.vectorstores import Chroma
index = VectorstoreIndexCreator(vectorstore_cls=Chroma, vectorstore_kwargs={ "persist_directory": "VectorStoreIndex/"}).from_loaders(loaders)
index.vectorstore.persist()
# Load the saved index
index_saved = VectorstoreIndexCreator().from_persistent_index(".")
description = '''This is an AI conversational agent that has studied the Asom Barta newspapers over the last 1 year, from June 2022 to May 2023. You can ask it any question pertaining to this period, and it will answer it.
\n\nThe AI can only frame its answers based on its worldview attained from the Asom Barta newspapers. If you ask it about anything not pertaining to the content of the
newspapers, it will simply reply with "I don't know". Enjoy!'''
def chat_response(query):
return index_saved.query(query)
interface = gradio.Interface(fn=chat_response, inputs="text", outputs="text", title='Asom Barta Q&A Bot', description=description)
interface.launch() |