tx3bas commited on
Commit
c2cfdef
·
verified ·
1 Parent(s): 7af5714

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -78,13 +78,27 @@ def main():
78
  translated_text = translate_text(lang, text)
79
 
80
  # Mostrar el resultado con el botón de copia
81
- html_output = f"""
82
- <div>
83
- <span id='translated_text'>{translated_text}</span>
84
- <button class="lg secondary svelte-cmf5ev" style="font-size: small; padding: 2px; color: #808080ba; border: none; margin-left: 5px;" onclick='navigator.clipboard.writeText(document.getElementById("translated_text").innerText).then(() => alert("Texto copiado al portapapeles"))'>&nbsp;✂&nbsp;</button>
85
- </div>
86
- """
87
- st.markdown(html_output, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
- if __name__ == "__main__":
90
- main()
 
78
  translated_text = translate_text(lang, text)
79
 
80
  # Mostrar el resultado con el botón de copia
81
+ st.session_state.translated_text = translated_text
82
+ st.write("Texto traducido:")
83
+ st.write(translated_text)
84
+
85
+ # Mostrar el botón de copiar
86
+ copy_button = """
87
+ <button onclick="copyToClipboard()">Copiar</button>
88
+ <script>
89
+ function copyToClipboard() {
90
+ var text = `{}`;
91
+ navigator.clipboard.writeText(text).then(function() {
92
+ alert('Texto copiado al portapapeles');
93
+ }, function(err) {
94
+ console.error('No se pudo copiar el texto: ', err);
95
+ });
96
+ }
97
+ </script>
98
+ """.format(translated_text.replace("\n", "\\n").replace("'", "\\'"))
99
+ st.markdown(copy_button, unsafe_allow_html=True)
100
+
101
+ if "translated_text" not in st.session_state:
102
+ st.session_state.translated_text = ""
103
 
104
+ main()