alaselababatunde commited on
Commit
caa2aff
·
1 Parent(s): e9ae209
Files changed (1) hide show
  1. main.py +23 -31
main.py CHANGED
@@ -24,11 +24,16 @@ if not SPITCH_API_KEY:
24
  os.environ["SPITCH_API_KEY"] = SPITCH_API_KEY
25
  spitch_client = Spitch()
26
 
27
- # HuggingFace LLM
28
  llm = HuggingFaceEndpoint(
29
  repo_id=HF_MODEL,
30
  temperature=0.2,
31
- model_kwargs={"max_length": 2048}
 
 
 
 
 
32
  )
33
 
34
  # FastAPI app
@@ -76,34 +81,21 @@ Documentation:
76
  """
77
 
78
  sme_template = """
79
- You are an SME site builder AI.
80
- Your job is to turn ANY user prompt (simple or complex) into a working, modern web project.
81
- You must analyze the request carefully and generate clean, professional, and responsive code.
82
-
83
- Rules:
84
- 1. Always return ONLY valid JSON (no explanations, no Markdown).
85
- 2. Always include "index.html", "style.css", and "script.js" in the "files".
86
- 3. Support multiple pages if the user specifies them.
87
- 4. Style must be modern, vibrant, and responsive:
88
- - Use semantic HTML5 (<header>, <main>, <section>, <footer>).
89
- - Use CSS with modern fonts, colors, spacing, hover effects, flex/grid.
90
- - Buttons must be styled and interactive.
91
- - Add responsiveness for mobile.
92
- 5. Translate vague descriptions like “make it futuristic and sharp” into concrete CSS design choices.
93
- 6. If the request is very detailed, honor as much as possible while still keeping valid code.
94
-
95
- User Prompt:
96
- {user_prompt}
97
-
98
- Return ONLY JSON in this format:
99
- {
100
- "files": {
101
- "index.html": "<!DOCTYPE html> ... </html>",
102
- "style.css": "/* modern responsive CSS here */",
103
- "script.js": "// optional interactivity here"
104
- },
105
- "README.md": "# Instructions on how to run the project"
106
- }
107
  """
108
 
109
  # ----------------- CHAINS -----------------
@@ -142,7 +134,7 @@ def chat(req: ChatRequest, authorization: str | None = Header(None)):
142
  return {"reply": answer.strip() if isinstance(answer, str) else str(answer)}
143
  except HfHubHTTPError as e:
144
  if "exceeded" in str(e).lower() or "quota" in str(e).lower():
145
- return {"reply": "⚠️ You have reached your daily limit for responses. Please come back in 24 hours."}
146
  raise e
147
 
148
  @app.post("/stt")
 
24
  os.environ["SPITCH_API_KEY"] = SPITCH_API_KEY
25
  spitch_client = Spitch()
26
 
27
+ # HuggingFace LLM (better tuned for code generation)
28
  llm = HuggingFaceEndpoint(
29
  repo_id=HF_MODEL,
30
  temperature=0.2,
31
+ model_kwargs={
32
+ "max_new_tokens": 1500, # more space for multi-file generation
33
+ "do_sample": True,
34
+ "top_p": 0.9,
35
+ "repetition_penalty": 1.1
36
+ }
37
  )
38
 
39
  # FastAPI app
 
81
  """
82
 
83
  sme_template = """
84
+ You are a senior full-stack engineer specializing in modern front-end development.
85
+ Your job is to generate **production-ready code** for websites and apps.
86
+
87
+ Guidelines:
88
+ - Always return three separate files: index.html, styles.css, and script.js
89
+ - HTML must be semantic, responsive, and mobile-first (use <meta viewport>)
90
+ - CSS should use Flexbox/Grid and include hover/transition effects
91
+ - JavaScript must add interactivity (e.g. button actions, animations, toggles)
92
+ - Include a hero section, feature grid, testimonials, and footer
93
+ - Fill with realistic content (no lorem ipsum, no placeholders)
94
+ - Return **only valid JSON** with keys: "files" { "index.html": "...", "styles.css": "...", "script.js": "..." }
95
+
96
+ Prompt: {user_prompt}
97
+
98
+ Output:
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  """
100
 
101
  # ----------------- CHAINS -----------------
 
134
  return {"reply": answer.strip() if isinstance(answer, str) else str(answer)}
135
  except HfHubHTTPError as e:
136
  if "exceeded" in str(e).lower() or "quota" in str(e).lower():
137
+ return {"reply": "⚠️ Daily token limit reached. Try again in 24 hours."}
138
  raise e
139
 
140
  @app.post("/stt")