Spaces:
Paused
Paused
Update app.py
Browse files477 unmodified lines478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544477 unmodified linesif model_selection == "Clipboard only":# Escape the prompt for JavaScriptescaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n')# Create a temporary file for downloadwith tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:f.write(prompt)download_file = f.name# Use f-string for HTMLhtml_template = f'''<div style="text-align: center; margin: 10px;"><buttononclick="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>'''# Return all three valuesreturn gr.HTML(html_template), "Text copied to clipboard.", download_file# Get the summary based on model selectionif model_selection == "HuggingFace Inference":477 unmodified lines478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547477 unmodified linesif model_selection == "Clipboard only":# Escape the prompt for JavaScriptescaped_prompt = prompt.replace('"', '\\"').replace("'", "\\'").replace('\n', '\\n')# Create temporary file for downloadwith tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as f:f.write(prompt)download_file = f.name# Create HTML with JavaScript using fallback methodshtml_template = f'''<buttononclick="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 methodconst 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 expected outputs:# 1. HTML component for clipboard action# 2. A success message for summary output# 3. The download filereturn gr.HTML(html_template), "Text copied to clipboard. Use paste for processing.", download_file# Get the summary based on model selectionif model_selection == "HuggingFace Inference":
app.py+58-55