Spaces:
Runtime error
Runtime error
Update frontend_agent/live_frontend.py
Browse files
frontend_agent/live_frontend.py
CHANGED
|
@@ -6,10 +6,25 @@ os.makedirs(FRONTEND_DIR, exist_ok=True)
|
|
| 6 |
|
| 7 |
def save_react_component(task_name, code_str):
|
| 8 |
"""
|
| 9 |
-
Save
|
| 10 |
"""
|
| 11 |
-
filename = f"{task_name.replace(' ','_')}.
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def save_react_component(task_name, code_str):
|
| 8 |
"""
|
| 9 |
+
Save React component to frontend_live directory for live preview.
|
| 10 |
"""
|
| 11 |
+
filename = f"{task_name.replace(' ', '_')}.html"
|
| 12 |
+
filepath = os.path.join(FRONTEND_DIR, filename)
|
| 13 |
+
html_content = f"""
|
| 14 |
+
<!DOCTYPE html>
|
| 15 |
+
<html lang="en">
|
| 16 |
+
<head>
|
| 17 |
+
<meta charset="UTF-8">
|
| 18 |
+
<title>{task_name}</title>
|
| 19 |
+
</head>
|
| 20 |
+
<body>
|
| 21 |
+
<div id="root"></div>
|
| 22 |
+
<script type="text/babel">
|
| 23 |
+
{code_str}
|
| 24 |
+
</script>
|
| 25 |
+
</body>
|
| 26 |
+
</html>
|
| 27 |
+
"""
|
| 28 |
+
with open(filepath, "w") as f:
|
| 29 |
+
f.write(html_content)
|
| 30 |
+
return filepath
|