Isaac Quarenta commited on
Commit
0c8e0ad
·
1 Parent(s): d1efef8

fix: image gen provider order - HF Inference first, Pollinations last

Browse files
Files changed (1) hide show
  1. modules/cellcog_integration.py +23 -23
modules/cellcog_integration.py CHANGED
@@ -1041,21 +1041,13 @@ class AIMediaFactory:
1041
  ) -> Dict[str, Any]:
1042
  providers_tried = []
1043
 
1044
- # TIER 1: Pollinations Flux (único provider funcional, grátis, sem key)
1045
- providers_tried.append("pollinations")
1046
- pollinations_model = model
1047
- keywords_realistas = ["realistic", "photo", "cinematic", "8k", "photorealistic", "ultra realistic",
1048
- "realista", "foto", "cinematográfico", "shape", "gym", "angulo", "feições"]
1049
- if any(kw in prompt.lower() for kw in keywords_realistas):
1050
- pollinations_model = "flux-realism"
1051
- flux_result = self._try_provider("Pollinations Flux", prompt, aspect_ratio, pollinations_model, self.flux)
1052
- if flux_result and flux_result.get("success"):
1053
- flux_result["image_data"] = self._extract_and_render_text(
1054
- flux_result["image_data"], prompt
1055
- )
1056
- return flux_result
1057
 
1058
- # TIER 2: CellCog (reservado para quando voltar)
1059
  if self.cellcog.available:
1060
  providers_tried.append("cellcog")
1061
  result = self.cellcog.generate_image(
@@ -1068,13 +1060,7 @@ class AIMediaFactory:
1068
  return result
1069
  logger.warning(f"⚠️ [MEDIA FACTORY] CellCog falhou: {result.get('error', 'unknown')[:80]}")
1070
 
1071
- # TIER 3: HuggingFace Inference (reservado para quando voltar)
1072
- providers_tried.append("hf_inference")
1073
- hf_result = self._try_provider("HuggingFace", prompt, aspect_ratio, model, self.hf_image)
1074
- if hf_result:
1075
- return hf_result
1076
-
1077
- # TIER 4: Google Imagen 3 (Gemini API)
1078
  providers_tried.append("google_imagen")
1079
  try:
1080
  from .google_image_gen import get_google_image_gen
@@ -1084,7 +1070,7 @@ class AIMediaFactory:
1084
  except Exception as e:
1085
  logger.warning(f"⚠️ [MEDIA FACTORY] Google Imagen não disponível: {e}")
1086
 
1087
- # TIER 5: Cloudflare Workers AI
1088
  providers_tried.append("cloudflare")
1089
  try:
1090
  from .cloudflare_image_gen import get_cloudflare_image_gen
@@ -1094,7 +1080,7 @@ class AIMediaFactory:
1094
  except Exception as e:
1095
  logger.warning(f"⚠️ [MEDIA FACTORY] Cloudflare não disponível: {e}")
1096
 
1097
- # TIER 6: Stability AI SD3.5
1098
  providers_tried.append("stability")
1099
  try:
1100
  from .stability_image_gen import get_stability_image_gen
@@ -1104,6 +1090,20 @@ class AIMediaFactory:
1104
  except Exception as e:
1105
  logger.warning(f"⚠️ [MEDIA FACTORY] Stability AI não disponível: {e}")
1106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1107
  logger.error(f"❌ [MEDIA FACTORY] TODOS os providers falharam: {', '.join(providers_tried)}")
1108
  return {"success": False, "error": f"Todos os providers de imagem falharam: {', '.join(providers_tried)}"}
1109
 
 
1041
  ) -> Dict[str, Any]:
1042
  providers_tried = []
1043
 
1044
+ # TIER 1: HuggingFace Inference (rotação de tokens, melhor qualidade)
1045
+ providers_tried.append("hf_inference")
1046
+ hf_result = self._try_provider("HuggingFace", prompt, aspect_ratio, model, self.hf_image)
1047
+ if hf_result:
1048
+ return hf_result
 
 
 
 
 
 
 
 
1049
 
1050
+ # TIER 2: CellCog (se disponível)
1051
  if self.cellcog.available:
1052
  providers_tried.append("cellcog")
1053
  result = self.cellcog.generate_image(
 
1060
  return result
1061
  logger.warning(f"⚠️ [MEDIA FACTORY] CellCog falhou: {result.get('error', 'unknown')[:80]}")
1062
 
1063
+ # TIER 3: Google Imagen 3 (Gemini API)
 
 
 
 
 
 
1064
  providers_tried.append("google_imagen")
1065
  try:
1066
  from .google_image_gen import get_google_image_gen
 
1070
  except Exception as e:
1071
  logger.warning(f"⚠️ [MEDIA FACTORY] Google Imagen não disponível: {e}")
1072
 
1073
+ # TIER 4: Cloudflare Workers AI
1074
  providers_tried.append("cloudflare")
1075
  try:
1076
  from .cloudflare_image_gen import get_cloudflare_image_gen
 
1080
  except Exception as e:
1081
  logger.warning(f"⚠️ [MEDIA FACTORY] Cloudflare não disponível: {e}")
1082
 
1083
+ # TIER 5: Stability AI SD3.5
1084
  providers_tried.append("stability")
1085
  try:
1086
  from .stability_image_gen import get_stability_image_gen
 
1090
  except Exception as e:
1091
  logger.warning(f"⚠️ [MEDIA FACTORY] Stability AI não disponível: {e}")
1092
 
1093
+ # TIER 6: Pollinations Flux (último fallback, grátis, sem key)
1094
+ providers_tried.append("pollinations")
1095
+ pollinations_model = model
1096
+ keywords_realistas = ["realistic", "photo", "cinematic", "8k", "photorealistic", "ultra realistic",
1097
+ "realista", "foto", "cinematográfico", "shape", "gym", "angulo", "feições"]
1098
+ if any(kw in prompt.lower() for kw in keywords_realistas):
1099
+ pollinations_model = "flux-realism"
1100
+ flux_result = self._try_provider("Pollinations Flux", prompt, aspect_ratio, pollinations_model, self.flux)
1101
+ if flux_result and flux_result.get("success"):
1102
+ flux_result["image_data"] = self._extract_and_render_text(
1103
+ flux_result["image_data"], prompt
1104
+ )
1105
+ return flux_result
1106
+
1107
  logger.error(f"❌ [MEDIA FACTORY] TODOS os providers falharam: {', '.join(providers_tried)}")
1108
  return {"success": False, "error": f"Todos os providers de imagem falharam: {', '.join(providers_tried)}"}
1109