Spaces:
Runtime error
Runtime error
''' | |
Om Sri Sai Ram | |
Swami's Chatbot Alpha Version | |
''' | |
from langchain.vectorstores import FAISS | |
from langchain.chains.question_answering import load_qa_chain | |
from langchain.embeddings.openai import OpenAIEmbeddings | |
from langchain.llms import OpenAI | |
import gradio as gr | |
import time | |
import os | |
OPEN_AI_KEY=os.getenv('OPENAI_API_KEY') | |
os.environ["OPENAI_API_KEY"]=OPENAI_API_KEY | |
vectordb = FAISS.load_local("faiss_index OPENAI", OpenAIEmbeddings()) | |
chain = load_qa_chain(OpenAI(), chain_type = 'stuff') | |
with gr.Blocks() as demo: | |
chatbot = gr.Chatbot() | |
msg = gr.Textbox() | |
clear = gr.ClearButton([msg, chatbot]) | |
def respond(message, chat_history): | |
docs = vectordb.similarity_search(message) | |
chat_history.append((message, chain.run(input_documents = docs, question = message))) | |
return "", chat_history | |
msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
if __name__ == "__main__": | |
demo.launch() |