Spaces:
Running
Running
Upload app.py
Browse files33 unmodified lines34353637383940414243447 unmodified lines52535455565758591169 unmodified lines122912301231123212331234123512363 unmodified lines124012411242124312441245124657 unmodified lines13041305130613071308130913101311131233 unmodified lines"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"]# Model Configuration - Models that support JSON modeAI_MODELS = {"groq": ["llama-3.1-8b-instant", # Supports JSON mode"llama-3.3-70b-versatile", # Supports JSON mode]}7 unmodified linesreturn min_usage_keydef get_random_model():"""Select random model for variety"""return random.choice(AI_MODELS["groq"])class AIWebsiteRequest(BaseModel):prompt: str1169 unmodified lines{"role": "system", "content": system_prompt},{"role": "user", "content": user_prompt}],"temperature": 0.5, # Balanced for creativity and consistency"max_tokens": 16000, # Increased for full website generation"response_format": {"type": "json_object"} # Force JSON mode}3 unmodified lines"https://api.groq.com/openai/v1/chat/completions",headers=headers,json=payload,timeout=60)if response.status_code != 200:57 unmodified linesraise ValueError("No HTML in AI response")# Check if HTML is null or emptyif not generated_content['html'] or generated_content['html'] == 'null':logs.append({"time": time.time(), "type": "error", "message": "AI returned null/empty HTML"})raise ValueError("AI returned null or empty HTML content. Please try again.")logs.append({"time": time.time(), "type": "success", "message": "AI response parsed successfully"})logs.append({"time": time.time(), "type": "info", "message": f"Generated {len(generated_content.get('html', ''))} chars of HTML"})33 unmodified lines343536373839404142437 unmodified lines51525354555657581169 unmodified lines122812291230123112321233123412353 unmodified lines123912401241124212431244124557 unmodified lines13031304130513061307130813091310131113121313131433 unmodified lines"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"]# Model Configuration - Use ONLY the most capable modelAI_MODELS = {"groq": ["llama-3.3-70b-versatile", # Most capable, reliable for complex generation]}7 unmodified linesreturn min_usage_keydef get_random_model():"""Select model (always use 70B for reliability)"""return AI_MODELS["groq"][0] # Always use llama-3.3-70b-versatileclass AIWebsiteRequest(BaseModel):prompt: str1169 unmodified lines{"role": "system", "content": system_prompt},{"role": "user", "content": user_prompt}],"temperature": 0.7, # Balanced for creativity and consistency"max_tokens": 32000, # Maximum tokens for complete generation"response_format": {"type": "json_object"} # Force JSON mode}3 unmodified lines"https://api.groq.com/openai/v1/chat/completions",headers=headers,json=payload,timeout=180 # 3 minutes for complex generation)if response.status_code != 200:57 unmodified linesraise ValueError("No HTML in AI response")# Check if HTML is null or emptyhtml_content = generated_content.get('html', '')if not html_content or html_content == 'null' or len(html_content.strip()) < 100:logs.append({"time": time.time(), "type": "error", "message": f"AI returned invalid HTML (length: {len(html_content)})"})logs.append({"time": time.time(), "type": "error", "message": f"Model used: {model}"})logs.append({"time": time.time(), "type": "error", "message": f"Response preview: {str(generated_content)[:200]}"})raise ValueError(f"AI returned null or empty HTML content. Model: {model}. Please try again.")logs.append({"time": time.time(), "type": "success", "message": "AI response parsed successfully"})logs.append({"time": time.time(), "type": "info", "message": f"Generated {len(generated_content.get('html', ''))} chars of HTML"})
app.py+13-11