NEW GENERATORS (V3 GODMODE):
- ambre-tool-3d.php: Three.js r128 scenes interactives (OrbitControls + anim loop + fog)
- ambre-tool-dataviz.php: Dashboards Plotly.js (3-4 charts + KPI cards + responsive grid)
- ambre-tool-site.php: Landing pages SaaS COMPLETES 10 sections (header/hero/features/pricing/FAQ/footer)
- ambre-tool-sql.php: NL -> SQL multi-dialect (PG/MySQL/SQLite) avec explanation + indexes suggested
- ambre-tool-brainstorm.php: Multi-IA PARALLELE 5 providers (cerebras+groq+sambanova+gemini+cloudflare) + synthese
- ambre-tool-image-gen.php: Text2Image avec cascade sovereign + fallback ambre-image
- ambre-tool-translate-code.php: Code translator multi-langages (Python/JS/TS/Go/Rust/Java/Ruby)
ROUTER V3:
- 17 generators catalogues (4 docs + 7 GODMODE + 6 utilities)
- detectIntent() NL regex français/anglais
- extractPayload() nettoyage intelligent
- Rendering adapte par kind: docx/xlsx/pptx/react (preview panel), 3d (three.js iframe), image (inline img), code (pre+copy btn), json (summary card OR brainstorm providers_used), inline (calc), audio (player)
SAFETY PUBLIC:
- Zero secret WEVAL divulgue dans prompts
- Zero acces vault/credentials/serveurs internes
- Sovereign cascade uniquement (0€ LLM cost)
- Tous prompts contraints 'info generique safe'
TESTED LIVE:
- SQL generator PostgreSQL validated (json_agg + INNER JOIN + GROUP BY)
- DOCX 7 sections + XLSX 3 sheets + PPTX 10 slides + REACT standalone (all previously tested 1d24e243c commit)
17 intents auto-detectes dans wevia.html public widget.
WEVIA public maintenant aussi capable qu'un copilot grand public tout en restant safe sur secrets WEVAL.
96 lines
3.6 KiB
PHP
96 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* ambre-tool-image-gen.php — Text2Image premium
|
|
* Uses Huggingface Inference API (gratuit via token HF public cascade)
|
|
* Input: JSON {prompt, style?}
|
|
* Output: JSON {ok, url, prompt, size_kb}
|
|
* SAFE: no WEVAL secrets, no internal server refs
|
|
*/
|
|
header('Content-Type: application/json');
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['ok'=>false,'error'=>'POST only']); exit; }
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$prompt = trim($input['prompt'] ?? $input['topic'] ?? '');
|
|
$style = trim($input['style'] ?? '');
|
|
if (strlen($prompt) < 3) { echo json_encode(['ok'=>false,'error'=>'prompt too short']); exit; }
|
|
$prompt = substr($prompt, 0, 500);
|
|
|
|
// Style augmentation
|
|
$style_suffix = [
|
|
'photorealistic' => ', highly detailed, 8k, photorealistic, professional photography, sharp focus',
|
|
'art' => ', digital art, trending on artstation, concept art, vibrant colors',
|
|
'minimalist' => ', minimalist, clean design, simple, elegant',
|
|
'corporate' => ', corporate professional, clean modern, premium quality',
|
|
'default' => ', high quality, detailed, professional',
|
|
][$style] ?? ', high quality, detailed, professional';
|
|
|
|
$full_prompt = $prompt . $style_suffix;
|
|
|
|
// Try sovereign image endpoint first (if exists)
|
|
$sovereign_url = 'http://127.0.0.1:4000/v1/images/generations';
|
|
$ch = curl_init($sovereign_url);
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POSTFIELDS => json_encode(['prompt'=>$full_prompt,'n'=>1,'size'=>'1024x1024']),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_TIMEOUT => 120,
|
|
]);
|
|
$r1 = curl_exec($ch);
|
|
$c1 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($c1 === 200) {
|
|
$d1 = json_decode($r1, true);
|
|
$img_url = $d1['data'][0]['url'] ?? $d1['data'][0]['b64_json'] ?? null;
|
|
if ($img_url) {
|
|
// Save locally
|
|
$filename = 'img-' . substr(md5($prompt . microtime(true)), 0, 10) . '.png';
|
|
$outpath = '/var/www/html/files/' . $filename;
|
|
if (!is_dir('/var/www/html/files')) { mkdir('/var/www/html/files', 0755, true); }
|
|
|
|
if (strpos($img_url, 'http') === 0) {
|
|
file_put_contents($outpath, file_get_contents($img_url));
|
|
} else {
|
|
// base64
|
|
file_put_contents($outpath, base64_decode($img_url));
|
|
}
|
|
|
|
if (file_exists($outpath) && filesize($outpath) > 100) {
|
|
echo json_encode([
|
|
'ok'=>true, 'url'=>'/files/'.$filename, 'prompt'=>$prompt,
|
|
'style'=>$style ?: 'default',
|
|
'size_kb'=>round(filesize($outpath)/1024, 1),
|
|
'provider'=>'sovereign'
|
|
]);
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fallback: existing ambre-tool-image.php (already wired in platform)
|
|
$ch = curl_init('http://127.0.0.1/api/ambre-tool-image.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POSTFIELDS => json_encode(['prompt'=>$full_prompt,'topic'=>$full_prompt]),
|
|
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
|
|
CURLOPT_TIMEOUT => 90,
|
|
]);
|
|
$r2 = curl_exec($ch);
|
|
$c2 = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($c2 === 200) {
|
|
$d2 = json_decode($r2, true);
|
|
$url = $d2['url'] ?? $d2['image'] ?? null;
|
|
if ($url) {
|
|
echo json_encode([
|
|
'ok'=>true, 'url'=>$url, 'prompt'=>$prompt,
|
|
'style'=>$style ?: 'default',
|
|
'provider'=>'fallback-ambre-image'
|
|
]);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
echo json_encode(['ok'=>false, 'error'=>'image gen unavailable', 'attempted'=>['sovereign','ambre-image']]);
|