ai_project_agent / frontend_agent /live_frontend.py
curiouscurrent's picture
Update frontend_agent/live_frontend.py
4767a8a verified
raw
history blame contribute delete
660 Bytes
# 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