Spaces:
Runtime error
Runtime error
Refactored and fixed UI layout
Browse files
kalbecdt_genomic_paper_extractor_proto/app.py
CHANGED
|
@@ -4,47 +4,53 @@ from dotenv import load_dotenv
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
from extractor import Answerer, Store
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
-
|
| 13 |
-
vec_store = Store("main")
|
| 14 |
vec_store.setup()
|
| 15 |
|
| 16 |
q_answerer = Answerer(vec_store)
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
def process_query(message, history, context_docs):
|
| 20 |
if len(history) == 0:
|
| 21 |
result, new_context_docs = q_answerer.answer_with_search(message)
|
| 22 |
new_context_docs = [
|
| 23 |
-
f"{os.path.basename(res.metadata['source'])}_{res.metadata['page']}"
|
| 24 |
for res in new_context_docs
|
| 25 |
]
|
| 26 |
-
|
| 27 |
-
return "", result, context_docs + new_context_docs
|
| 28 |
|
| 29 |
-
|
|
|
|
| 30 |
|
| 31 |
-
with gr.Blocks() as demo:
|
| 32 |
context_docs = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
with gr.Row():
|
| 34 |
-
with gr.Column(scale=1, min_width=100):
|
| 35 |
-
doc_explorer = gr.FileExplorer("*.pdf")
|
| 36 |
-
doc_upload = gr.File(label="Upload a doc")
|
| 37 |
-
doc_upload_btn = gr.Button("Upload")
|
| 38 |
with gr.Column(scale=2, min_width=400):
|
| 39 |
chat = gr.Chatbot(type="messages")
|
| 40 |
query_input = gr.Text(label="Chat input")
|
| 41 |
btn = gr.Button("Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
|
| 47 |
# Make it so every message makes a query, but filter for duplicate pages
|
| 48 |
|
| 49 |
-
demo.launch()
|
| 50 |
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
from extractor import Answerer, Store
|
| 7 |
+
from pdf_processor.pdf_processor import ProcessorPDF
|
| 8 |
+
from upload import Uploader
|
| 9 |
|
| 10 |
load_dotenv()
|
| 11 |
|
| 12 |
+
vec_store = Store("main", doc_k=5)
|
|
|
|
| 13 |
vec_store.setup()
|
| 14 |
|
| 15 |
q_answerer = Answerer(vec_store)
|
| 16 |
+
pdf_processor = ProcessorPDF()
|
| 17 |
+
doc_uploader = Uploader(pdf_processor, vec_store)
|
| 18 |
|
| 19 |
def process_query(message, history, context_docs):
|
| 20 |
if len(history) == 0:
|
| 21 |
result, new_context_docs = q_answerer.answer_with_search(message)
|
| 22 |
new_context_docs = [
|
| 23 |
+
{"id":f"{os.path.basename(res.metadata['source'])}_{res.metadata['page']}","text":res.page_content}
|
| 24 |
for res in new_context_docs
|
| 25 |
]
|
| 26 |
+
return "", result, new_context_docs, "\n".join([i["id"] for i in new_context_docs])
|
|
|
|
| 27 |
|
| 28 |
+
print(history[0]["role"])
|
| 29 |
+
return "", q_answerer.answer_without_search(message,history), context_docs, "\n".join([i["id"] for i in context_docs])
|
| 30 |
|
| 31 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 32 |
context_docs = gr.State([])
|
| 33 |
+
gr.Markdown(
|
| 34 |
+
"""
|
| 35 |
+
# Genomics Answering System
|
| 36 |
+
## **Every first question is used for the document query, and all questions after use the first question's context**
|
| 37 |
+
""")
|
| 38 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
with gr.Column(scale=2, min_width=400):
|
| 40 |
chat = gr.Chatbot(type="messages")
|
| 41 |
query_input = gr.Text(label="Chat input")
|
| 42 |
btn = gr.Button("Send")
|
| 43 |
+
with gr.Column(scale=1, min_width=100):
|
| 44 |
+
show_context = gr.Textbox(label="Docs in context", interactive=False)
|
| 45 |
+
doc_upload = gr.File(label="Upload a doc")
|
| 46 |
+
doc_upload_btn = gr.Button("Upload")
|
| 47 |
|
| 48 |
+
io_s = [query_input, chat, context_docs]
|
| 49 |
+
btn.click(process_query, io_s, io_s+[show_context])
|
| 50 |
+
query_input.submit(process_query, io_s, io_s+[show_context])
|
| 51 |
+
doc_upload_btn.click(doc_uploader.get_upload, doc_upload, doc_upload)
|
| 52 |
|
| 53 |
# Make it so every message makes a query, but filter for duplicate pages
|
| 54 |
|
| 55 |
+
demo.launch(share=True)
|
| 56 |
|