fffiloni commited on
Commit
9814f59
1 Parent(s): e348efe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -15,16 +15,33 @@ from langchain.vectorstores import Chroma
15
 
16
  from langchain.chains import RetrievalQA
17
 
18
- def infer(pdf_doc):
19
  loader = OnlinePDFLoader(pdf_doc)
20
  documents = loader.load()
21
  texts = text_splitter.split_documents(documents)
22
  db = Chroma.from_documents(texts, embeddings)
23
  retriever = db.as_retriever()
24
  qa = RetrievalQA.from_chain_type(llm=flan_ul2, chain_type="stuff", retriever=retriever, return_source_documents=True)
25
- query = "What is the title of this paper?"
 
 
 
 
26
  result = qa({"query": query})
27
 
28
  return result
29
 
30
- gr.Interface(fn=infer, inputs=[gr.Textbox(value="https://arxiv.org/pdf/2304.03757.pdf")], outputs=[gr.Textbox()]).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  from langchain.chains import RetrievalQA
17
 
18
+ def pdf_changes(pdf_doc):
19
  loader = OnlinePDFLoader(pdf_doc)
20
  documents = loader.load()
21
  texts = text_splitter.split_documents(documents)
22
  db = Chroma.from_documents(texts, embeddings)
23
  retriever = db.as_retriever()
24
  qa = RetrievalQA.from_chain_type(llm=flan_ul2, chain_type="stuff", retriever=retriever, return_source_documents=True)
25
+ return "Ready"
26
+
27
+ def infer(question):
28
+
29
+ query = question
30
  result = qa({"query": query})
31
 
32
  return result
33
 
34
+ with gr.Blocks() as demo:
35
+ with gr.Column():
36
+ pdf_doc = gr.File(label="Load a pdf")
37
+ langchain_status = gr.Textbox()
38
+ pdf_doc.change(pdf_changes, pdf_doc, langchain_status, queue=False)
39
+ question = gr.Textbox(label="Your Question")
40
+ answer = gr.Textbox(label="Anwser")
41
+ submit_button = gr.Button("Send Question")
42
+
43
+ pdf_doc.change(pdf_changes, pdf_doc, langchain_status, queue=False)
44
+ submit_button.click(infer, inputs=[question], outputs=[answer])
45
+
46
+
47
+ demo.launch()