Spaces:
Sleeping
Sleeping
File size: 3,637 Bytes
48ab112 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
import os
import re
def fix_dashboard_branding():
print("🎨 Correcting Dashboard Title...")
path = "dashboard.html"
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
content = f.read()
# Brutal replace: Fix the repeating "AI AI AI" issue
# We replace any variation of "StyleSync AI AI..." with just "StyleSync AI"
new_content = re.sub(r"StyleSync AI( AI)+", "StyleSync AI", content)
# Ensure the Title tag is clean
new_content = new_content.replace("<title>StyleSync AI AI AI AI AI Dashboard</title>", "<title>StyleSync AI Dashboard</title>")
# Ensure the H2 header is clean
new_content = new_content.replace("Enterprise Edition", "Enterprise Edition 1.0")
with open(path, "w", encoding="utf-8") as f:
f.write(new_content)
print("✅ Dashboard branding sanitized.")
def fix_writer_prompt():
print("✍️ Reinforcing Writer Agent...")
path = "agents/writer_agent.py"
# Overwrite with robust version
robust_code = """import os
import json
from groq import Groq
from dotenv import load_dotenv
load_dotenv()
class WriterAgent:
def __init__(self):
self.api_key = os.getenv("GROQ_API_KEY")
self.client = Groq(api_key=self.api_key) if self.api_key else None
self.model = "llama-3.3-70b-versatile"
def write_listing(self, visual_data: dict, seo_keywords: list) -> dict:
if not self.client:
return {"error": "No API Key"}
system_prompt = \"\"\"You are a professional copywriter.
Write a JSON product listing.
RULES:
1. Output strictly valid JSON.
2. "description": Single paragraph, plain text, no newlines.
3. "title": Concise SEO title.
4. "features": List of 3 distinct features.
Example Output:
{
"title": "Classic Leather Jacket",
"description": "A timeless piece crafted from premium leather.",
"features": ["Genuine Leather", "Slim Fit", "Zip Closure"],
"price_estimate": "$100-$150"
}
\"\"\"
user_content = f\"\"\"
DATA: {json.dumps(visual_data)}
KEYWORDS: {', '.join(seo_keywords)}
\"\"\"
try:
completion = self.client.chat.completions.create(
model=self.model,
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_content}
],
temperature=0.1,
response_format={"type": "json_object"}
)
return json.loads(completion.choices[0].message.content)
except Exception as e:
print(f"❌ Writer Error: {e}")
return {
"title": visual_data.get('product_type', 'Product Name'),
"description": "High-quality fashion item matching your style.",
"features": visual_data.get('visual_features', []),
"price_estimate": "$50-$100"
}
"""
with open(path, "w", encoding="utf-8") as f:
f.write(robust_code)
print("✅ Writer Agent logic updated to 'Robust Mode'.")
def force_docker_rebuild():
print("🐳 Touching Dockerfile to force rebuild...")
path = "Dockerfile"
if os.path.exists(path):
with open(path, "a") as f:
f.write("\n# Force Rebuild: Final Polish v1.0\n")
print("✅ Dockerfile updated.")
if __name__ == "__main__":
fix_dashboard_branding()
fix_writer_prompt()
force_docker_rebuild() |