| | from typing import Dict, Any, List |
| | import re |
| |
|
| | class PromptEnhancer: |
| | def __init__(self): |
| | self.quality_terms = { |
| | "Ultra Réaliste": [ |
| | "masterpiece", "best quality", "ultra realistic", |
| | "photorealistic", "8k uhd", "high resolution", |
| | "detailed", "sharp focus", "professional photography" |
| | ], |
| | "Artistique Pro": [ |
| | "masterpiece", "best quality", "professional", |
| | "detailed", "artistic", "perfect composition", |
| | "award winning", "trending on artstation" |
| | ] |
| | } |
| |
|
| | def enhance(self, prompt: str, style: str, composition: str, mood: str) -> str: |
| | """Améliore le prompt en ajoutant des termes de qualité et de style appropriés""" |
| | |
| | cleaned_prompt = self._clean_prompt(prompt) |
| | |
| | |
| | quality_terms = self.quality_terms.get(style, self.quality_terms["Ultra Réaliste"]) |
| | quality_string = ", ".join(quality_terms) |
| | |
| | |
| | enhanced_prompt = f"{cleaned_prompt}, {quality_string}, {composition}, {mood}" |
| | |
| | |
| | return self._optimize_prompt(enhanced_prompt) |
| |
|
| | def _clean_prompt(self, prompt: str) -> str: |
| | """Nettoie et normalise le prompt""" |
| | |
| | cleaned = re.sub(r'\s+', ' ', prompt.strip()) |
| | |
| | |
| | redundant_terms = ["high quality", "good quality", "best quality", "hq"] |
| | for term in redundant_terms: |
| | cleaned = re.sub(rf'\b{term}\b', '', cleaned, flags=re.IGNORECASE) |
| | |
| | return cleaned.strip() |
| |
|
| | def _optimize_prompt(self, prompt: str) -> str: |
| | """Optimisation finale du prompt""" |
| | |
| | words = prompt.split() |
| | if len(words) > 77: |
| | words = words[:77] |
| | |
| | |
| | important_terms = [] |
| | regular_terms = [] |
| | |
| | for word in words: |
| | if word.lower() in ["masterpiece", "best quality", "professional"]: |
| | important_terms.append(word) |
| | else: |
| | regular_terms.append(word) |
| | |
| | return ", ".join(important_terms + regular_terms) |