Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,11 @@ def get_id_picto_from_predicted_lemma(df_lexicon, lemma):
|
|
| 39 |
def generate_html(ids):
|
| 40 |
html_content = '<html><head><style>'
|
| 41 |
html_content += '''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
figure {
|
| 43 |
display: inline-block;
|
| 44 |
text-align: center;
|
|
@@ -72,18 +77,35 @@ def generate_html(ids):
|
|
| 72 |
|
| 73 |
|
| 74 |
def generate_pdf(ids):
|
| 75 |
-
pdf = FPDF()
|
| 76 |
pdf.add_page()
|
| 77 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
for picto_id, lemma in ids:
|
| 80 |
if picto_id != 0: # ignore invalid IDs
|
| 81 |
img_url = f"https://static.arasaac.org/pictograms/{picto_id}/{picto_id}_500.png"
|
| 82 |
-
pdf.image(img_url, x=
|
| 83 |
-
pdf.
|
| 84 |
pdf.set_font("Arial", size=12)
|
| 85 |
-
pdf.cell(
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
pdf_path = "pictograms.pdf"
|
| 88 |
pdf.output(pdf_path)
|
| 89 |
return pdf_path
|
|
@@ -104,8 +126,6 @@ if sentence:
|
|
| 104 |
st.components.v1.html(html, height=800, scrolling=True)
|
| 105 |
|
| 106 |
# Container to hold the download button
|
| 107 |
-
|
| 108 |
-
with
|
| 109 |
-
|
| 110 |
-
with open(pdf_path, "rb") as pdf_file:
|
| 111 |
-
st.download_button(label="Télécharger la traduction en PDF", data=pdf_file, file_name="pictograms.pdf", mime="application/pdf")
|
|
|
|
| 39 |
def generate_html(ids):
|
| 40 |
html_content = '<html><head><style>'
|
| 41 |
html_content += '''
|
| 42 |
+
body {
|
| 43 |
+
display: flex;
|
| 44 |
+
flex-wrap: wrap;
|
| 45 |
+
justify-content: center;
|
| 46 |
+
}
|
| 47 |
figure {
|
| 48 |
display: inline-block;
|
| 49 |
text-align: center;
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
def generate_pdf(ids):
|
| 80 |
+
pdf = FPDF(orientation='L', unit='mm', format='A4') # 'L' for landscape orientation
|
| 81 |
pdf.add_page()
|
| 82 |
pdf.set_auto_page_break(auto=True, margin=15)
|
| 83 |
|
| 84 |
+
# Start positions
|
| 85 |
+
x_start = 10
|
| 86 |
+
y_start = 10
|
| 87 |
+
img_width = 50
|
| 88 |
+
img_height = 50
|
| 89 |
+
spacing = 10
|
| 90 |
+
max_width = 297 # A4 landscape width in mm
|
| 91 |
+
current_x = x_start
|
| 92 |
+
current_y = y_start
|
| 93 |
+
|
| 94 |
for picto_id, lemma in ids:
|
| 95 |
if picto_id != 0: # ignore invalid IDs
|
| 96 |
img_url = f"https://static.arasaac.org/pictograms/{picto_id}/{picto_id}_500.png"
|
| 97 |
+
pdf.image(img_url, x=current_x, y=current_y, w=img_width, h=img_height)
|
| 98 |
+
pdf.set_xy(current_x, current_y + img_height + 5)
|
| 99 |
pdf.set_font("Arial", size=12)
|
| 100 |
+
pdf.cell(img_width, 10, txt=lemma, ln=1, align='C')
|
| 101 |
+
|
| 102 |
+
current_x += img_width + spacing
|
| 103 |
+
|
| 104 |
+
# Move to the next line if exceeds max width
|
| 105 |
+
if current_x + img_width > max_width:
|
| 106 |
+
current_x = x_start
|
| 107 |
+
current_y += img_height + spacing + 10 # Adjust for image height and some spacing
|
| 108 |
+
|
| 109 |
pdf_path = "pictograms.pdf"
|
| 110 |
pdf.output(pdf_path)
|
| 111 |
return pdf_path
|
|
|
|
| 126 |
st.components.v1.html(html, height=800, scrolling=True)
|
| 127 |
|
| 128 |
# Container to hold the download button
|
| 129 |
+
pdf_path = generate_pdf(pictogram_ids)
|
| 130 |
+
with open(pdf_path, "rb") as pdf_file:
|
| 131 |
+
st.download_button(label="Télécharger la traduction en PDF", data=pdf_file, file_name="pictograms.pdf", mime="application/pdf")
|
|
|
|
|
|