jobanpreet123 commited on
Commit
4d7bb70
1 Parent(s): adccdb2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +44 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.chat_models import ChatOpenAI
2
+ # from langchain_community.document_loaders import WebBaseLoader
3
+ # from langchain.text_splitter import RecursiveCharacterTextSplitter
4
+ import gradio as gr
5
+ from langchain_pinecone import Pinecone
6
+ from langchain_openai import OpenAIEmbeddings , ChatOpenAI
7
+ from langchain.prompts import PromptTemplate
8
+ from langchain.chains import RetrievalQA
9
+ import os
10
+
11
+ os.environ["PINECONE_API_KEY"] = "9952de06-975b-4ca4-9908-491e8d08328a"
12
+ os.environ["OPENAI_API_KEY"]="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"
13
+
14
+
15
+ # create embeddings and store in vector database (Pinecone)
16
+ embeddings=OpenAIEmbeddings()
17
+ #docsearch=Pinecone.from_texts([t.page_content for t in document_chunks],embeddings,index_name="index_name")
18
+
19
+
20
+ llm = ChatOpenAI(temperature=0, model='gpt-3.5-turbo-16k')
21
+ # If you already have embeddings stored , you can load it using below code
22
+ vector_search=Pinecone.from_existing_index("erginouswebsite",embeddings)
23
+
24
+ template = """You are provided with a content related to the company. You will be asked any question related to the company. If you don't know ,just say I don't know the answer'.
25
+ {context}
26
+ Question: {question}
27
+ Helpful Answer:"""
28
+ QA_CHAIN_PROMPT = PromptTemplate(input_variables=["question"],template=template)
29
+ qa = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=vector_search.as_retriever(),chain_type_kwargs={"prompt": QA_CHAIN_PROMPT})
30
+
31
+ def predict(message, history):
32
+ gpt_response = qa.invoke(message)
33
+ return gpt_response['result']
34
+
35
+ gr.ChatInterface(predict,chatbot=gr.Chatbot(height=300),
36
+ textbox=gr.Textbox(placeholder="Ask me a question", container=False, scale=7),
37
+ title="AI Assistant Chatbot",
38
+ description="Chatbot AI Assistant",
39
+ theme="soft",
40
+ examples=["Provide address of the company", "Solutions provided by the company", "Career opportunities in company"],
41
+ cache_examples=True,
42
+ retry_btn=None,
43
+ undo_btn="Delete Previous",
44
+ clear_btn="Clear",).launch(share=True , server_name="0.0.0.0" ,server_port=8080)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain_pinecone
2
+ python-dotenv
3
+ langchain_openai
4
+ gradio