Spaces:
Sleeping
Sleeping
Commit ·
135d47f
1
Parent(s): 3345ea7
Add pypandoc integration for proposal document conversion to DOCX
Browse files- poetry.lock +12 -1
- pyproject.toml +1 -0
- src/app.py +5 -1
poetry.lock
CHANGED
|
@@ -267,6 +267,17 @@ files = [
|
|
| 267 |
[package.dependencies]
|
| 268 |
typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
|
| 269 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
[[package]]
|
| 271 |
name = "python-dotenv"
|
| 272 |
version = "1.0.1"
|
|
@@ -355,4 +366,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"]
|
|
| 355 |
[metadata]
|
| 356 |
lock-version = "2.0"
|
| 357 |
python-versions = "3.12.*"
|
| 358 |
-
content-hash = "
|
|
|
|
| 267 |
[package.dependencies]
|
| 268 |
typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0"
|
| 269 |
|
| 270 |
+
[[package]]
|
| 271 |
+
name = "pypandoc"
|
| 272 |
+
version = "1.15"
|
| 273 |
+
description = "Thin wrapper for pandoc."
|
| 274 |
+
optional = false
|
| 275 |
+
python-versions = ">=3.7"
|
| 276 |
+
files = [
|
| 277 |
+
{file = "pypandoc-1.15-py3-none-any.whl", hash = "sha256:4ededcc76c8770f27aaca6dff47724578428eca84212a31479403a9731fc2b16"},
|
| 278 |
+
{file = "pypandoc-1.15.tar.gz", hash = "sha256:ea25beebe712ae41d63f7410c08741a3cab0e420f6703f95bc9b3a749192ce13"},
|
| 279 |
+
]
|
| 280 |
+
|
| 281 |
[[package]]
|
| 282 |
name = "python-dotenv"
|
| 283 |
version = "1.0.1"
|
|
|
|
| 366 |
[metadata]
|
| 367 |
lock-version = "2.0"
|
| 368 |
python-versions = "3.12.*"
|
| 369 |
+
content-hash = "1e3c817649f0d4f426ccd3d325fc43c1c13e7630bd9c8e979000d3c4215e4b2a"
|
pyproject.toml
CHANGED
|
@@ -12,6 +12,7 @@ uvicorn = "^0.34.0"
|
|
| 12 |
loguru = "^0.7.3"
|
| 13 |
python-dotenv = "^1.0.1"
|
| 14 |
aiosmtplib = "^3.0.2"
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
[build-system]
|
|
|
|
| 12 |
loguru = "^0.7.3"
|
| 13 |
python-dotenv = "^1.0.1"
|
| 14 |
aiosmtplib = "^3.0.2"
|
| 15 |
+
pypandoc = "^1.15"
|
| 16 |
|
| 17 |
|
| 18 |
[build-system]
|
src/app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import re
|
| 3 |
import tempfile
|
| 4 |
|
|
|
|
| 5 |
from fastapi import FastAPI, HTTPException
|
| 6 |
from pydantic import BaseModel
|
| 7 |
|
|
@@ -43,7 +44,10 @@ async def generate_proposal(data: dict):
|
|
| 43 |
)
|
| 44 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".md") as temp_file:
|
| 45 |
temp_file.write(proposal.encode())
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
| 47 |
recipient_email = os.getenv("RECIPIENT_EMAIL")
|
| 48 |
subject = f"Proposal for {data.get('project_name')}"
|
| 49 |
body = f"Hello,\n\nPlease find the proposal attached.\n\nBest,\nProposal Bot"
|
|
|
|
| 2 |
import re
|
| 3 |
import tempfile
|
| 4 |
|
| 5 |
+
import pypandoc
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
from pydantic import BaseModel
|
| 8 |
|
|
|
|
| 44 |
)
|
| 45 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".md") as temp_file:
|
| 46 |
temp_file.write(proposal.encode())
|
| 47 |
+
temp_file.flush()
|
| 48 |
+
docx_file_path = temp_file.name.replace(".md", ".docx")
|
| 49 |
+
pypandoc.convert_file(temp_file.name, "docx", outputfile=docx_file_path)
|
| 50 |
+
attachments = [docx_file_path]
|
| 51 |
recipient_email = os.getenv("RECIPIENT_EMAIL")
|
| 52 |
subject = f"Proposal for {data.get('project_name')}"
|
| 53 |
body = f"Hello,\n\nPlease find the proposal attached.\n\nBest,\nProposal Bot"
|