LuisBlanche
commited on
Commit
•
54e6ce8
1
Parent(s):
7ed9b81
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ class PDFPoster:
|
|
44 |
):
|
45 |
df_subset = self.votes[self.votes["vote_topic"].isin(vote_list)]
|
46 |
|
47 |
-
pdf_filename = f"{self.deputy_name}.pdf"
|
48 |
document = SimpleDocTemplate(pdf_filename, pagesize=A4)
|
49 |
|
50 |
# Set up the styles
|
@@ -157,7 +157,12 @@ class PDFPoster:
|
|
157 |
vote_text,
|
158 |
]
|
159 |
document.build(elements)
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
def get_deputy_votes_page(self):
|
163 |
"""Fetches the webpage containing the voting records of a specified deputy.
|
@@ -297,17 +302,12 @@ def generate_poster(deputy_name, message_1, message_2, vote_list):
|
|
297 |
|
298 |
pdfposter = PDFPoster(deputy_name)
|
299 |
pdfposter.retrieve_deputy_data()
|
300 |
-
pdf_filename = pdfposter.generate_poster(vote_list, message_1, message_2)
|
301 |
-
|
302 |
-
# Move the PDF to a known location
|
303 |
-
static_dir = '/data'
|
304 |
-
os.makedirs(static_dir, exist_ok=True)
|
305 |
-
static_pdf_path = os.path.join(static_dir, pdf_filename)
|
306 |
-
shutil.move(pdf_filename, static_pdf_path)
|
307 |
|
|
|
308 |
# Create the iframe HTML to display the PDF
|
309 |
-
iframe_html = f'<iframe src="
|
310 |
-
return gr.HTML(iframe_html),
|
311 |
|
312 |
with gr.Blocks(css=css) as demo:
|
313 |
|
|
|
44 |
):
|
45 |
df_subset = self.votes[self.votes["vote_topic"].isin(vote_list)]
|
46 |
|
47 |
+
pdf_filename = f"/data/{self.deputy_name}.pdf"
|
48 |
document = SimpleDocTemplate(pdf_filename, pagesize=A4)
|
49 |
|
50 |
# Set up the styles
|
|
|
157 |
vote_text,
|
158 |
]
|
159 |
document.build(elements)
|
160 |
+
buffer.seek(0)
|
161 |
+
pdf_data = buffer.read()
|
162 |
+
buffer.close()
|
163 |
+
pdf_base64 = base64.b64encode(pdf_data).decode('utf-8')
|
164 |
+
|
165 |
+
return pdf_base64, pdf_filename
|
166 |
|
167 |
def get_deputy_votes_page(self):
|
168 |
"""Fetches the webpage containing the voting records of a specified deputy.
|
|
|
302 |
|
303 |
pdfposter = PDFPoster(deputy_name)
|
304 |
pdfposter.retrieve_deputy_data()
|
305 |
+
pdf_base64, pdf_filename = pdfposter.generate_poster(vote_list, message_1, message_2)
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
+
|
308 |
# Create the iframe HTML to display the PDF
|
309 |
+
iframe_html = f'<iframe src="data:application/pdf;base64,{pdf_base64}" width="100%" height="800px"></iframe>'
|
310 |
+
return gr.HTML(iframe_html), pdf_filename
|
311 |
|
312 |
with gr.Blocks(css=css) as demo:
|
313 |
|