From ad1c6e7d41bd13ce4f0e52dc9262725284979860 Mon Sep 17 00:00:00 2001 From: Priyadarshi Roy Date: Fri, 22 Mar 2024 00:15:02 +0530 Subject: [PATCH] Adding UI button for downloading report in docx format --- backend/server.py | 10 +++++++--- frontend/index.html | 3 ++- frontend/scripts.js | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/backend/server.py b/backend/server.py index 5b49bbd..bb88e75 100644 --- a/backend/server.py +++ b/backend/server.py @@ -5,7 +5,7 @@ from pydantic import BaseModel import json import os from gpt_researcher.utils.websocket_manager import WebSocketManager -from .utils import write_md_to_pdf +from .utils import write_md_to_pdf, write_md_to_word class ResearchRequest(BaseModel): @@ -48,8 +48,12 @@ async def websocket_endpoint(websocket: WebSocket): report_type = json_data.get("report_type") if task and report_type: report = await manager.start_streaming(task, report_type, websocket) - path = await write_md_to_pdf(report) - await websocket.send_json({"type": "path", "output": path}) + # Saving report as pdf + pdf_path = await write_md_to_pdf(report) + # Saving report as docx + docx_path = await write_md_to_word(report) + # Returning the path of saved report files + await websocket.send_json({"type": "path", "output": {"pdf": pdf_path, "docx": docx_path}}) else: print("Error: not enough parameters provided.") diff --git a/frontend/index.html b/frontend/index.html index 6ef261f..f5fa1dc 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -96,7 +96,8 @@
Copy to clipboard - Download as PDF + Download as PDF + Download as WORD
diff --git a/frontend/scripts.js b/frontend/scripts.js index d46023d..78043f6 100644 --- a/frontend/scripts.js +++ b/frontend/scripts.js @@ -32,7 +32,6 @@ const GPTResearcher = (() => { } else if (data.type === 'path') { updateState("finished") updateDownloadLink(data); - } }; @@ -67,8 +66,10 @@ const GPTResearcher = (() => { }; const updateDownloadLink = (data) => { - const path = data.output; - document.getElementById("downloadLink").setAttribute("href", path); + const pdf_path = data.output.pdf; + const docx_path = data.output.docx; + document.getElementById("downloadLink").setAttribute("href", pdf_path); + document.getElementById("downloadLinkWord").setAttribute("href", docx_path); }; const updateScroll = () => {