andregprospero commited on
Commit
a5db901
·
verified ·
1 Parent(s): 1bf136f

Upload 3 files

Browse files
Files changed (3) hide show
  1. Modelo_POP_v1.docx +0 -0
  2. app.py +24 -0
  3. requirements.txt +4 -0
Modelo_POP_v1.docx ADDED
Binary file (61 kB). View file
 
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ from fastapi.responses import FileResponse
3
+ from docxtpl import DocxTemplate
4
+ from pathlib import Path
5
+ import uuid
6
+
7
+ app = FastAPI()
8
+
9
+ @app.post("/generate-pop")
10
+ async def generate_pop(request: Request):
11
+ data = await request.json()
12
+
13
+ doc = DocxTemplate("Modelo_POP_v1.docx")
14
+ doc.render(data)
15
+
16
+ filename = f"POP_{uuid.uuid4().hex[:8]}.docx"
17
+ filepath = Path(filename)
18
+ doc.save(filepath)
19
+
20
+ return FileResponse(
21
+ path=filepath,
22
+ media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
23
+ filename=filename
24
+ )
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ docxtpl
4
+ python-multipart