File size: 941 Bytes
b03b7d1
 
 
 
 
 
 
 
 
 
903cfeb
 
b03b7d1
 
019070f
b03b7d1
 
 
 
903cfeb
 
 
 
 
 
 
b03b7d1
 
903cfeb
 
 
 
 
 
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
29
30
31
32
33
34
'''
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

os.environ['OPENAI_API_KEY'] = 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

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()