Actualizar app.py
Browse files
app.py
CHANGED
|
@@ -1,203 +1,97 @@
|
|
| 1 |
import os
|
| 2 |
import random
|
| 3 |
-
import
|
| 4 |
-
from
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
self.POSES = [
|
| 96 |
-
"standing gracefully with one leg slightly forward, skirt adjusting as if caught in motion revealing lace panties",
|
| 97 |
-
"seated on the edge, legs crossed, skirt shifting and lace panties subtly visible",
|
| 98 |
-
"bending forward slightly as if picking something up, skirt rising to show lace panties",
|
| 99 |
-
"leaning against a wall, one hip cocked, skirt riding up to reveal lace panties",
|
| 100 |
-
"walking with a natural sway, skirt moving with motion to show glimpses of lace panties",
|
| 101 |
-
"reaching upwards for an object, skirt lifting to display lace panties",
|
| 102 |
-
"sitting on stairs, legs slightly apart, skirt providing a view of lace panties",
|
| 103 |
-
"lying on a sofa, dress falling open to reveal lace panties naturally",
|
| 104 |
-
"dancing gently, skirt flowing to show lace panties during spins",
|
| 105 |
-
"adjusting stockings, skirt lifted to expose lace panties momentarily"
|
| 106 |
-
]
|
| 107 |
-
|
| 108 |
-
self.SETTINGS = [
|
| 109 |
-
"a modern professional office with golden sunset light and sophisticated decor",
|
| 110 |
-
"a stylish hospital room with clean bright tones and realistic medical equipment",
|
| 111 |
-
"a luxurious bedroom with silk sheets and soft lighting",
|
| 112 |
-
"an elegant living room with vintage furniture and warm ambiance",
|
| 113 |
-
"a photography studio with professional lighting and minimalist backdrop",
|
| 114 |
-
"a high-end hotel suite with city views and contemporary design",
|
| 115 |
-
"a classic library with wooden shelves and warm reading lights",
|
| 116 |
-
"a rooftop terrace with urban landscape and twilight sky",
|
| 117 |
-
"a dressing room with large mirrors and velvet furnishings",
|
| 118 |
-
"a boutique hotel lobby with art deco elements and soft lighting"
|
| 119 |
-
]
|
| 120 |
-
|
| 121 |
-
self.ATMOSPHERES = [
|
| 122 |
-
"soft professional lighting with perfect color, crisp highlights and smooth skin shadows",
|
| 123 |
-
"warm ambient sunlight, rich gold reflections and depth",
|
| 124 |
-
"moody cinematic lighting with dramatic shadows and highlights",
|
| 125 |
-
"romantic candlelight with soft glows and intimate shadows",
|
| 126 |
-
"studio flash lighting with clean, sharp details and minimal shadows",
|
| 127 |
-
"golden hour natural light with warm, flattering tones",
|
| 128 |
-
"moonlit ambiance with cool tones and mysterious atmosphere",
|
| 129 |
-
"neon accent lighting with vibrant colors and urban vibe"
|
| 130 |
-
]
|
| 131 |
-
|
| 132 |
-
self.TECHNICAL_DETAILS = (
|
| 133 |
-
"shot in full vertical 9:16 aspect ratio capturing the entire figure with natural human proportions and anatomical precision, "
|
| 134 |
-
"featuring hyperrealistic skin texture with subtle imperfections, perfect makeup, and real fabric and hair strand details. "
|
| 135 |
-
"Captured with professional camera gear (Canon R5, 85mm lens, f/1.2) emphasizing soft, natural lighting and highlights for humanized photorealism. "
|
| 136 |
-
"Exclude any cartoon, 2D, painting, stylized, CGI, illustration, low resolution, or watermark artifacts."
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
def _random_choice(self, collection: list) -> str:
|
| 140 |
-
return random.choice(collection)
|
| 141 |
-
|
| 142 |
-
def generate_prompt(
|
| 143 |
-
self,
|
| 144 |
-
seed_config: Optional[Dict[str, Any]] = None,
|
| 145 |
-
context: Optional[Dict[str, Any]] = None
|
| 146 |
-
) -> str:
|
| 147 |
-
seed = seed_config or {}
|
| 148 |
-
|
| 149 |
-
role = seed.get("role", self._random_choice(self.ROLES))
|
| 150 |
-
hair_color = seed.get("hair_color", self._random_choice(self.HAIR_COLORS))
|
| 151 |
-
eye_color = seed.get("eye_color", self._random_choice(self.EYE_COLORS))
|
| 152 |
-
hair_style = seed.get("hair_style", self._random_choice(self.HAIR_STYLES))
|
| 153 |
-
outfit = self.OUTFIT_TEMPLATES.get(role, self.OUTFIT_TEMPLATES["secretary"])
|
| 154 |
-
pose = seed.get("pose", self._random_choice(self.POSES))
|
| 155 |
-
setting = seed.get("setting", self._random_choice(self.SETTINGS))
|
| 156 |
-
atmosphere = seed.get("atmosphere", self._random_choice(self.ATMOSPHERES))
|
| 157 |
-
|
| 158 |
-
context_note = f" Context: {context['summary']}." if context and "summary" in context else ""
|
| 159 |
-
|
| 160 |
-
prompt = (
|
| 161 |
-
f"A hyperrealistic full-body portrait of a sensual {role} with {hair_style} in {hair_color}, {eye_color} eyes, "
|
| 162 |
-
f"perfect makeup and flawless skin with subtle natural imperfections. Wearing {outfit}. "
|
| 163 |
-
f"Pose: {pose}. Scene: {setting} with {atmosphere}.{context_note} "
|
| 164 |
-
f"{self.TECHNICAL_DETAILS}"
|
| 165 |
-
)
|
| 166 |
-
|
| 167 |
-
cache_list = self.cache.get(self.CACHE_KEY, [])
|
| 168 |
-
if prompt in cache_list:
|
| 169 |
-
prompt = prompt + f" [uid:{random.randint(1000,9999)}]"
|
| 170 |
-
|
| 171 |
-
cache_list.append(prompt)
|
| 172 |
-
self.cache.set(self.CACHE_KEY, cache_list)
|
| 173 |
-
|
| 174 |
-
return f"``````"
|
| 175 |
-
|
| 176 |
-
def generate_five_prompts(
|
| 177 |
-
self,
|
| 178 |
-
seed_config: Optional[Dict[str, Any]] = None,
|
| 179 |
-
context: Optional[Dict[str, Any]] = None
|
| 180 |
-
) -> list[str]:
|
| 181 |
-
prompts = []
|
| 182 |
-
for _ in range(5):
|
| 183 |
-
prompt = self.generate_prompt(seed_config=seed_config, context=context)
|
| 184 |
-
prompts.append(prompt)
|
| 185 |
-
return prompts
|
| 186 |
-
|
| 187 |
-
def update_configuration(self, new_config: Dict[str, Any]) -> None:
|
| 188 |
-
for key, value in new_config.items():
|
| 189 |
-
if hasattr(self, key):
|
| 190 |
-
existing = getattr(self, key)
|
| 191 |
-
if isinstance(existing, list) and isinstance(value, list):
|
| 192 |
-
existing.extend(x for x in value if x not in existing)
|
| 193 |
-
elif isinstance(existing, dict) and isinstance(value, dict):
|
| 194 |
-
existing.update(value)
|
| 195 |
-
|
| 196 |
|
| 197 |
if __name__ == "__main__":
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
prompts = generator.generate_five_prompts()
|
| 201 |
-
for prompt in prompts:
|
| 202 |
-
print(prompt + "\n")
|
| 203 |
-
|
|
|
|
| 1 |
import os
|
| 2 |
import random
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from smolagents import InferenceClientModel
|
| 5 |
+
|
| 6 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
+
|
| 8 |
+
# Inicializa el modelo Mistral con token Hugging Face
|
| 9 |
+
model = InferenceClientModel(
|
| 10 |
+
model_id="mistralai/Mistral-7B-Instruct-v0.1",
|
| 11 |
+
token=HF_TOKEN,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# Datos básicos para generar prompts
|
| 15 |
+
ROLES = [
|
| 16 |
+
"nurse", "nun", "doctor", "secretary", "teacher", "schoolgirl", "lawyer"
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
HAIR_STYLES = [
|
| 20 |
+
"long flowing chestnut hair styled in soft waves",
|
| 21 |
+
"sleek straight long black hair",
|
| 22 |
+
"luxurious long blonde curls",
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
EYE_COLORS = [
|
| 26 |
+
"intense brown", "bright sapphire blue", "emerald green"
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
OUTFIT_TEMPLATES = {
|
| 30 |
+
"nurse": "a classic short nurse dress, thigh-high stockings, semi-transparent lace panties, no bra, elegant high heels",
|
| 31 |
+
"nun": "a sensual interpretation of a nun's habit with a revealing long robe and thigh-high stockings",
|
| 32 |
+
"doctor": "a daring white lab coat minidress left slightly open, thigh-high stockings",
|
| 33 |
+
"secretary": "a provocative office pencil skirt and sheer blouse, thigh-high stockings",
|
| 34 |
+
"teacher": "a fitted blazer over a silk blouse and short skirt, thigh-high stockings",
|
| 35 |
+
"schoolgirl": "a short pleated skirt and white blouse, thigh-high stockings",
|
| 36 |
+
"lawyer": "a tailored suit with skirt cut above knees, silk blouse unbuttoned slightly, thigh-high stockings"
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
POSES = [
|
| 40 |
+
"standing gracefully with one leg slightly forward",
|
| 41 |
+
"seated on the edge, legs crossed",
|
| 42 |
+
"bending forward slightly as if picking something up"
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
SETTINGS = [
|
| 46 |
+
"a modern professional office with golden sunset light and sophisticated decor",
|
| 47 |
+
"a stylish hospital room with clean bright tones and realistic medical equipment",
|
| 48 |
+
"a luxurious bedroom with silk sheets and soft lighting"
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
ATMOSPHERES = [
|
| 52 |
+
"soft professional lighting with perfect color, crisp highlights and smooth skin shadows",
|
| 53 |
+
"warm ambient sunlight, rich gold reflections and depth",
|
| 54 |
+
"moody cinematic lighting with dramatic shadows and highlights"
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
TECHNICAL_DETAILS = (
|
| 58 |
+
"shot in full vertical 9:16 aspect ratio capturing the entire figure with natural human proportions and anatomical precision, "
|
| 59 |
+
"featuring hyperrealistic skin texture with subtle imperfections, perfect makeup and natural fabric and hair strand details. "
|
| 60 |
+
"Captured with professional camera gear (Canon R5, 85mm lens, f/1.2) emphasizing soft, natural lighting and highlights for humanized photorealism. "
|
| 61 |
+
"Exclude any cartoon, 2D, painting, stylized, CGI, low resolution or watermark artifacts."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def generate_prompt():
|
| 66 |
+
role = random.choice(ROLES)
|
| 67 |
+
hair_style = random.choice(HAIR_STYLES)
|
| 68 |
+
eye_color = random.choice(EYE_COLORS)
|
| 69 |
+
outfit = OUTFIT_TEMPLATES[role]
|
| 70 |
+
pose = random.choice(POSES)
|
| 71 |
+
setting = random.choice(SETTINGS)
|
| 72 |
+
atmosphere = random.choice(ATMOSPHERES)
|
| 73 |
+
|
| 74 |
+
prompt_text = (
|
| 75 |
+
f"A hyperrealistic full-body portrait of a sensual {role} with {hair_style} and {eye_color} eyes, "
|
| 76 |
+
f"perfect makeup and flawless skin with subtle natural imperfections. Wearing {outfit}. "
|
| 77 |
+
f"Pose: {pose}. Scene: {setting} with {atmosphere}. "
|
| 78 |
+
f"{TECHNICAL_DETAILS}"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
return f"``````"
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def generate_five_prompts():
|
| 85 |
+
return [generate_prompt() for _ in range(5)]
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
with gr.Blocks() as demo:
|
| 89 |
+
gr.Markdown("## Hyperrealistic Full-Body Prompt Generator")
|
| 90 |
+
output = gr.Textbox(label="Generated Prompts", lines=20)
|
| 91 |
+
btn = gr.Button("Generate 5 Prompts")
|
| 92 |
+
|
| 93 |
+
btn.click(fn=lambda: "\n\n".join(generate_five_prompts()), outputs=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
| 96 |
+
demo.launch()
|
| 97 |
+
|
|
|
|
|
|
|
|
|
|
|
|