saad-sust commited on
Commit
c45f5d7
Β·
verified Β·
1 Parent(s): 0e8cd77

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -175,6 +175,25 @@ html, body, [class*="css"] {
175
  background: #161b2e !important;
176
  }
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  /* ── Spinner ── */
179
  .stSpinner > div { border-top-color: #3b82f6 !important; }
180
 
@@ -1889,14 +1908,28 @@ for i, msg in enumerate(st.session_state.messages):
1889
  avatar = "πŸ§‘β€πŸŽ“" if msg["role"] == "user" else "πŸ“"
1890
  with st.chat_message(msg["role"], avatar=avatar):
1891
  st.markdown(msg["content"])
1892
- # Copy button on AI responses
1893
  if msg["role"] == "assistant":
1894
- if st.button("πŸ“‹ Copy", key=f"copy_{i}", help="Copy response"):
1895
- st.write(
1896
- f'<script>navigator.clipboard.writeText({repr(msg["content"])})</script>',
1897
- unsafe_allow_html=True
1898
- )
1899
- st.toast("βœ… Copied!", icon="πŸ“‹")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1900
 
1901
  # ════════════════════════════════════════════════════════════════════
1902
  # INPUT β€” use st.chat_input (cleaner than text_input + button)
 
175
  background: #161b2e !important;
176
  }
177
 
178
+ /* ── Copy button β€” Claude style ── */
179
+ [data-testid="stChatMessage"] .stButton > button {
180
+ background: transparent !important;
181
+ border: 1px solid #2a2a2a !important;
182
+ color: #555 !important;
183
+ border-radius: 6px !important;
184
+ font-size: 0.75rem !important;
185
+ padding: 2px 6px !important;
186
+ width: auto !important;
187
+ min-height: 0 !important;
188
+ height: 24px !important;
189
+ transition: all 0.15s !important;
190
+ }
191
+ [data-testid="stChatMessage"] .stButton > button:hover {
192
+ border-color: #3b82f6 !important;
193
+ color: #ececec !important;
194
+ background: #1a1f2e !important;
195
+ }
196
+
197
  /* ── Spinner ── */
198
  .stSpinner > div { border-top-color: #3b82f6 !important; }
199
 
 
1908
  avatar = "πŸ§‘β€πŸŽ“" if msg["role"] == "user" else "πŸ“"
1909
  with st.chat_message(msg["role"], avatar=avatar):
1910
  st.markdown(msg["content"])
1911
+ # Claude-style copy button β€” pure HTML/JS
1912
  if msg["role"] == "assistant":
1913
+ safe_text = (msg["content"]
1914
+ .replace("&", "&amp;")
1915
+ .replace("<", "&lt;")
1916
+ .replace(">", "&gt;")
1917
+ .replace('"', "&quot;")
1918
+ .replace("'", "&#39;"))
1919
+ btn_id = f"copybtn_{i}"
1920
+ copy_html = (
1921
+ f'<button id="{btn_id}" '
1922
+ f'onclick="navigator.clipboard.writeText(this.getAttribute(\'data-text\'))'
1923
+ f'.then(()=>{{this.textContent=\'βœ… Copied!\';setTimeout(()=>{{this.textContent=\'πŸ“‹ Copy\';}},2000)}})'
1924
+ f'.catch(()=>{{this.textContent=\'❌ Failed\'}})" '
1925
+ f'data-text="{safe_text}" '
1926
+ f'style="background:transparent;border:1px solid #2a2a2a;color:#666;'
1927
+ f'border-radius:6px;padding:2px 10px;font-size:0.75rem;'
1928
+ f'cursor:pointer;margin-top:4px;" '
1929
+ f'onmouseover="this.style.borderColor=\'#3b82f6\';this.style.color=\'#ececec\'" '
1930
+ f'onmouseout="this.style.borderColor=\'#2a2a2a\';this.style.color=\'#666\'">πŸ“‹ Copy</button>'
1931
+ )
1932
+ st.markdown(copy_html, unsafe_allow_html=True)
1933
 
1934
  # ════════════════════════════════════════════════════════════════════
1935
  # INPUT β€” use st.chat_input (cleaner than text_input + button)