From 3dfd2ac4ea0d60def52a0e99cf0ff88beef6b837 Mon Sep 17 00:00:00 2001 From: Harsha Ramayanam Date: Tue, 4 Feb 2025 09:43:24 -0800 Subject: [PATCH 1/4] Added logic for showing/deleting files from vector store Signed-off-by: Harsha Ramayanam --- .../intel/cpu/xeon/compose.yaml | 2 + .../ui/gradio/multimodalqna_ui_gradio.py | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/MultimodalQnA/docker_compose/intel/cpu/xeon/compose.yaml b/MultimodalQnA/docker_compose/intel/cpu/xeon/compose.yaml index 31f543c75..6eb97ebc3 100644 --- a/MultimodalQnA/docker_compose/intel/cpu/xeon/compose.yaml +++ b/MultimodalQnA/docker_compose/intel/cpu/xeon/compose.yaml @@ -169,6 +169,8 @@ services: - DATAPREP_INGEST_SERVICE_ENDPOINT=${DATAPREP_INGEST_SERVICE_ENDPOINT} - DATAPREP_GEN_TRANSCRIPT_SERVICE_ENDPOINT=${DATAPREP_GEN_TRANSCRIPT_SERVICE_ENDPOINT} - DATAPREP_GEN_CAPTION_SERVICE_ENDPOINT=${DATAPREP_GEN_CAPTION_SERVICE_ENDPOINT} + - DATAPREP_GET_FILE_ENDPOINT=${DATAPREP_GET_FILE_ENDPOINT} + - DATAPREP_DELETE_FILE_ENDPOINT=${DATAPREP_DELETE_FILE_ENDPOINT} - MEGA_SERVICE_PORT:=${MEGA_SERVICE_PORT} - UI_PORT=${UI_PORT} - DATAPREP_MMR_PORT=${DATAPREP_MMR_PORT} diff --git a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py index 7919ce591..c2bb15bb0 100644 --- a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py +++ b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py @@ -430,6 +430,32 @@ def hide_text(request: gr.Request): def clear_text(request: gr.Request): return None +def get_files(): + try: + response = requests.post(dataprep_get_file_addr, headers=headers) + logger.info(response.status_code) + files = response.json() + html_content = "" + yield ( + gr.HTML(html_content, visible=True, max_height=200) + ) + return + except Exception as e: + logger.info(f"Error getting files from vector store: {str(e)}") + +def delete_files(): + import json + data = { "file_path": "all" } + try: + response = requests.post(dataprep_delete_file_addr, headers=headers, data=json.dumps(data)) + logger.info(response.status_code) + yield ( + gr.update(value="Deleted all files!") + ) + return + except Exception as e: + logger.info(f"Error deleting files from vector store: {str(e)}") + with gr.Blocks() as upload_video: gr.Markdown("# Ingest Videos Using Generated Transcripts or Captions") @@ -577,6 +603,19 @@ def select_upload_type(choice, request: gr.Request): ], [state, chatbot, video, image, pdf, clear_btn], ) + +with gr.Blocks() as vector_store: + gr.Markdown("# Uploaded Files") + + with gr.Row(): + with gr.Column(scale=6): + files = gr.HTML(visible=False) + with gr.Column(scale=3): + refresh_btn = gr.Button(value="↻ Refresh", interactive=True, variant="primary") + delete_btn = gr.Button(value="🗑️ Delete", interactive=True, variant="stop") + refresh_btn.click(get_files, None, [files]) + delete_btn.click(delete_files, None, [files]) + with gr.Blocks(css=css) as demo: gr.Markdown("# MultimodalQnA") with gr.Tabs(): @@ -590,6 +629,8 @@ def select_upload_type(choice, request: gr.Request): upload_audio.render() with gr.TabItem("Upload PDF"): upload_pdf.render() + with gr.TabItem("Vector Store"): + vector_store.render() demo.queue() app = gr.mount_gradio_app(app, demo, path="/") @@ -618,6 +659,12 @@ def select_upload_type(choice, request: gr.Request): dataprep_gen_caption_endpoint = os.getenv( "DATAPREP_GEN_CAPTION_SERVICE_ENDPOINT", f"http://localhost:{DATAPREP_MMR_PORT}/v1/generate_captions" ) + dataprep_get_file_endpoint = os.getenv( + "DATAPREP_GET_FILE_ENDPOINT", f"http://localhost:{DATAPREP_MMR_PORT}/v1/dataprep/get" + ) + dataprep_delete_file_endpoint = os.getenv( + "DATAPREP_DELETE_FILE_ENDPOINT", f"http://localhost:{DATAPREP_MMR_PORT}/v1/dataprep/delete" + ) args = parser.parse_args() logger.info(f"args: {args}") global gateway_addr @@ -628,5 +675,9 @@ def select_upload_type(choice, request: gr.Request): dataprep_gen_transcript_addr = dataprep_gen_transcript_endpoint global dataprep_gen_caption_addr dataprep_gen_caption_addr = dataprep_gen_caption_endpoint + global dataprep_get_file_addr + dataprep_get_file_addr = dataprep_get_file_endpoint + global dataprep_delete_file_addr + dataprep_delete_file_addr = dataprep_delete_file_endpoint uvicorn.run(app, host=args.host, port=args.port) From 4dd7ef5958c29a1b14d907e2fec61c44679fcff2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 4 Feb 2025 17:48:17 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../ui/gradio/multimodalqna_ui_gradio.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py index c2bb15bb0..abaac047b 100644 --- a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py +++ b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py @@ -430,28 +430,27 @@ def hide_text(request: gr.Request): def clear_text(request: gr.Request): return None + def get_files(): try: response = requests.post(dataprep_get_file_addr, headers=headers) logger.info(response.status_code) files = response.json() html_content = "" - yield ( - gr.HTML(html_content, visible=True, max_height=200) - ) + yield (gr.HTML(html_content, visible=True, max_height=200)) return except Exception as e: logger.info(f"Error getting files from vector store: {str(e)}") - + + def delete_files(): import json - data = { "file_path": "all" } + + data = {"file_path": "all"} try: response = requests.post(dataprep_delete_file_addr, headers=headers, data=json.dumps(data)) logger.info(response.status_code) - yield ( - gr.update(value="Deleted all files!") - ) + yield (gr.update(value="Deleted all files!")) return except Exception as e: logger.info(f"Error deleting files from vector store: {str(e)}") @@ -606,7 +605,7 @@ def select_upload_type(choice, request: gr.Request): with gr.Blocks() as vector_store: gr.Markdown("# Uploaded Files") - + with gr.Row(): with gr.Column(scale=6): files = gr.HTML(visible=False) @@ -615,7 +614,7 @@ def select_upload_type(choice, request: gr.Request): delete_btn = gr.Button(value="🗑️ Delete", interactive=True, variant="stop") refresh_btn.click(get_files, None, [files]) delete_btn.click(delete_files, None, [files]) - + with gr.Blocks(css=css) as demo: gr.Markdown("# MultimodalQnA") with gr.Tabs(): From 2ed821e9243f1ff84df1a6931373f39281ff4ca0 Mon Sep 17 00:00:00 2001 From: Harsha Ramayanam Date: Tue, 4 Feb 2025 10:57:01 -0800 Subject: [PATCH 3/4] Added message to show when vector store is empty Signed-off-by: Harsha Ramayanam --- .../ui/gradio/multimodalqna_ui_gradio.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py index c2bb15bb0..987ae7c75 100644 --- a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py +++ b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py @@ -435,11 +435,17 @@ def get_files(): response = requests.post(dataprep_get_file_addr, headers=headers) logger.info(response.status_code) files = response.json() - html_content = "
    " + "".join(f"
  • {item}
  • " for item in files) + "
" - yield ( - gr.HTML(html_content, visible=True, max_height=200) - ) - return + if files: + html_content = "
    " + "".join(f"
  • {item}
  • " for item in files) + "
" + yield ( + gr.HTML(html_content, visible=True, max_height=200) + ) + return + else: + yield ( + gr.HTML("Vector store is empty!", visible=True) + ) + return except Exception as e: logger.info(f"Error getting files from vector store: {str(e)}") From bb3a540729c0254c9bd72060b59f781bda6a6bc3 Mon Sep 17 00:00:00 2001 From: Harsha Ramayanam Date: Tue, 4 Feb 2025 11:03:46 -0800 Subject: [PATCH 4/4] Update MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py Co-authored-by: Dina Suehiro Jones --- MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py index deb79826e..1ba4f43c2 100644 --- a/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py +++ b/MultimodalQnA/ui/gradio/multimodalqna_ui_gradio.py @@ -444,7 +444,7 @@ def get_files(): return else: yield ( - gr.HTML("Vector store is empty!", visible=True) + gr.HTML("Vector store is empty.", visible=True) ) return except Exception as e: