From 5d405a3fc5b8631c3ab8b7223faa3198b54cbb64 Mon Sep 17 00:00:00 2001 From: TripZz Date: Thu, 31 Oct 2024 20:20:14 +0100 Subject: [PATCH] NN-605 Adding AI enrich button to document window -bridge frontend/backend with enriched data --- backend/src/main.py | 10 ++++++++++ frontend/src/components/DocumentWindow.vue | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/backend/src/main.py b/backend/src/main.py index 0d6e4102..e77a889f 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -186,6 +186,16 @@ def chatbot_response(): return Response(response, mimetype="application/json") +# ====================== AI enrich text ====================== +# TODO Refactor this +# Request comes from ContextSection.vue +@app.route("/api/subgraph/textenrich", methods=["POST"]) +def enrich_text(): + content = request.form.get("content") + + return Response(json.dumps(content), mimetype="application/json") + + # ====================== Subgraph API ====================== # request comes from home.js # TODO Refactor this diff --git a/frontend/src/components/DocumentWindow.vue b/frontend/src/components/DocumentWindow.vue index 2b934dbb..98889506 100644 --- a/frontend/src/components/DocumentWindow.vue +++ b/frontend/src/components/DocumentWindow.vue @@ -68,6 +68,7 @@
+
@@ -89,6 +90,9 @@ export default { pathways: [], proteins: [], tags: [], + api: { + textenrich: "api/subgraph/textenrich", + }, }; }, computed: { @@ -168,14 +172,12 @@ export default { } }, addTag(bullet) { - console.log(bullet.data); if (bullet.type == "protein") this.addBullet(bullet.data.label); if (bullet.type == "subset") this.addBullet( `${bullet.id} (${bullet.data.map((node) => node.label).join(", ")})` ); if (bullet.type == "term") this.addBullet(bullet.data.name); - console.log(bullet); }, addImage(imgURL) { var selection = quill.getSelection(true); @@ -211,6 +213,17 @@ export default { ); saveAs(docAsBlob, "word-export.docx"); }, + async textImprove() { + const delta = quill.getContents(); + var com = this; + + var formData = new FormData(); + formData.append("content", JSON.stringify(delta.ops)); + + com.axios.post(com.api.textenrich, formData).then((response) => { + console.log(response); + }); + }, dragElement(elmnt) { var pos1 = 0, pos2 = 0, @@ -362,7 +375,7 @@ export default { .export-bar { color: white; - padding: 15px; + padding: 1%; width: 99%; display: flex; justify-content: end; @@ -375,6 +388,7 @@ export default { .export-bar button { padding: 8px 16px; + margin-left: 2%; background-color: #007bff; color: white; border: none;