Malaji71 commited on
Commit
07a0179
·
verified ·
1 Parent(s): 9847261

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +158 -155
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
- """BUILD ULTRA SUPREME FLUX PROMPT - ABSOLUTE MAXIMUM QUALITY"""
289
-
290
- components = []
291
-
292
- # 1. ULTRA INTELLIGENT ARTICLE SELECTION
293
- subject_desc = []
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
- clothing_details.append("wearing a traditional black hat")
 
 
 
 
 
 
 
 
365
  else:
366
- clothing_details.append(f"wearing a {headwear}")
367
-
368
- if clothing_details:
369
- components.extend(clothing_details)
370
-
371
- # 6. ULTRA POSE AND BODY LANGUAGE
372
- pose_description = "positioned with natural dignity"
373
-
374
- if ultra_analysis["pose_composition"]["posture"]:
375
- posture = ultra_analysis["pose_composition"]["posture"][0]
376
- pose_description = f"maintaining {posture}"
377
- elif ultra_analysis["technical_analysis"]["shot_type"] == "portrait":
378
- pose_description = "captured in contemplative portrait pose"
379
-
380
- components.append(pose_description)
381
-
382
- # 7. ULTRA ENVIRONMENTAL CONTEXT
383
- environment_desc = "in a thoughtfully composed environment"
384
-
385
- if ultra_analysis["environmental"]["setting_type"]:
386
- setting_map = {
387
- "residential": "in an intimate home setting",
388
- "office": "in a professional office environment",
389
- "religious": "in a sacred traditional space",
390
- "formal": "in a distinguished formal setting"
391
- }
392
- environment_desc = setting_map.get(ultra_analysis["environmental"]["setting_type"], "in a carefully arranged professional setting")
393
-
394
- components.append(environment_desc)
395
-
396
- # 8. ULTRA SOPHISTICATED LIGHTING
397
- lighting_desc = "illuminated by sophisticated portrait lighting that emphasizes character and facial texture"
398
-
399
- if ultra_analysis["environmental"]["lighting_analysis"]:
400
- primary_light = ultra_analysis["environmental"]["lighting_analysis"][0]
401
- if "dramatic" in primary_light:
402
- lighting_desc = "bathed in dramatic chiaroscuro lighting that creates compelling depth and shadow play"
403
- elif "natural" in primary_light or "window" in primary_light:
404
- lighting_desc = "graced by gentle natural lighting that brings out intricate facial details and warmth"
405
- elif "soft" in primary_light:
406
- lighting_desc = "softly illuminated to reveal nuanced expressions and character"
407
-
408
- components.append(lighting_desc)
409
-
410
- # 9. ULTRA TECHNICAL SPECIFICATIONS
411
- if ultra_analysis["technical_analysis"]["shot_type"] in ["portrait", "headshot", "close-up"]:
412
- camera_setup = "Shot on Phase One XF IQ4, 85mm f/1.4 lens, f/2.8 aperture"
413
- elif ultra_analysis["demographic"]["cultural_religious"]:
414
- camera_setup = "Shot on Hasselblad X2D, 90mm lens, f/2.8 aperture"
415
- else:
416
- camera_setup = "Shot on Phase One XF, 80mm lens, f/4 aperture"
417
-
418
- components.append(camera_setup)
419
-
420
- # 10. ULTRA QUALITY DESIGNATION
421
- quality_designation = "professional portrait photography"
422
-
423
- if ultra_analysis["demographic"]["cultural_religious"]:
424
- quality_designation = "fine art documentary photography"
425
- elif ultra_analysis["emotional_state"]["primary_emotion"]:
426
- quality_designation = "expressive portrait photography"
427
-
428
- components.append(quality_designation)
429
-
430
- # ULTRA FINAL ASSEMBLY
431
- prompt = ", ".join(components)
432
-
433
- # Ultra cleaning and optimization
434
- prompt = re.sub(r'\s+', ' ', prompt)
435
- prompt = re.sub(r',\s*,+', ',', prompt)
436
- prompt = re.sub(r'\s*,\s*', ', ', prompt)
437
- prompt = prompt.replace(" ,", ",")
438
-
439
- if prompt:
440
- prompt = prompt[0].upper() + prompt[1:]
441
-
442
- return prompt
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  def calculate_ultra_supreme_score(self, prompt, ultra_analysis):
444
- """ULTRA SUPREME INTELLIGENCE SCORING"""
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
- @spaces.GPU
 
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: