import gradio as gr import os def generate_html(training_text, iterations, gen_length, layer1, layer2): safe_text = training_text.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n") html_content = f"""

Live LSTM Training Output (updates every 10s)

Starting training...
""" # Save the HTML to the /tmp directory (accessible in Hugging Face Spaces) html_path = "/tmp/train.html" with open(html_path, "w") as f: f.write(html_content) # Return iframe HTML to embed the file iframe_code = f'' return iframe_code with gr.Blocks() as demo: gr.Markdown("## 🧠 Live recurrent.js LSTM Trainer (in-browser training)") training_text = gr.Textbox(label="Training Text", lines=6, placeholder="Paste text here") iterations = gr.Slider(10, 200, value=50, step=10, label="Training Epochs") gen_length = gr.Slider(20, 500, value=100, step=10, label="Characters to Generate") layer1 = gr.Slider(16, 256, value=128, step=16, label="Neurons in Layer 1") layer2 = gr.Slider(16, 256, value=128, step=16, label="Neurons in Layer 2") run_button = gr.Button("Start Training") html_output = gr.HTML() run_button.click(fn=generate_html, inputs=[training_text, iterations, gen_length, layer1, layer2], outputs=html_output) demo.launch()