Spaces:
Sleeping
Sleeping
Update agents/software_engineer.py
Browse files- agents/software_engineer.py +35 -27
agents/software_engineer.py
CHANGED
|
@@ -7,52 +7,60 @@ def run(state):
|
|
| 7 |
user_prompt = state["messages"][0].content
|
| 8 |
|
| 9 |
prompt = f"""
|
| 10 |
-
You are a front-end engineer.
|
| 11 |
|
| 12 |
-
|
| 13 |
"{user_prompt}"
|
| 14 |
|
| 15 |
-
|
| 16 |
{architecture}
|
| 17 |
|
| 18 |
-
🎨 Design
|
| 19 |
-
-
|
| 20 |
-
- Use
|
| 21 |
-
-
|
| 22 |
-
|
| 23 |
-
-
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
-
|
| 28 |
-
-
|
| 29 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
-
|
| 33 |
-
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
- Use <style> in the <head> for all CSS
|
| 37 |
-
- No markdown, no code fences, no explanation — only valid HTML
|
| 38 |
-
- Final output must be a complete HTML page (start with <!DOCTYPE html>)
|
| 39 |
-
|
| 40 |
-
Your output will be rendered directly in a browser.
|
| 41 |
"""
|
| 42 |
|
| 43 |
output = call_model(prompt)
|
| 44 |
|
| 45 |
-
#
|
| 46 |
cleaned = re.sub(r"```(?:html|css)?", "", output).strip()
|
| 47 |
|
| 48 |
-
# Extract
|
| 49 |
matches = re.findall(r"<!DOCTYPE html>.*?</html>", cleaned, flags=re.DOTALL | re.IGNORECASE)
|
| 50 |
if matches:
|
| 51 |
final_html = matches[0]
|
| 52 |
elif cleaned.lower().startswith("<!doctype"):
|
| 53 |
final_html = cleaned
|
| 54 |
else:
|
| 55 |
-
#
|
| 56 |
final_html = f"""<!DOCTYPE html>
|
| 57 |
<html lang="en">
|
| 58 |
<head>
|
|
|
|
| 7 |
user_prompt = state["messages"][0].content
|
| 8 |
|
| 9 |
prompt = f"""
|
| 10 |
+
You are a senior front-end engineer. Based on the user prompt and architecture, generate a beautiful, fully responsive HTML page with embedded CSS.
|
| 11 |
|
| 12 |
+
User Prompt:
|
| 13 |
"{user_prompt}"
|
| 14 |
|
| 15 |
+
UI Design Plan:
|
| 16 |
{architecture}
|
| 17 |
|
| 18 |
+
🎨 Design Requirements:
|
| 19 |
+
- Full HTML page starting with <!DOCTYPE html>
|
| 20 |
+
- Use semantic HTML5 tags: <nav>, <section>, <footer>, etc.
|
| 21 |
+
- Fixed top `.navbar` with horizontally centered links (not floating), styled with padding, hover states, and active class
|
| 22 |
+
- Hero section:
|
| 23 |
+
- Full viewport height
|
| 24 |
+
- Unsplash image background based on the theme (car, travel, food, etc.)
|
| 25 |
+
- A dark overlay using `rgba(0,0,0,0.6)`
|
| 26 |
+
- Centered text and a button styled as `.btn`
|
| 27 |
+
- Content:
|
| 28 |
+
- Use `.container` with `max-width: 1200px; margin: auto;`
|
| 29 |
+
- 3 content sections styled with `.section` class, using alternating background colors (#fff, #f9f9f9)
|
| 30 |
+
- Each section must have a heading, paragraph, and one `.btn`
|
| 31 |
+
- Footer:
|
| 32 |
+
- Centered, with solid dark background and padding
|
| 33 |
+
- Color Palette:
|
| 34 |
+
- Use a visually appealing modern palette (not default black/gray)
|
| 35 |
+
- Accent color for buttons and nav hover states
|
| 36 |
+
- Typography:
|
| 37 |
+
- Use system font stack or Google Fonts if needed
|
| 38 |
+
- Responsiveness:
|
| 39 |
+
- Use Flexbox or Grid
|
| 40 |
+
- Add media queries for < 768px screens
|
| 41 |
+
- Stack nav items and center hero text on mobile
|
| 42 |
|
| 43 |
+
🚫 DO NOT:
|
| 44 |
+
- Return markdown or explanations
|
| 45 |
+
- Include duplicate HTML tags
|
| 46 |
+
- Forget to close any HTML tag
|
| 47 |
|
| 48 |
+
Return only the final clean HTML code.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
"""
|
| 50 |
|
| 51 |
output = call_model(prompt)
|
| 52 |
|
| 53 |
+
# Clean markdown or triple backticks if any
|
| 54 |
cleaned = re.sub(r"```(?:html|css)?", "", output).strip()
|
| 55 |
|
| 56 |
+
# Extract valid HTML content
|
| 57 |
matches = re.findall(r"<!DOCTYPE html>.*?</html>", cleaned, flags=re.DOTALL | re.IGNORECASE)
|
| 58 |
if matches:
|
| 59 |
final_html = matches[0]
|
| 60 |
elif cleaned.lower().startswith("<!doctype"):
|
| 61 |
final_html = cleaned
|
| 62 |
else:
|
| 63 |
+
# Wrap fallback
|
| 64 |
final_html = f"""<!DOCTYPE html>
|
| 65 |
<html lang="en">
|
| 66 |
<head>
|