tx3bas commited on
Commit
d6d3f42
verified
1 Parent(s): 10fb3da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -3,7 +3,9 @@ from mtranslate import translate
3
  import re
4
  import fitz # PyMuPDF
5
  import docx
 
6
 
 
7
  lang_dict = {
8
  'Espa帽ol': 'es',
9
  'English': 'en',
@@ -80,6 +82,23 @@ def read_docx(file):
80
  text = "\n".join([para.text for para in doc.paragraphs])
81
  return text
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def main():
84
  st.title("Traducci贸n sin l铆mites")
85
 
@@ -106,5 +125,23 @@ def main():
106
  # Bot贸n para copiar el texto traducido
107
  st.markdown(f'<button onclick="navigator.clipboard.writeText(`{translated_text}`)">Copiar al portapapeles</button>', unsafe_allow_html=True)
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  if __name__ == "__main__":
110
- main()
 
3
  import re
4
  import fitz # PyMuPDF
5
  import docx
6
+ from io import BytesIO
7
 
8
+ # Diccionario de idiomas y sus c贸digos
9
  lang_dict = {
10
  'Espa帽ol': 'es',
11
  'English': 'en',
 
82
  text = "\n".join([para.text for para in doc.paragraphs])
83
  return text
84
 
85
+ def save_pdf(text):
86
+ buffer = BytesIO()
87
+ doc = fitz.open()
88
+ page = doc.new_page()
89
+ page.insert_text((72, 72), text)
90
+ doc.save(buffer)
91
+ buffer.seek(0)
92
+ return buffer
93
+
94
+ def save_docx(text):
95
+ buffer = BytesIO()
96
+ doc = docx.Document()
97
+ doc.add_paragraph(text)
98
+ doc.save(buffer)
99
+ buffer.seek(0)
100
+ return buffer
101
+
102
  def main():
103
  st.title("Traducci贸n sin l铆mites")
104
 
 
125
  # Bot贸n para copiar el texto traducido
126
  st.markdown(f'<button onclick="navigator.clipboard.writeText(`{translated_text}`)">Copiar al portapapeles</button>', unsafe_allow_html=True)
127
 
128
+ if uploaded_file:
129
+ if uploaded_file.type == "application/pdf":
130
+ translated_file = save_pdf(translated_text)
131
+ st.download_button(
132
+ label="Descargar PDF traducido",
133
+ data=translated_file,
134
+ file_name="documento_traducido.pdf",
135
+ mime="application/pdf"
136
+ )
137
+ elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
138
+ translated_file = save_docx(translated_text)
139
+ st.download_button(
140
+ label="Descargar DOCX traducido",
141
+ data=translated_file,
142
+ file_name="documento_traducido.docx",
143
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
144
+ )
145
+
146
  if __name__ == "__main__":
147
+ main()