Spaces:
Sleeping
Sleeping
Update agents/software_engineer.py
Browse files- agents/software_engineer.py +17 -23
agents/software_engineer.py
CHANGED
|
@@ -4,39 +4,33 @@ import re
|
|
| 4 |
|
| 5 |
def run(state):
|
| 6 |
design = state["architecture"]
|
| 7 |
-
|
| 8 |
-
prompt = f"""You are a front-end engineer. Create a complete HTML page with embedded CSS for the following
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
Requirements:
|
| 13 |
-
-
|
| 14 |
-
-
|
| 15 |
-
-
|
| 16 |
-
-
|
| 17 |
-
-
|
| 18 |
-
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
- Only return the complete HTML (no explanation, no markdown)"""
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
# Get output from model
|
| 25 |
output = call_model(prompt)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
cleaned = re.sub(r"```(?:html|css)?", "", output)
|
| 29 |
-
cleaned = re.sub(r"(This example.+|Given the constraints.+|Here is.+|Below is.+)", "", cleaned, flags=re.IGNORECASE)
|
| 30 |
-
cleaned = cleaned.strip()
|
| 31 |
|
| 32 |
-
#
|
| 33 |
matches = re.findall(r"<!DOCTYPE html>.*?</html>", cleaned, flags=re.DOTALL | re.IGNORECASE)
|
| 34 |
if matches:
|
| 35 |
final_html = matches[0]
|
| 36 |
elif cleaned.lower().startswith("<!doctype"):
|
| 37 |
final_html = cleaned
|
| 38 |
else:
|
| 39 |
-
#
|
| 40 |
final_html = f"""<!DOCTYPE html>
|
| 41 |
<html lang="en">
|
| 42 |
<head>
|
|
@@ -45,8 +39,8 @@ Requirements:
|
|
| 45 |
<style>
|
| 46 |
body {{
|
| 47 |
font-family: Arial, sans-serif;
|
| 48 |
-
background-color: #f4f4f4;
|
| 49 |
padding: 2rem;
|
|
|
|
| 50 |
}}
|
| 51 |
</style>
|
| 52 |
</head>
|
|
|
|
| 4 |
|
| 5 |
def run(state):
|
| 6 |
design = state["architecture"]
|
| 7 |
+
|
| 8 |
+
prompt = f"""You are a front-end engineer. Create a complete HTML page with embedded CSS for the following UI design:
|
| 9 |
+
|
| 10 |
+
{design}
|
| 11 |
|
| 12 |
Requirements:
|
| 13 |
+
- Self-contained HTML document with <!DOCTYPE>
|
| 14 |
+
- CSS must be embedded in <style> inside <head>
|
| 15 |
+
- Design should reflect the user’s theme (e.g., yoga site, fintech dashboard, travel blog, etc.)
|
| 16 |
+
- Use a mobile-responsive layout (flex/grid, media queries)
|
| 17 |
+
- Include common web elements like a header, hero section, content cards, and footer
|
| 18 |
+
- Only return the final HTML. Do NOT explain or include markdown. Do NOT include planning or wireframes.
|
| 19 |
+
"""
|
| 20 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
output = call_model(prompt)
|
| 22 |
|
| 23 |
+
# Remove any markdown fences or extra explanations
|
| 24 |
+
cleaned = re.sub(r"```(?:html|css)?", "", output).strip()
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Try to extract a clean HTML document
|
| 27 |
matches = re.findall(r"<!DOCTYPE html>.*?</html>", cleaned, flags=re.DOTALL | re.IGNORECASE)
|
| 28 |
if matches:
|
| 29 |
final_html = matches[0]
|
| 30 |
elif cleaned.lower().startswith("<!doctype"):
|
| 31 |
final_html = cleaned
|
| 32 |
else:
|
| 33 |
+
# If malformed, wrap it in a basic HTML structure
|
| 34 |
final_html = f"""<!DOCTYPE html>
|
| 35 |
<html lang="en">
|
| 36 |
<head>
|
|
|
|
| 39 |
<style>
|
| 40 |
body {{
|
| 41 |
font-family: Arial, sans-serif;
|
|
|
|
| 42 |
padding: 2rem;
|
| 43 |
+
background-color: #f4f4f4;
|
| 44 |
}}
|
| 45 |
</style>
|
| 46 |
</head>
|