Adding UI button for downloading report in docx format

This commit is contained in:
Priyadarshi Roy
2024-03-22 00:15:02 +05:30
parent 6c37a3c844
commit ad1c6e7d41
3 changed files with 13 additions and 7 deletions

View File

@@ -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.")

View File

@@ -96,7 +96,8 @@
<div id="reportActions">
<div class="alert alert-info" role="alert" id="status"></div>
<a id="copyToClipboard" onclick="GPTResearcher.copyToClipboard()" class="btn btn-secondary mt-3" style="margin-right: 10px;">Copy to clipboard</a>
<a id="downloadLink" href="#" class="btn btn-secondary mt-3" target="_blank">Download as PDF</a>
<a id="downloadLink" href="#" class="btn btn-secondary mt-3" style="margin-right: 10px;" target="_blank">Download as PDF</a>
<a id="downloadLinkWord" href="#" class="btn btn-secondary mt-3" target="_blank">Download as WORD</a>
</div>
</div>
</main>

View File

@@ -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 = () => {