cecilemacaire commited on
Commit
ae4476a
·
verified ·
1 Parent(s): 0120ffb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -69,6 +69,26 @@ def generate_html(ids):
69
  html_content += '</body></html>'
70
  return html_content
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  st.title("Traduction d'une phrase en pictogrammes ARASAAC")
73
  sentence = st.text_input("Entrez une phrase en français:")
74
  if sentence:
@@ -80,4 +100,9 @@ if sentence:
80
  pictogram_ids = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
81
 
82
  html = generate_html(pictogram_ids)
83
- st.components.v1.html(html, height=800, scrolling=True)
 
 
 
 
 
 
69
  html_content += '</body></html>'
70
  return html_content
71
 
72
+
73
+ def generate_pdf(ids):
74
+ pdf = FPDF()
75
+ pdf.add_page()
76
+ pdf.set_auto_page_break(auto=True, margin=15)
77
+
78
+ for picto_id, lemma in ids:
79
+ if picto_id != 0: # ignore invalid IDs
80
+ img_url = f"https://static.arasaac.org/pictograms/{picto_id}/{picto_id}_500.png"
81
+ pdf.image(img_url, x=None, y=None, w=50, h=50)
82
+ pdf.ln(55)
83
+ pdf.set_font("Arial", size=12)
84
+ pdf.cell(200, 10, txt=lemma, ln=True, align='C')
85
+
86
+ pdf_path = "pictograms.pdf"
87
+ pdf.output(pdf_path)
88
+ return pdf_path
89
+
90
+
91
+
92
  st.title("Traduction d'une phrase en pictogrammes ARASAAC")
93
  sentence = st.text_input("Entrez une phrase en français:")
94
  if sentence:
 
100
  pictogram_ids = [get_id_picto_from_predicted_lemma(lexicon, lemma) for lemma in sentence_to_map]
101
 
102
  html = generate_html(pictogram_ids)
103
+ st.components.v1.html(html, height=800, scrolling=True)
104
+
105
+ if st.button("Télécharger en PDF"):
106
+ pdf_path = generate_pdf(pictogram_ids)
107
+ with open(pdf_path, "rb") as pdf_file:
108
+ st.download_button(label="Télécharger le PDF", data=pdf_file, file_name="pictograms.pdf", mime="application/pdf")