Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -190,23 +190,27 @@ if prompt := st.chat_input("Your message..."):
|
|
| 190 |
]
|
| 191 |
elif content["type"] == "text":
|
| 192 |
messages[-1]["content"] += f"\n\n[Attached File Content]\n{content['content']}"
|
| 193 |
-
|
| 194 |
# Generate response
|
| 195 |
with st.chat_message("assistant"):
|
| 196 |
with st.spinner(f"Asking {model}..."):
|
| 197 |
try:
|
| 198 |
reply = call_openrouter(model, messages, temperature, max_tokens, api_key)
|
| 199 |
|
|
|
|
|
|
|
|
|
|
| 200 |
# Clipboard-ready response with JS
|
| 201 |
st.markdown(f"""
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
|
| 209 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 210 |
except Exception as e:
|
| 211 |
st.error(str(e))
|
| 212 |
st.session_state.messages.append({"role": "assistant", "content": f"❌ {str(e)}"})
|
|
|
|
|
|
| 190 |
]
|
| 191 |
elif content["type"] == "text":
|
| 192 |
messages[-1]["content"] += f"\n\n[Attached File Content]\n{content['content']}"
|
| 193 |
+
###### x
|
| 194 |
# Generate response
|
| 195 |
with st.chat_message("assistant"):
|
| 196 |
with st.spinner(f"Asking {model}..."):
|
| 197 |
try:
|
| 198 |
reply = call_openrouter(model, messages, temperature, max_tokens, api_key)
|
| 199 |
|
| 200 |
+
# Preprocess reply for JS clipboard (safe escaping)
|
| 201 |
+
safe_reply = reply.replace("`", "\\`").replace("\n", "\\n").replace('"', '\\"')
|
| 202 |
+
|
| 203 |
# Clipboard-ready response with JS
|
| 204 |
st.markdown(f"""
|
| 205 |
+
<div style="position: relative;">
|
| 206 |
+
<button onclick="navigator.clipboard.writeText(`{safe_reply}`)"
|
| 207 |
+
style="position:absolute; right:0; top:0;">📋 Copy</button>
|
| 208 |
+
<div style="padding-right:50px;">{reply}</div>
|
| 209 |
+
</div>
|
| 210 |
+
""", unsafe_allow_html=True)
|
| 211 |
|
| 212 |
st.session_state.messages.append({"role": "assistant", "content": reply})
|
| 213 |
except Exception as e:
|
| 214 |
st.error(str(e))
|
| 215 |
st.session_state.messages.append({"role": "assistant", "content": f"❌ {str(e)}"})
|
| 216 |
+
|