LuisBlanche
commited on
Commit
•
b6a9bcf
1
Parent(s):
752a11a
Update app.py
Browse files
app.py
CHANGED
@@ -11,8 +11,14 @@ from reportlab.lib.enums import TA_CENTER
|
|
11 |
from reportlab.lib.pagesizes import A4
|
12 |
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
|
13 |
from reportlab.lib.units import cm
|
14 |
-
from reportlab.platypus import (
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
from unidecode import unidecode
|
17 |
|
18 |
import gradio as gr
|
@@ -150,7 +156,6 @@ class PDFPoster:
|
|
150 |
vote_text,
|
151 |
]
|
152 |
document.build(elements)
|
153 |
-
buffer = BytesIO()
|
154 |
|
155 |
buffer.seek(0)
|
156 |
|
@@ -277,7 +282,7 @@ css = """
|
|
277 |
|
278 |
def create_pdf_preview(pdf_buffer):
|
279 |
# Create an image with PIL to simulate the first page of the PDF
|
280 |
-
image = PILImage.new(
|
281 |
draw = ImageDraw.Draw(image)
|
282 |
draw.text((10, 10), "This is a preview of the PDF content", fill=(0, 0, 0))
|
283 |
return image
|
@@ -301,9 +306,6 @@ def generate_poster(deputy_name, message_1, message_2, vote_list):
|
|
301 |
pdfposter = PDFPoster(deputy_name)
|
302 |
pdfposter.retrieve_deputy_data()
|
303 |
pdf_buffer = pdfposter.generate_poster(vote_list, message_1, message_2)
|
304 |
-
pdf_path = f"/data/{deputy_name}.pdf"
|
305 |
-
with open(pdf_path, "wb") as f:
|
306 |
-
f.write(pdf_buffer.getvalue())
|
307 |
|
308 |
# Generate a preview image of the first page
|
309 |
pdf_buffer.seek(0)
|
|
|
11 |
from reportlab.lib.pagesizes import A4
|
12 |
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
|
13 |
from reportlab.lib.units import cm
|
14 |
+
from reportlab.platypus import (
|
15 |
+
Image,
|
16 |
+
Paragraph,
|
17 |
+
SimpleDocTemplate,
|
18 |
+
Spacer,
|
19 |
+
Table,
|
20 |
+
TableStyle,
|
21 |
+
)
|
22 |
from unidecode import unidecode
|
23 |
|
24 |
import gradio as gr
|
|
|
156 |
vote_text,
|
157 |
]
|
158 |
document.build(elements)
|
|
|
159 |
|
160 |
buffer.seek(0)
|
161 |
|
|
|
282 |
|
283 |
def create_pdf_preview(pdf_buffer):
|
284 |
# Create an image with PIL to simulate the first page of the PDF
|
285 |
+
image = PILImage.new("RGB", (2480, 3508), color=(255, 255, 255)) # A4 at 300 dpi
|
286 |
draw = ImageDraw.Draw(image)
|
287 |
draw.text((10, 10), "This is a preview of the PDF content", fill=(0, 0, 0))
|
288 |
return image
|
|
|
306 |
pdfposter = PDFPoster(deputy_name)
|
307 |
pdfposter.retrieve_deputy_data()
|
308 |
pdf_buffer = pdfposter.generate_poster(vote_list, message_1, message_2)
|
|
|
|
|
|
|
309 |
|
310 |
# Generate a preview image of the first page
|
311 |
pdf_buffer.seek(0)
|