Spaces:
Sleeping
Sleeping
Update agents/software_engineer.py
Browse files- agents/software_engineer.py +23 -16
agents/software_engineer.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from langchain_core.messages import AIMessage
|
| 2 |
from utils.inference import call_model
|
|
|
|
| 3 |
|
| 4 |
def run(state):
|
| 5 |
design = state["architecture"]
|
|
@@ -10,30 +11,36 @@ def run(state):
|
|
| 10 |
|
| 11 |
Requirements:
|
| 12 |
- Full HTML document with <!DOCTYPE>
|
| 13 |
-
- CSS inside <style> tags in <head>
|
| 14 |
-
- Mobile responsive
|
| 15 |
-
-
|
| 16 |
-
-
|
|
|
|
| 17 |
|
| 18 |
output = call_model(prompt)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
cleaned =
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
if not cleaned.lower()
|
| 25 |
cleaned = f"""<!DOCTYPE html>
|
| 26 |
-
<html>
|
| 27 |
<head>
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
</head>
|
| 35 |
<body>
|
| 36 |
-
|
|
|
|
|
|
|
| 37 |
</body>
|
| 38 |
</html>"""
|
| 39 |
|
|
|
|
| 1 |
from langchain_core.messages import AIMessage
|
| 2 |
from utils.inference import call_model
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
def run(state):
|
| 6 |
design = state["architecture"]
|
|
|
|
| 11 |
|
| 12 |
Requirements:
|
| 13 |
- Full HTML document with <!DOCTYPE>
|
| 14 |
+
- CSS embedded inside <style> tags in <head>
|
| 15 |
+
- Mobile responsive and visually appealing
|
| 16 |
+
- Self-contained (runnable directly as .html file)
|
| 17 |
+
- No markdown formatting (no ```html, ```css, etc.)
|
| 18 |
+
"""
|
| 19 |
|
| 20 |
output = call_model(prompt)
|
| 21 |
|
| 22 |
+
# Clean markdown code block formatting if the model added it anyway
|
| 23 |
+
cleaned = re.sub(r"```(?:html|css)?", "", output).strip()
|
| 24 |
|
| 25 |
+
# Fallback HTML wrapper if model output is incomplete or broken
|
| 26 |
+
if "<!DOCTYPE html>" not in cleaned.lower():
|
| 27 |
cleaned = f"""<!DOCTYPE html>
|
| 28 |
+
<html lang="en">
|
| 29 |
<head>
|
| 30 |
+
<meta charset="UTF-8">
|
| 31 |
+
<title>Generated UI</title>
|
| 32 |
+
<style>
|
| 33 |
+
body {{
|
| 34 |
+
font-family: Arial, sans-serif;
|
| 35 |
+
background-color: #f4f4f4;
|
| 36 |
+
padding: 2rem;
|
| 37 |
+
}}
|
| 38 |
+
</style>
|
| 39 |
</head>
|
| 40 |
<body>
|
| 41 |
+
<main>
|
| 42 |
+
{cleaned}
|
| 43 |
+
</main>
|
| 44 |
</body>
|
| 45 |
</html>"""
|
| 46 |
|