curiouscurrent commited on
Commit
4767a8a
·
verified ·
1 Parent(s): 474286c

Update frontend_agent/live_frontend.py

Browse files
Files changed (1) hide show
  1. frontend_agent/live_frontend.py +21 -6
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 generated React component to a file for live preview
10
  """
11
- filename = f"{task_name.replace(' ','_')}.jsx"
12
- path = os.path.join(FRONTEND_DIR, filename)
13
- with open(path, "w") as f:
14
- f.write(code_str)
15
- return filename
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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