Malaji71 commited on
Commit
6803d3e
·
verified ·
1 Parent(s): 7db5a7a

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +89 -13
utils.py CHANGED
@@ -352,33 +352,109 @@ def _get_scene_camera_setup(scene_type: str) -> str:
352
 
353
 
354
  def _get_essential_keywords(description: str, camera_setup: str, analysis_metadata: Optional[Dict[str, Any]]) -> List[str]:
355
- """Get essential style keywords without redundancy"""
356
  try:
357
  keywords = []
358
  description_lower = description.lower()
359
 
360
- # Only add depth of field if not already mentioned
 
 
 
 
 
 
 
 
 
 
361
  if "depth" not in description_lower and "bokeh" not in description_lower:
362
  if any(term in camera_setup for term in ["f/1.4", "f/2.8", "85mm"]):
363
  keywords.append("shallow depth of field")
364
 
365
- # Add professional photography only if no specific camera mentioned
366
- if "shot on" not in camera_setup:
367
  keywords.append("professional photography")
368
 
369
- # Scene-specific keywords
370
- if "portrait" in description_lower and "studio lighting" not in description_lower:
371
- keywords.append("professional portrait")
372
-
373
- # Technical quality (only if needed)
374
- if len(keywords) < 2:
375
- keywords.append("high quality")
376
-
377
  return keywords[:3] # Limit to 3 essential keywords
378
 
379
  except Exception as e:
380
  logger.warning(f"Keyword extraction failed: {e}")
381
- return ["professional photography"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
382
 
383
 
384
  def _build_optimized_prompt(description: str, camera_setup: str, keywords: List[str]) -> str:
 
352
 
353
 
354
  def _get_essential_keywords(description: str, camera_setup: str, analysis_metadata: Optional[Dict[str, Any]]) -> List[str]:
355
+ """Get essential lighting and composition keywords without redundancy"""
356
  try:
357
  keywords = []
358
  description_lower = description.lower()
359
 
360
+ # Detect and add lighting information
361
+ lighting = _detect_lighting_from_description(description_lower)
362
+ if lighting:
363
+ keywords.append(lighting)
364
+
365
+ # Detect and add composition technique
366
+ composition = _detect_composition_from_description(description_lower, camera_setup)
367
+ if composition:
368
+ keywords.append(composition)
369
+
370
+ # Only add depth of field if not already mentioned and relevant
371
  if "depth" not in description_lower and "bokeh" not in description_lower:
372
  if any(term in camera_setup for term in ["f/1.4", "f/2.8", "85mm"]):
373
  keywords.append("shallow depth of field")
374
 
375
+ # Add professional photography only if no specific camera mentioned (fallback)
376
+ if "shot on" not in camera_setup and len(keywords) == 0:
377
  keywords.append("professional photography")
378
 
 
 
 
 
 
 
 
 
379
  return keywords[:3] # Limit to 3 essential keywords
380
 
381
  except Exception as e:
382
  logger.warning(f"Keyword extraction failed: {e}")
383
+ return ["natural lighting"]
384
+
385
+
386
+ def _detect_lighting_from_description(description_lower: str) -> Optional[str]:
387
+ """Detect lighting type from description"""
388
+ try:
389
+ # Check for existing lighting mentions
390
+ if any(term in description_lower for term in ["lighting", "light", "lit", "illuminated"]):
391
+ return None # Already has lighting info
392
+
393
+ # Detect lighting conditions from scene context
394
+ if any(term in description_lower for term in ["sunset", "sunrise", "golden", "warm"]):
395
+ return "golden hour lighting"
396
+ elif any(term in description_lower for term in ["twilight", "dusk", "evening", "blue hour"]):
397
+ return "blue hour lighting"
398
+ elif any(term in description_lower for term in ["overcast", "cloudy", "soft", "diffused"]):
399
+ return "soft natural lighting"
400
+ elif any(term in description_lower for term in ["bright", "sunny", "daylight", "outdoor"]):
401
+ return "natural daylight"
402
+ elif any(term in description_lower for term in ["indoor", "interior", "inside"]):
403
+ return "ambient lighting"
404
+ elif any(term in description_lower for term in ["studio", "controlled", "professional"]):
405
+ return "studio lighting"
406
+ elif any(term in description_lower for term in ["dramatic", "moody", "shadow"]):
407
+ return "dramatic lighting"
408
+ else:
409
+ # Default based on scene type
410
+ if any(term in description_lower for term in ["portrait", "person", "face"]):
411
+ return "natural lighting"
412
+ elif any(term in description_lower for term in ["landscape", "outdoor", "nature"]):
413
+ return "natural daylight"
414
+ else:
415
+ return "natural lighting"
416
+
417
+ except Exception as e:
418
+ logger.warning(f"Lighting detection failed: {e}")
419
+ return "natural lighting"
420
+
421
+
422
+ def _detect_composition_from_description(description_lower: str, camera_setup: str) -> Optional[str]:
423
+ """Detect composition technique from description and camera setup"""
424
+ try:
425
+ # Check for existing composition mentions
426
+ if any(term in description_lower for term in ["composition", "framing", "rule of thirds"]):
427
+ return None # Already has composition info
428
+
429
+ # Detect composition from perspective/angle
430
+ if any(term in description_lower for term in ["elevated", "above", "overhead", "aerial"]):
431
+ return "elevated perspective"
432
+ elif any(term in description_lower for term in ["low angle", "looking up", "from below"]):
433
+ return "low angle composition"
434
+ elif any(term in description_lower for term in ["close-up", "tight", "detailed"]):
435
+ return "close-up framing"
436
+ elif any(term in description_lower for term in ["wide", "expansive", "panoramic"]):
437
+ return "wide composition"
438
+
439
+ # Detect composition from subject arrangement
440
+ elif any(term in description_lower for term in ["centered", "center", "middle"]):
441
+ return "centered composition"
442
+ elif any(term in description_lower for term in ["symmetr", "balanced", "mirror"]):
443
+ return "symmetrical composition"
444
+ elif any(term in description_lower for term in ["leading", "lines", "path", "diagonal"]):
445
+ return "leading lines"
446
+
447
+ # Default composition based on camera setup
448
+ elif any(term in camera_setup for term in ["85mm", "135mm", "f/1.4", "f/2.8"]):
449
+ return "rule of thirds" # Portrait/shallow DOF typically uses rule of thirds
450
+ elif any(term in camera_setup for term in ["24mm", "35mm", "wide"]):
451
+ return "dynamic composition" # Wide angle allows for dynamic compositions
452
+ else:
453
+ return "rule of thirds" # Universal fallback
454
+
455
+ except Exception as e:
456
+ logger.warning(f"Composition detection failed: {e}")
457
+ return "rule of thirds"
458
 
459
 
460
  def _build_optimized_prompt(description: str, camera_setup: str, keywords: List[str]) -> str: