Spaces:
Runtime error
Runtime error
| # frontend_agent/live_frontend.py | |
| import os | |
| FRONTEND_DIR = "frontend_live" | |
| os.makedirs(FRONTEND_DIR, exist_ok=True) | |
| def save_react_component(task_name, code_str): | |
| """ | |
| Save React component to frontend_live directory for live preview. | |
| """ | |
| filename = f"{task_name.replace(' ', '_')}.html" | |
| filepath = os.path.join(FRONTEND_DIR, filename) | |
| html_content = f""" | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>{task_name}</title> | |
| </head> | |
| <body> | |
| <div id="root"></div> | |
| <script type="text/babel"> | |
| {code_str} | |
| </script> | |
| </body> | |
| </html> | |
| """ | |
| with open(filepath, "w") as f: | |
| f.write(html_content) | |
| return filepath | |