mroccuper commited on
Commit
92e5dfb
·
verified ·
1 Parent(s): 8881c71

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -252,19 +252,33 @@ def build_interface():
252
  outputs=[prompt_output, quality_report, token_stats],
253
  api_name="generate"
254
  )
255
-
256
- if pyperclip:
257
- copy_btn.click(
258
- lambda x: pyperclip.copy(x) if x else None,
259
- inputs=prompt_output,
260
- outputs=None
261
- )
262
- else:
263
- copy_btn.click(
264
- lambda: "Copy functionality not available (pyperclip not installed)",
265
- inputs=None,
266
- outputs=status_msg
267
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
 
269
  return app
270
 
 
252
  outputs=[prompt_output, quality_report, token_stats],
253
  api_name="generate"
254
  )
255
+
256
+ # Implement browser-based clipboard functionality instead of pyperclip
257
+ copy_btn.click(
258
+ None, # No Python function needed
259
+ inputs=prompt_output,
260
+ outputs=None,
261
+ _js="""
262
+ (text) => {
263
+ if (!text) return;
264
+ navigator.clipboard.writeText(text)
265
+ .then(() => {
266
+ // Show temporary success message
267
+ const button = document.querySelector("button:contains('Copy')");
268
+ const originalText = button.innerText;
269
+ button.innerText = "✓ Copied!";
270
+ setTimeout(() => {
271
+ button.innerText = originalText;
272
+ }, 2000);
273
+ })
274
+ .catch(err => {
275
+ console.error('Failed to copy: ', err);
276
+ alert('Copy failed. Please select and copy manually.');
277
+ });
278
+ return;
279
+ }
280
+ """
281
+ )
282
 
283
  return app
284