themeetjani commited on
Commit
0ee5e57
1 Parent(s): 766875d

Update pages/AI_Chatbot.py

Browse files
Files changed (1) hide show
  1. pages/AI_Chatbot.py +6 -6
pages/AI_Chatbot.py CHANGED
@@ -13,9 +13,9 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
13
  from langchain.document_loaders import PyPDFLoader
14
  from langchain.chat_models import ChatOpenAI
15
 
 
16
  st.title("Chat with data")
17
  model = ChatOpenAI(model = 'gpt-4', max_tokens = 100,temperature=0)
18
-
19
  uploaded_file = st.file_uploader("Choose a file")
20
  if uploaded_file is not None:
21
  # Make temp file path from uploaded file
@@ -31,15 +31,15 @@ def extract(uploaded_file):
31
  res.append(i.page_content.replace('\n',''))
32
  a = " ".join(res)
33
  return a
34
- def lang(uploaded_file,ques):
35
- context = extract(uploaded_file)
36
  docs = Document(page_content=context)
37
  index2 = VectorstoreIndexCreator().from_documents([docs])
38
  answer = index2.query(llm = model, question = ques)
39
  index2.vectorstore.delete_collection()
40
  return answer
41
- def qna(uploaded_file,ques):
42
- session_state['answer']= lang(uploaded_file,ques)
43
 
44
  if 'answer' not in session_state:
45
  session_state['answer']= ""
@@ -49,4 +49,4 @@ ques= st.text_area(label= "Please enter the Question that you wanna ask.",
49
 
50
  st.text_area("result", value=session_state['answer'])
51
 
52
- st.button("Get answer dictionary", on_click=qna, args=[uploaded_file,ques])
 
13
  from langchain.document_loaders import PyPDFLoader
14
  from langchain.chat_models import ChatOpenAI
15
 
16
+
17
  st.title("Chat with data")
18
  model = ChatOpenAI(model = 'gpt-4', max_tokens = 100,temperature=0)
 
19
  uploaded_file = st.file_uploader("Choose a file")
20
  if uploaded_file is not None:
21
  # Make temp file path from uploaded file
 
31
  res.append(i.page_content.replace('\n',''))
32
  a = " ".join(res)
33
  return a
34
+ def lang(ques):
35
+ context = extract(tmp_file.name)
36
  docs = Document(page_content=context)
37
  index2 = VectorstoreIndexCreator().from_documents([docs])
38
  answer = index2.query(llm = model, question = ques)
39
  index2.vectorstore.delete_collection()
40
  return answer
41
+ def qna(ques):
42
+ session_state['answer']= lang(ques)
43
 
44
  if 'answer' not in session_state:
45
  session_state['answer']= ""
 
49
 
50
  st.text_area("result", value=session_state['answer'])
51
 
52
+ st.button("Get answer dictionary", on_click=qna, args=[ques])