LuisBlanche
commited on
Commit
•
752a11a
1
Parent(s):
d9403bf
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,15 @@ from io import BytesIO
|
|
4 |
import mechanicalsoup
|
5 |
import pandas as pd
|
6 |
import requests
|
|
|
|
|
7 |
from reportlab.lib import colors
|
8 |
from reportlab.lib.enums import TA_CENTER
|
9 |
from reportlab.lib.pagesizes import A4
|
10 |
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
|
11 |
from reportlab.lib.units import cm
|
12 |
-
from reportlab.platypus import (
|
13 |
-
|
14 |
-
Paragraph,
|
15 |
-
SimpleDocTemplate,
|
16 |
-
Spacer,
|
17 |
-
Table,
|
18 |
-
TableStyle,
|
19 |
-
)
|
20 |
from unidecode import unidecode
|
21 |
|
22 |
import gradio as gr
|
@@ -279,18 +275,12 @@ css = """
|
|
279 |
"""
|
280 |
|
281 |
|
282 |
-
def
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
canvas = Canvas(buffer, pagesize=A4)
|
289 |
-
canvas.showPage()
|
290 |
-
canvas.save()
|
291 |
-
buffer.seek(0)
|
292 |
-
pil_image = drawToPIL(Drawing)
|
293 |
-
return pil_image
|
294 |
|
295 |
|
296 |
def fetch_votes(deputy_name):
|
@@ -317,7 +307,7 @@ def generate_poster(deputy_name, message_1, message_2, vote_list):
|
|
317 |
|
318 |
# Generate a preview image of the first page
|
319 |
pdf_buffer.seek(0)
|
320 |
-
preview_image =
|
321 |
return preview_image, pdf_path
|
322 |
|
323 |
|
|
|
4 |
import mechanicalsoup
|
5 |
import pandas as pd
|
6 |
import requests
|
7 |
+
from PIL import Image as PILImage
|
8 |
+
from PIL import ImageDraw
|
9 |
from reportlab.lib import colors
|
10 |
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 (Image, Paragraph, SimpleDocTemplate, Spacer,
|
15 |
+
Table, TableStyle)
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
from unidecode import unidecode
|
17 |
|
18 |
import gradio as gr
|
|
|
275 |
"""
|
276 |
|
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('RGB', (2480, 3508), color = (255, 255, 255)) # A4 at 300 dpi
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
284 |
|
285 |
|
286 |
def fetch_votes(deputy_name):
|
|
|
307 |
|
308 |
# Generate a preview image of the first page
|
309 |
pdf_buffer.seek(0)
|
310 |
+
preview_image = create_pdf_preview(pdf_buffer)
|
311 |
return preview_image, pdf_path
|
312 |
|
313 |
|