deepozzzie commited on
Commit
f9a51f1
·
1 Parent(s): 90d9fe0

add messages

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -23,12 +23,19 @@ def pdf_changes(pdf_doc, open_ai_key):
23
  if openai_key is not None:
24
  os.environ['OPENAI_API_KEY'] = open_ai_key
25
  loader = OnlinePDFLoader(pdf_doc.name)
 
26
  documents = loader.load()
 
27
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
 
28
  texts = text_splitter.split_documents(documents)
 
29
  embeddings = OpenAIEmbeddings()
 
30
  db = Chroma.from_documents(texts, embeddings)
 
31
  retriever = db.as_retriever()
 
32
  global qa
33
  qa = ConversationalRetrievalChain.from_llm(
34
  llm=OpenAI(temperature=0.5),
@@ -40,15 +47,20 @@ def pdf_changes(pdf_doc, open_ai_key):
40
 
41
  def add_text(history, text):
42
  history = history + [(text, None)]
 
43
  return history, ""
44
 
45
  def bot(history):
46
  response = infer(history[-1][0], history)
 
 
47
  history[-1][1] = ""
48
 
49
  for character in response:
50
  history[-1][1] += character
 
51
  time.sleep(0.05)
 
52
  yield history
53
 
54
 
@@ -64,6 +76,8 @@ def infer(question, history):
64
  query = question
65
  result = qa({"question": query, "chat_history": chat_history})
66
  #print(result)
 
 
67
  return result["answer"]
68
 
69
  css="""
 
23
  if openai_key is not None:
24
  os.environ['OPENAI_API_KEY'] = open_ai_key
25
  loader = OnlinePDFLoader(pdf_doc.name)
26
+ print(loader)
27
  documents = loader.load()
28
+ print(documents)
29
  text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
30
+ print(text_splitter)
31
  texts = text_splitter.split_documents(documents)
32
+ print(texts)
33
  embeddings = OpenAIEmbeddings()
34
+ print(embeddings)
35
  db = Chroma.from_documents(texts, embeddings)
36
+ print(db)
37
  retriever = db.as_retriever()
38
+ print(retriever)
39
  global qa
40
  qa = ConversationalRetrievalChain.from_llm(
41
  llm=OpenAI(temperature=0.5),
 
47
 
48
  def add_text(history, text):
49
  history = history + [(text, None)]
50
+ print(history)
51
  return history, ""
52
 
53
  def bot(history):
54
  response = infer(history[-1][0], history)
55
+ print('bot response:')
56
+ print(response)
57
  history[-1][1] = ""
58
 
59
  for character in response:
60
  history[-1][1] += character
61
+ print("history")
62
  time.sleep(0.05)
63
+ print(history)
64
  yield history
65
 
66
 
 
76
  query = question
77
  result = qa({"question": query, "chat_history": chat_history})
78
  #print(result)
79
+ print("infer result")
80
+ print(result)
81
  return result["answer"]
82
 
83
  css="""