lekkalar commited on
Commit
ecdabf6
1 Parent(s): e977a64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -25
app.py CHANGED
@@ -33,31 +33,10 @@ def pdf_changes(pdf_doc, open_ai_key):
33
  else:
34
  return "Please provide an OpenAI API key"
35
 
36
- def add_text(history, text):
37
- history = history + [(text, None)]
38
- return history, ""
39
 
40
- def bot(history):
41
- response = infer(history[-1][0], history)
42
- history[-1][1] = ""
43
-
44
- for character in response:
45
- history[-1][1] += character
46
- time.sleep(0.05)
47
- yield history
48
-
49
-
50
- def infer(question, history):
51
-
52
- results = []
53
- for human, ai in history[:-1]:
54
- pair = (human, ai)
55
- results.append(pair)
56
-
57
- chat_history = results
58
- print(chat_history)
59
  query = question
60
- result = pdf_qa({"question": query, "chat_history": chat_history})
61
  print(result)
62
  return result["answer"]
63
 
@@ -91,10 +70,10 @@ with gr.Blocks(css=css) as demo:
91
  submit_btn = gr.Button("Send Message")
92
  load_pdf.click(loading_pdf, None, langchain_status, queue=False)
93
  load_pdf.click(pdf_changes, inputs=[pdf_doc, openai_key], outputs=[langchain_status], queue=False)
94
- question.submit(add_text, [chatbot, question], [chatbot, question]).then(
95
  bot, chatbot, chatbot
96
  )
97
- submit_btn.click(add_text, [chatbot, question], [chatbot, question]).then(
98
  bot, chatbot, chatbot)
99
 
100
  demo.launch()
 
33
  else:
34
  return "Please provide an OpenAI API key"
35
 
 
 
 
36
 
37
+ def infer(question):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  query = question
39
+ result = pdf_qa({"question": query})
40
  print(result)
41
  return result["answer"]
42
 
 
70
  submit_btn = gr.Button("Send Message")
71
  load_pdf.click(loading_pdf, None, langchain_status, queue=False)
72
  load_pdf.click(pdf_changes, inputs=[pdf_doc, openai_key], outputs=[langchain_status], queue=False)
73
+ question.submit( [chatbot, question], [chatbot, question]).then(
74
  bot, chatbot, chatbot
75
  )
76
+ submit_btn.click( [chatbot, question], [chatbot, question]).then(
77
  bot, chatbot, chatbot)
78
 
79
  demo.launch()