Noo88ear commited on
Commit
22a36c5
Β·
verified Β·
1 Parent(s): 204138a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -77,6 +77,9 @@ GOOGLE_API_KEY = next((key for key in GCP_KEYS if key), None)
77
  if GOOGLE_API_KEY and GEMINI_AVAILABLE:
78
  genai.configure(api_key=GOOGLE_API_KEY)
79
  logger.info("βœ… Google AI configured successfully")
 
 
 
80
 
81
  # MCP-enabled functions for Agent1 (Image Generator)
82
  def enhance_prompt_with_gemini(prompt: str, style: str) -> str:
@@ -159,6 +162,7 @@ def generate_marketing_image(prompt: str, style: str = "realistic") -> str:
159
  if GEMINI_AVAILABLE and GOOGLE_API_KEY:
160
  try:
161
  logger.info("🎨 Using Google Genai SDK for image generation")
 
162
 
163
  # Initialize the genai SDK client
164
  client = genai_sdk.Client(api_key=GOOGLE_API_KEY)
@@ -201,6 +205,10 @@ def generate_marketing_image(prompt: str, style: str = "realistic") -> str:
201
 
202
  except Exception as e:
203
  logger.error(f"Google SDK generation failed: {e}")
 
 
 
 
204
 
205
  # Fallback: Generate a deterministic placeholder
206
  logger.info("πŸ”„ Using placeholder URL fallback")
@@ -439,11 +447,21 @@ def process_generated_image_and_results(api_response_str: str) -> Tuple[Image.Im
439
  image_data_b64 = image_info.get('data', image_info.get('url', ''))
440
 
441
  image = None
442
- if image_data_b64 and image_data_b64.startswith('data:image'):
443
  try:
444
- base64_data = image_data_b64.split(',')[1]
445
- image_bytes = base64.b64decode(base64_data)
446
- image = Image.open(io.BytesIO(image_bytes))
 
 
 
 
 
 
 
 
 
 
447
  except Exception as e:
448
  logger.error(f"Error processing image: {str(e)}")
449
 
 
77
  if GOOGLE_API_KEY and GEMINI_AVAILABLE:
78
  genai.configure(api_key=GOOGLE_API_KEY)
79
  logger.info("βœ… Google AI configured successfully")
80
+ logger.info(f"Key source: {[key for key in ['GOOGLE_API_KEY', 'GEMINI_API_KEY', 'GCP_API_KEY'] if os.getenv(key)]}")
81
+ else:
82
+ logger.warning(f"❌ Google AI NOT configured - GEMINI_AVAILABLE: {GEMINI_AVAILABLE}, GOOGLE_API_KEY: {'present' if GOOGLE_API_KEY else 'missing'}")
83
 
84
  # MCP-enabled functions for Agent1 (Image Generator)
85
  def enhance_prompt_with_gemini(prompt: str, style: str) -> str:
 
162
  if GEMINI_AVAILABLE and GOOGLE_API_KEY:
163
  try:
164
  logger.info("🎨 Using Google Genai SDK for image generation")
165
+ logger.info(f"API Key available: {GOOGLE_API_KEY[:10]}...")
166
 
167
  # Initialize the genai SDK client
168
  client = genai_sdk.Client(api_key=GOOGLE_API_KEY)
 
205
 
206
  except Exception as e:
207
  logger.error(f"Google SDK generation failed: {e}")
208
+ logger.error(f"Error type: {type(e).__name__}")
209
+ if hasattr(e, 'response'):
210
+ logger.error(f"Response status: {getattr(e.response, 'status_code', 'unknown')}")
211
+ logger.error(f"Response text: {getattr(e.response, 'text', 'unknown')}")
212
 
213
  # Fallback: Generate a deterministic placeholder
214
  logger.info("πŸ”„ Using placeholder URL fallback")
 
447
  image_data_b64 = image_info.get('data', image_info.get('url', ''))
448
 
449
  image = None
450
+ if image_data_b64:
451
  try:
452
+ if image_data_b64.startswith('data:image'):
453
+ # Handle base64 data URLs
454
+ base64_data = image_data_b64.split(',')[1]
455
+ image_bytes = base64.b64decode(base64_data)
456
+ image = Image.open(io.BytesIO(image_bytes))
457
+ elif image_data_b64.startswith('http'):
458
+ # Handle regular URLs (like picsum.photos)
459
+ import requests
460
+ response = requests.get(image_data_b64, timeout=10)
461
+ if response.status_code == 200:
462
+ image = Image.open(io.BytesIO(response.content))
463
+ else:
464
+ logger.error(f"Failed to fetch image from URL: {response.status_code}")
465
  except Exception as e:
466
  logger.error(f"Error processing image: {str(e)}")
467