Public Access
Déploiement serveur pour test de génération multimédia (HuggingFace + Cloudflare)
Build and Push Docker Image / build-and-push (push) Successful in 35s
Build and Push Docker Image / build-and-push (push) Successful in 35s
This commit is contained in:
1 parent
519a42107f
commit
391d9acae1
1 file changed
+14
-2
+14
-2
@@ -2,10 +2,11 @@ import os
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
|
import base64 # <-- NOUVEL IMPORT POUR DECODER L'IMAGE
|
||||||
from modules.logger import log_event
|
from modules.logger import log_event
|
||||||
|
|
||||||
def generer_image_cloudflare(prompt: str) -> bytes:
|
def generer_image_cloudflare(prompt: str) -> bytes:
|
||||||
"""Appel à l'API Cloudflare Workers AI"""
|
"""Appel à l'API Cloudflare Workers AI avec décodage Base64"""
|
||||||
account_id = os.getenv("CLOUDFLARE_ACCOUNT_ID")
|
account_id = os.getenv("CLOUDFLARE_ACCOUNT_ID")
|
||||||
api_token = os.getenv("CLOUDFLARE_API_TOKEN")
|
api_token = os.getenv("CLOUDFLARE_API_TOKEN")
|
||||||
if not account_id or not api_token: return None
|
if not account_id or not api_token: return None
|
||||||
@@ -15,11 +16,22 @@ def generer_image_cloudflare(prompt: str) -> bytes:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
resp = requests.post(url, headers=headers, json={"prompt": prompt}, timeout=120)
|
resp = requests.post(url, headers=headers, json={"prompt": prompt}, timeout=120)
|
||||||
if resp.status_code == 200: return resp.content
|
if resp.status_code == 200:
|
||||||
|
# On vérifie si Cloudflare nous répond en texte (JSON)
|
||||||
|
if "application/json" in resp.headers.get("Content-Type", ""):
|
||||||
|
data = resp.json()
|
||||||
|
if data.get("success") and "result" in data:
|
||||||
|
# On transforme le texte Base64 en véritable fichier image binaire
|
||||||
|
return base64.b64decode(data["result"])
|
||||||
|
else:
|
||||||
|
# S'il répond nativement en binaire (parfois le cas selon la requête)
|
||||||
|
return resp.content
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_event("WARNING", "MEDIA", f"Échec Cloudflare : {e}")
|
log_event("WARNING", "MEDIA", f"Échec Cloudflare : {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# ... (le reste du fichier reste identique)
|
||||||
|
|
||||||
def generer_image_huggingface(prompt: str) -> bytes:
|
def generer_image_huggingface(prompt: str) -> bytes:
|
||||||
"""Appel à l'API HuggingFace"""
|
"""Appel à l'API HuggingFace"""
|
||||||
api_key = os.getenv("HUGGINGFACE_API_KEY")
|
api_key = os.getenv("HUGGINGFACE_API_KEY")
|
||||||
|
|||||||
Reference in new issue
Block a user