diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2024-04-08 00:23:52 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2024-04-08 00:23:52 +0200 |
commit | 8211705debf9d1335223c606275f46c43c78d8a2 (patch) | |
tree | f09f902c7d31b2035813c42cbb4a47e720fa363b /rag/ui.py | |
parent | 95f47c4900a96d91daaef93bf87094ed3d4da43c (diff) |
Updates
Diffstat (limited to 'rag/ui.py')
-rw-r--r-- | rag/ui.py | 39 |
1 files changed, 35 insertions, 4 deletions
@@ -1,8 +1,14 @@ import streamlit as st +from langchain_community.document_loaders.blob_loaders import Blob + +try: + from rag.rag import RAG +except ModuleNotFoundError: + from rag import RAG + +rag = RAG() -# from loguru import logger as log -# from rag.rag import RAG def upload_pdfs(): files = st.file_uploader( @@ -11,10 +17,35 @@ def upload_pdfs(): accept_multiple_files=True, ) for file in files: - bytes = file.read() - st.write(bytes) + blob = Blob.from_data(file.read()) + rag.add_pdf_from_blob(blob) if __name__ == "__main__": st.header("RAG-UI") + upload_pdfs() + query = st.text_area( + "query", + key="query", + height=100, + placeholder="Enter query here", + help="", + label_visibility="collapsed", + disabled=False, + ) + + (result_column, context_column) = st.columns(2) + + if query: + response = rag.retrive(query) + + with result_column: + st.markdown("### Answer") + st.markdown(response.answer) + + with context_column: + st.markdown("### Context") + for c in response.context: + st.markdown(c) + st.markdown("---") |