Spaces:
Paused
Paused
Update app.py
Browse files477 unmodified lines478479480481482481482483484485486487487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537539540541538539540541542543544545546547477 unmodified lines if model_selection == "Clipboard only": # Escape the prompt for JavaScript escaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n') # Create a temporary file for download
# Create temporary file for download with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f: f.write(prompt) download_file = f.name
# Use f-string for HTML # Create HTML with JavaScript using fallback methods html_template = f''' <div style="text-align: center; margin: 10px;"> <button onclick=" try {{ const textToCopy = `{escaped_prompt}`; navigator.clipboard.writeText(textToCopy) .then(() => {{ this.textContent = 'β
Copied to clipboard!'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }}) .catch(err => {{ console.error('Copy failed:', err); const textarea = document.createElement('textarea'); textarea.value = textToCopy; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); this.textContent = 'β
Copied to clipboard!'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }}); }} catch(err) {{ console.error('Copy error:', err); this.textContent = 'β Copy failed. Try again.'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }} " style=" padding: 10px 20px; background-color: #2C3E50; color: white; border: none; border-radius: 5px; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease; " onmouseover="this.style.backgroundColor='#34495E'" onmouseout="this.style.backgroundColor='#2C3E50'" > π Copy Text to Clipboard </button> </div> <button onclick=" try {{ const textToCopy = `{escaped_prompt}`; navigator.clipboard.writeText(textToCopy) .then(() => {{ this.textContent = 'β
Copied to clipboard!'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }}) .catch(err => {{ console.error('Modern copy failed:', err); // Fallback to textarea method const textarea = document.createElement('textarea'); textarea.value = textToCopy; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); document.body.removeChild(textarea); this.textContent = 'β
Copied using fallback!'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }}); }} catch(err) {{ console.error('Copy error:', err); this.textContent = 'β Copy failed. Try again.'; setTimeout(() => {{ this.textContent = 'π Copy Text to Clipboard'; }}, 2000); }} " style=" padding: 10px 20px; background-color: #2C3E50; color: white; border: none; border-radius: 5px; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease; " onmouseover="this.style.backgroundColor='#34495E'" onmouseout="this.style.backgroundColor='#2C3E50'" > π Copy Text to Clipboard </button> ''' # Return all three values return gr.HTML(html_template), "Text copied to clipboard.", download_file
# Return all three expected outputs: # 1. HTML component for clipboard action # 2. A success message for summary output # 3. The download file return gr.HTML(html_template), "Text copied to clipboard. Use paste for processing.", download_file
# Get the summary based on model selection if model_selection == "HuggingFace Inference":app.py+58-55