import gradio as gr def create_scene(desc): print(f"✅ Python function called with: {desc}") return f"Created scene: {desc}" with gr.Blocks() as demo: desc_hidden = gr.Textbox(visible=False, elem_id="desc_hidden") btn_hidden = gr.Button("Create", visible=False, elem_id="btn_hidden") output = gr.HTML() btn_hidden.click(create_scene, desc_hidden, output) demo.load(None, None, None, js=""" () => { console.log('Test loaded'); window.testCreate = function() { const text = prompt('Enter description:'); if (!text) return; console.log('Setting value:', text); const textarea = document.querySelector('#desc_hidden textarea'); if (!textarea) { console.error('Textarea not found!'); return; } const nativeInputValueSetter = Object.getOwnPropertyDescriptor( window.HTMLTextAreaElement.prototype, 'value' ).set; nativeInputValueSetter.call(textarea, text); textarea.dispatchEvent(new Event('input', {bubbles: true})); setTimeout(() => { const btn = document.querySelector('#btn_hidden'); if (!btn) { console.error('Button not found!'); return; } console.log('Clicking button'); btn.click(); }, 200); }; console.log('testCreate ready'); } """) gr.HTML('') demo.launch()