Abhaykoul commited on
Commit
b36f425
1 Parent(s): 3e45166

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -65,28 +65,23 @@ def main():
65
  sanitized_report = sanitize_text(report + "\n\n" + outro)
66
 
67
  # Display the sanitized report
68
- st.text(sanitized_report)
 
69
  # Add a copy button to copy the output
70
  if st.button('Copy Report'):
71
- # Inject custom JavaScript to copy text to clipboard
72
- st.markdown("""
73
- <script>
74
- function copyToClipboard(text) {
75
- var textarea = document.createElement("textarea");
76
- textarea.textContent = text;
77
- document.body.appendChild(textarea);
78
- textarea.select();
79
- document.execCommand("copy");
80
- document.body.removeChild(textarea);
81
- alert("Report copied to clipboard!");
82
- }
83
- document.querySelector("button[data-baseweb='button']").onclick = function() {
84
- copyToClipboard(document.querySelector("div[data-testid='stText']").innerText);
85
- }
86
- </script>
87
- """, unsafe_allow_html=True)
88
  else:
89
  st.sidebar.error("❗ Please enter a research query.")
90
 
91
  if __name__ == "__main__":
92
- main()
 
65
  sanitized_report = sanitize_text(report + "\n\n" + outro)
66
 
67
  # Display the sanitized report
68
+ report_element = st.text(sanitized_report)
69
+
70
  # Add a copy button to copy the output
71
  if st.button('Copy Report'):
72
+ # Use the newer clipboard API
73
+ try:
74
+ st.write("Copying report to clipboard...")
75
+ st.write(report_element)
76
+ st.write(sanitized_report)
77
+ st.write(type(sanitized_report))
78
+ st.write(len(sanitized_report))
79
+ await st.experimental_set_state({"report_copied": True})
80
+ await st.experimental_rerun()
81
+ except Exception as e:
82
+ st.error(f"Error copying report: {e}")
 
 
 
 
 
 
83
  else:
84
  st.sidebar.error("❗ Please enter a research query.")
85
 
86
  if __name__ == "__main__":
87
+ main()