Spaces:
Sleeping
Sleeping
Commit
·
caa2aff
1
Parent(s):
e9ae209
Updated
Browse files
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={
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
# FastAPI app
|
|
@@ -76,34 +81,21 @@ Documentation:
|
|
| 76 |
"""
|
| 77 |
|
| 78 |
sme_template = """
|
| 79 |
-
You are
|
| 80 |
-
Your job is to
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 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": "⚠️
|
| 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")
|