Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -284,164 +284,166 @@ class UltraSupremeAnalyzer:
|
|
| 284 |
ultra_result["intelligence_metrics"]["cultural_awareness_score"] = len(ultra_result["demographic"]["cultural_religious"]) * 20
|
| 285 |
|
| 286 |
return ultra_result
|
|
|
|
| 287 |
def build_ultra_supreme_prompt(self, ultra_analysis, clip_results):
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
if ultra_analysis["demographic"]["cultural_religious"]:
|
| 295 |
-
subject_desc.extend(ultra_analysis["demographic"]["cultural_religious"][:1])
|
| 296 |
-
if ultra_analysis["demographic"]["age_category"] and ultra_analysis["demographic"]["age_category"] != "middle_aged":
|
| 297 |
-
subject_desc.append(ultra_analysis["demographic"]["age_category"].replace("_", " "))
|
| 298 |
-
if ultra_analysis["demographic"]["gender"]:
|
| 299 |
-
subject_desc.append(ultra_analysis["demographic"]["gender"])
|
| 300 |
-
|
| 301 |
-
if subject_desc:
|
| 302 |
-
full_subject = " ".join(subject_desc)
|
| 303 |
-
article = "An" if full_subject[0].lower() in 'aeiou' else "A"
|
| 304 |
-
else:
|
| 305 |
-
article = "A"
|
| 306 |
-
components.append(article)
|
| 307 |
-
|
| 308 |
-
# 2. ULTRA CONTEXTUAL ADJECTIVES (max 2-3 per Flux rules)
|
| 309 |
-
adjectives = []
|
| 310 |
-
|
| 311 |
-
# Age-based adjectives
|
| 312 |
-
age_cat = ultra_analysis["demographic"]["age_category"]
|
| 313 |
-
if age_cat and age_cat in self.quality_descriptors_ultra["based_on_age"]:
|
| 314 |
-
adjectives.extend(self.quality_descriptors_ultra["based_on_age"][age_cat][:2])
|
| 315 |
-
|
| 316 |
-
# Emotion-based adjectives
|
| 317 |
-
emotion = ultra_analysis["emotional_state"]["primary_emotion"]
|
| 318 |
-
if emotion and emotion in self.quality_descriptors_ultra["based_on_emotion"]:
|
| 319 |
-
adjectives.extend(self.quality_descriptors_ultra["based_on_emotion"][emotion][:1])
|
| 320 |
-
|
| 321 |
-
# Default if none found
|
| 322 |
-
if not adjectives:
|
| 323 |
-
adjectives = ["distinguished", "professional"]
|
| 324 |
-
|
| 325 |
-
components.extend(adjectives[:2]) # Flux rule: max 2-3 adjectives
|
| 326 |
-
|
| 327 |
-
# 3. ULTRA ENHANCED SUBJECT
|
| 328 |
-
if subject_desc:
|
| 329 |
-
components.append(" ".join(subject_desc))
|
| 330 |
-
else:
|
| 331 |
-
components.append("person")
|
| 332 |
-
|
| 333 |
-
# 4. ULTRA DETAILED FACIAL FEATURES
|
| 334 |
-
facial_details = []
|
| 335 |
-
|
| 336 |
-
# Eyes
|
| 337 |
-
if ultra_analysis["facial_ultra"]["eyes"]:
|
| 338 |
-
eye_desc = ultra_analysis["facial_ultra"]["eyes"][0]
|
| 339 |
-
facial_details.append(f"with {eye_desc}")
|
| 340 |
-
|
| 341 |
-
# Facial hair with ultra detail
|
| 342 |
-
if ultra_analysis["facial_ultra"]["facial_hair"]:
|
| 343 |
-
beard_details = ultra_analysis["facial_ultra"]["facial_hair"]
|
| 344 |
-
if any("silver" in detail or "gray" in detail or "grey" in detail for detail in beard_details):
|
| 345 |
-
facial_details.append("with a distinguished silver beard")
|
| 346 |
-
elif any("beard" in detail for detail in beard_details):
|
| 347 |
-
facial_details.append("with a full well-groomed beard")
|
| 348 |
-
|
| 349 |
-
if facial_details:
|
| 350 |
-
components.extend(facial_details)
|
| 351 |
-
|
| 352 |
-
# 5. CLOTHING AND ACCESSORIES ULTRA
|
| 353 |
-
clothing_details = []
|
| 354 |
-
|
| 355 |
-
# Eyewear
|
| 356 |
-
if ultra_analysis["clothing_accessories"]["eyewear"]:
|
| 357 |
-
eyewear = ultra_analysis["clothing_accessories"]["eyewear"][0]
|
| 358 |
-
clothing_details.append(f"wearing {eyewear}")
|
| 359 |
-
|
| 360 |
-
# Headwear
|
| 361 |
-
if ultra_analysis["clothing_accessories"]["headwear"]:
|
| 362 |
-
headwear = ultra_analysis["clothing_accessories"]["headwear"][0]
|
| 363 |
if ultra_analysis["demographic"]["cultural_religious"]:
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
else:
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
"
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
def calculate_ultra_supreme_score(self, prompt, ultra_analysis):
|
| 444 |
-
|
| 445 |
|
| 446 |
score = 0
|
| 447 |
breakdown = {}
|
|
@@ -549,7 +551,8 @@ class UltraSupremeOptimizer:
|
|
| 549 |
image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 550 |
|
| 551 |
return image
|
| 552 |
-
|
|
|
|
| 553 |
def generate_ultra_supreme_prompt(self, image):
|
| 554 |
try:
|
| 555 |
if not self.is_initialized:
|
|
|
|
| 284 |
ultra_result["intelligence_metrics"]["cultural_awareness_score"] = len(ultra_result["demographic"]["cultural_religious"]) * 20
|
| 285 |
|
| 286 |
return ultra_result
|
| 287 |
+
|
| 288 |
def build_ultra_supreme_prompt(self, ultra_analysis, clip_results):
|
| 289 |
+
"""BUILD ULTRA SUPREME FLUX PROMPT - ABSOLUTE MAXIMUM QUALITY"""
|
| 290 |
+
|
| 291 |
+
components = []
|
| 292 |
+
|
| 293 |
+
# 1. ULTRA INTELLIGENT ARTICLE SELECTION
|
| 294 |
+
subject_desc = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
if ultra_analysis["demographic"]["cultural_religious"]:
|
| 296 |
+
subject_desc.extend(ultra_analysis["demographic"]["cultural_religious"][:1])
|
| 297 |
+
if ultra_analysis["demographic"]["age_category"] and ultra_analysis["demographic"]["age_category"] != "middle_aged":
|
| 298 |
+
subject_desc.append(ultra_analysis["demographic"]["age_category"].replace("_", " "))
|
| 299 |
+
if ultra_analysis["demographic"]["gender"]:
|
| 300 |
+
subject_desc.append(ultra_analysis["demographic"]["gender"])
|
| 301 |
+
|
| 302 |
+
if subject_desc:
|
| 303 |
+
full_subject = " ".join(subject_desc)
|
| 304 |
+
article = "An" if full_subject[0].lower() in 'aeiou' else "A"
|
| 305 |
else:
|
| 306 |
+
article = "A"
|
| 307 |
+
components.append(article)
|
| 308 |
+
|
| 309 |
+
# 2. ULTRA CONTEXTUAL ADJECTIVES (max 2-3 per Flux rules)
|
| 310 |
+
adjectives = []
|
| 311 |
+
|
| 312 |
+
# Age-based adjectives
|
| 313 |
+
age_cat = ultra_analysis["demographic"]["age_category"]
|
| 314 |
+
if age_cat and age_cat in self.quality_descriptors_ultra["based_on_age"]:
|
| 315 |
+
adjectives.extend(self.quality_descriptors_ultra["based_on_age"][age_cat][:2])
|
| 316 |
+
|
| 317 |
+
# Emotion-based adjectives
|
| 318 |
+
emotion = ultra_analysis["emotional_state"]["primary_emotion"]
|
| 319 |
+
if emotion and emotion in self.quality_descriptors_ultra["based_on_emotion"]:
|
| 320 |
+
adjectives.extend(self.quality_descriptors_ultra["based_on_emotion"][emotion][:1])
|
| 321 |
+
|
| 322 |
+
# Default if none found
|
| 323 |
+
if not adjectives:
|
| 324 |
+
adjectives = ["distinguished", "professional"]
|
| 325 |
+
|
| 326 |
+
components.extend(adjectives[:2]) # Flux rule: max 2-3 adjectives
|
| 327 |
+
|
| 328 |
+
# 3. ULTRA ENHANCED SUBJECT
|
| 329 |
+
if subject_desc:
|
| 330 |
+
components.append(" ".join(subject_desc))
|
| 331 |
+
else:
|
| 332 |
+
components.append("person")
|
| 333 |
+
|
| 334 |
+
# 4. ULTRA DETAILED FACIAL FEATURES
|
| 335 |
+
facial_details = []
|
| 336 |
+
|
| 337 |
+
# Eyes
|
| 338 |
+
if ultra_analysis["facial_ultra"]["eyes"]:
|
| 339 |
+
eye_desc = ultra_analysis["facial_ultra"]["eyes"][0]
|
| 340 |
+
facial_details.append(f"with {eye_desc}")
|
| 341 |
+
|
| 342 |
+
# Facial hair with ultra detail
|
| 343 |
+
if ultra_analysis["facial_ultra"]["facial_hair"]:
|
| 344 |
+
beard_details = ultra_analysis["facial_ultra"]["facial_hair"]
|
| 345 |
+
if any("silver" in detail or "gray" in detail or "grey" in detail for detail in beard_details):
|
| 346 |
+
facial_details.append("with a distinguished silver beard")
|
| 347 |
+
elif any("beard" in detail for detail in beard_details):
|
| 348 |
+
facial_details.append("with a full well-groomed beard")
|
| 349 |
+
|
| 350 |
+
if facial_details:
|
| 351 |
+
components.extend(facial_details)
|
| 352 |
+
|
| 353 |
+
# 5. CLOTHING AND ACCESSORIES ULTRA
|
| 354 |
+
clothing_details = []
|
| 355 |
+
|
| 356 |
+
# Eyewear
|
| 357 |
+
if ultra_analysis["clothing_accessories"]["eyewear"]:
|
| 358 |
+
eyewear = ultra_analysis["clothing_accessories"]["eyewear"][0]
|
| 359 |
+
clothing_details.append(f"wearing {eyewear}")
|
| 360 |
+
|
| 361 |
+
# Headwear
|
| 362 |
+
if ultra_analysis["clothing_accessories"]["headwear"]:
|
| 363 |
+
headwear = ultra_analysis["clothing_accessories"]["headwear"][0]
|
| 364 |
+
if ultra_analysis["demographic"]["cultural_religious"]:
|
| 365 |
+
clothing_details.append("wearing a traditional black hat")
|
| 366 |
+
else:
|
| 367 |
+
clothing_details.append(f"wearing a {headwear}")
|
| 368 |
+
|
| 369 |
+
if clothing_details:
|
| 370 |
+
components.extend(clothing_details)
|
| 371 |
+
|
| 372 |
+
# 6. ULTRA POSE AND BODY LANGUAGE
|
| 373 |
+
pose_description = "positioned with natural dignity"
|
| 374 |
+
|
| 375 |
+
if ultra_analysis["pose_composition"]["posture"]:
|
| 376 |
+
posture = ultra_analysis["pose_composition"]["posture"][0]
|
| 377 |
+
pose_description = f"maintaining {posture}"
|
| 378 |
+
elif ultra_analysis["technical_analysis"]["shot_type"] == "portrait":
|
| 379 |
+
pose_description = "captured in contemplative portrait pose"
|
| 380 |
+
|
| 381 |
+
components.append(pose_description)
|
| 382 |
+
|
| 383 |
+
# 7. ULTRA ENVIRONMENTAL CONTEXT
|
| 384 |
+
environment_desc = "in a thoughtfully composed environment"
|
| 385 |
+
|
| 386 |
+
if ultra_analysis["environmental"]["setting_type"]:
|
| 387 |
+
setting_map = {
|
| 388 |
+
"residential": "in an intimate home setting",
|
| 389 |
+
"office": "in a professional office environment",
|
| 390 |
+
"religious": "in a sacred traditional space",
|
| 391 |
+
"formal": "in a distinguished formal setting"
|
| 392 |
+
}
|
| 393 |
+
environment_desc = setting_map.get(ultra_analysis["environmental"]["setting_type"], "in a carefully arranged professional setting")
|
| 394 |
+
|
| 395 |
+
components.append(environment_desc)
|
| 396 |
+
|
| 397 |
+
# 8. ULTRA SOPHISTICATED LIGHTING
|
| 398 |
+
lighting_desc = "illuminated by sophisticated portrait lighting that emphasizes character and facial texture"
|
| 399 |
+
|
| 400 |
+
if ultra_analysis["environmental"]["lighting_analysis"]:
|
| 401 |
+
primary_light = ultra_analysis["environmental"]["lighting_analysis"][0]
|
| 402 |
+
if "dramatic" in primary_light:
|
| 403 |
+
lighting_desc = "bathed in dramatic chiaroscuro lighting that creates compelling depth and shadow play"
|
| 404 |
+
elif "natural" in primary_light or "window" in primary_light:
|
| 405 |
+
lighting_desc = "graced by gentle natural lighting that brings out intricate facial details and warmth"
|
| 406 |
+
elif "soft" in primary_light:
|
| 407 |
+
lighting_desc = "softly illuminated to reveal nuanced expressions and character"
|
| 408 |
+
|
| 409 |
+
components.append(lighting_desc)
|
| 410 |
+
|
| 411 |
+
# 9. ULTRA TECHNICAL SPECIFICATIONS
|
| 412 |
+
if ultra_analysis["technical_analysis"]["shot_type"] in ["portrait", "headshot", "close-up"]:
|
| 413 |
+
camera_setup = "Shot on Phase One XF IQ4, 85mm f/1.4 lens, f/2.8 aperture"
|
| 414 |
+
elif ultra_analysis["demographic"]["cultural_religious"]:
|
| 415 |
+
camera_setup = "Shot on Hasselblad X2D, 90mm lens, f/2.8 aperture"
|
| 416 |
+
else:
|
| 417 |
+
camera_setup = "Shot on Phase One XF, 80mm lens, f/4 aperture"
|
| 418 |
+
|
| 419 |
+
components.append(camera_setup)
|
| 420 |
+
|
| 421 |
+
# 10. ULTRA QUALITY DESIGNATION
|
| 422 |
+
quality_designation = "professional portrait photography"
|
| 423 |
+
|
| 424 |
+
if ultra_analysis["demographic"]["cultural_religious"]:
|
| 425 |
+
quality_designation = "fine art documentary photography"
|
| 426 |
+
elif ultra_analysis["emotional_state"]["primary_emotion"]:
|
| 427 |
+
quality_designation = "expressive portrait photography"
|
| 428 |
+
|
| 429 |
+
components.append(quality_designation)
|
| 430 |
+
|
| 431 |
+
# ULTRA FINAL ASSEMBLY
|
| 432 |
+
prompt = ", ".join(components)
|
| 433 |
+
|
| 434 |
+
# Ultra cleaning and optimization
|
| 435 |
+
prompt = re.sub(r'\s+', ' ', prompt)
|
| 436 |
+
prompt = re.sub(r',\s*,+', ',', prompt)
|
| 437 |
+
prompt = re.sub(r'\s*,\s*', ', ', prompt)
|
| 438 |
+
prompt = prompt.replace(" ,", ",")
|
| 439 |
+
|
| 440 |
+
if prompt:
|
| 441 |
+
prompt = prompt[0].upper() + prompt[1:]
|
| 442 |
+
|
| 443 |
+
return prompt
|
| 444 |
+
|
| 445 |
def calculate_ultra_supreme_score(self, prompt, ultra_analysis):
|
| 446 |
+
"""ULTRA SUPREME INTELLIGENCE SCORING"""
|
| 447 |
|
| 448 |
score = 0
|
| 449 |
breakdown = {}
|
|
|
|
| 551 |
image.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
| 552 |
|
| 553 |
return image
|
| 554 |
+
|
| 555 |
+
@spaces.GPU
|
| 556 |
def generate_ultra_supreme_prompt(self, image):
|
| 557 |
try:
|
| 558 |
if not self.is_initialized:
|