ibrahim313 commited on
Commit
46d13ed
1 Parent(s): 50aa4eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -34,6 +34,17 @@ css = """
34
  color: red;
35
  font-weight: bold;
36
  }
 
 
 
 
 
 
 
 
 
 
 
37
  </style>
38
  """
39
 
@@ -114,11 +125,29 @@ if st.button("Generate Post"):
114
  if user_input:
115
  with st.spinner("Generating post..."):
116
  response = get_groq_response(post_type, user_input)
117
- st.success(response)
118
  else:
119
  st.error("Please enter a topic or idea!")
120
 
121
  # Allow users to copy the generated post
122
  if response:
123
  st.code(response)
124
- st.button("Copy to clipboard", on_click=st.experimental_rerun)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  color: red;
35
  font-weight: bold;
36
  }
37
+ .copy-btn {
38
+ background-color: #4CAF50;
39
+ color: white;
40
+ border: none;
41
+ padding: 10px 20px;
42
+ border-radius: 5px;
43
+ cursor: pointer;
44
+ }
45
+ .copy-btn:hover {
46
+ background-color: #45a049;
47
+ }
48
  </style>
49
  """
50
 
 
125
  if user_input:
126
  with st.spinner("Generating post..."):
127
  response = get_groq_response(post_type, user_input)
128
+ st.success("Post generated successfully!")
129
  else:
130
  st.error("Please enter a topic or idea!")
131
 
132
  # Allow users to copy the generated post
133
  if response:
134
  st.code(response)
135
+
136
+ # Add a Copy to Clipboard button using HTML and JavaScript
137
+ copy_button_code = f"""
138
+ <button class="copy-btn" onclick="copyToClipboard()">Copy to Clipboard</button>
139
+ <script>
140
+ function copyToClipboard() {{
141
+ var text = `{response}`;
142
+ var tempInput = document.createElement("textarea");
143
+ document.body.appendChild(tempInput);
144
+ tempInput.value = text;
145
+ tempInput.select();
146
+ document.execCommand("copy");
147
+ document.body.removeChild(tempInput);
148
+ alert("Copied to clipboard!");
149
+ }}
150
+ </script>
151
+ """
152
+
153
+ html(copy_button_code, unsafe_allow_html=True)