Update app.py
Browse files
app.py
CHANGED
|
@@ -31,102 +31,128 @@ def analyze_python_code(code: str) -> str:
|
|
| 31 |
tools = [analyze_python_code]
|
| 32 |
|
| 33 |
# Inicializa el agente con herramientas y modelo
|
| 34 |
-
#
|
| 35 |
agent = CodeAgent(
|
| 36 |
tools=tools,
|
| 37 |
model=model,
|
| 38 |
add_base_tools=False
|
| 39 |
)
|
| 40 |
|
| 41 |
-
# DATOS PARA GENERACIÓN DE PERSONAJES INVENTADOS (
|
| 42 |
FICTIONAL_ROLES = [
|
| 43 |
-
"
|
| 44 |
-
"Galactic Rogue", "Urban Shaman", "Silent Assassin", "Chrononaut Captain", "Arcane Detective", "Desert Nomad"
|
| 45 |
]
|
| 46 |
HAIR_STYLES = [
|
| 47 |
-
"long
|
| 48 |
-
"
|
| 49 |
-
"shaved head with glowing runes", "icy blue waterfall hair", "dark purple pigtails"
|
| 50 |
]
|
|
|
|
| 51 |
OUTFIT_THEMES = [
|
| 52 |
-
"a
|
| 53 |
-
"
|
| 54 |
-
"a
|
| 55 |
-
"a
|
| 56 |
-
"
|
|
|
|
| 57 |
]
|
| 58 |
-
EYE_COLORS = ["gold", "iridescent blue", "vibrant purple", "deep emerald green", "flaming orange", "silver"
|
| 59 |
-
|
| 60 |
|
|
|
|
| 61 |
SETTINGS = [
|
| 62 |
-
"
|
| 63 |
-
"
|
| 64 |
-
"
|
| 65 |
-
"
|
| 66 |
-
"
|
|
|
|
| 67 |
]
|
| 68 |
|
|
|
|
| 69 |
ACTIVITIES = [
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
-
"
|
| 73 |
-
"
|
| 74 |
-
"
|
|
|
|
| 75 |
]
|
| 76 |
|
| 77 |
LINGERIE_COLORS = ["black", "red", "white", "navy blue", "deep burgundy"]
|
| 78 |
STOCKING_DETAILS = ["a delicate back seam", "intricate lace pattern", "classic fishnet design", "smooth satin finish", "subtle floral embroidery"]
|
| 79 |
HEEL_DETAILS = ["sharp stiletto heels", "elegant kitten heels", "strappy high heels", "sleek patent leather pumps", "classic pointed toe heels"]
|
| 80 |
POSES = ["confident stance, one hand on hip", "sitting casually on a desk", "leaning slightly forward", "standing with arms crossed", "walking with a playful smile"]
|
| 81 |
-
EXPRESSIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def generate_prompt(role, hair_style, outfit_theme, eye_color, setting, activity, lingerie_color, stocking_detail, heel_detail, pose, expression, prompt_num):
|
| 84 |
"""
|
| 85 |
-
Genera un prompt en
|
| 86 |
-
y
|
| 87 |
"""
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
f"
|
| 93 |
-
f"
|
| 94 |
-
f"
|
| 95 |
-
f"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
"
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
def chat_with_agent(user_message, history):
|
| 132 |
user_message_clean = user_message.strip().lower()
|
|
@@ -138,41 +164,43 @@ def chat_with_agent(user_message, history):
|
|
| 138 |
# Selección única de componentes para asegurar 5 PROMPTS NO REPETIDOS
|
| 139 |
try:
|
| 140 |
# Componentes del personaje
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
| 154 |
|
| 155 |
except ValueError as e:
|
| 156 |
-
return history + [[user_message, f"Error: Una de las listas de componentes tiene menos de
|
| 157 |
|
| 158 |
|
| 159 |
for i in range(num_prompts):
|
| 160 |
# Se llama a la función con el set de componentes único para el índice 'i'
|
| 161 |
-
|
| 162 |
unique_roles[i],
|
| 163 |
unique_hair_styles[i],
|
| 164 |
unique_outfit_themes[i],
|
| 165 |
unique_eye_colors[i],
|
| 166 |
unique_settings[i],
|
| 167 |
unique_activities[i],
|
| 168 |
-
unique_lingerie_colors[i],
|
| 169 |
-
unique_stocking_details[i],
|
| 170 |
-
unique_heel_details[i],
|
| 171 |
-
unique_poses[i],
|
| 172 |
-
unique_expressions[i],
|
| 173 |
i + 1
|
| 174 |
)
|
| 175 |
-
|
|
|
|
| 176 |
|
| 177 |
return history + [[user_message, "\n\n".join(prompts)]]
|
| 178 |
|
|
@@ -182,7 +210,7 @@ def chat_with_agent(user_message, history):
|
|
| 182 |
return history + [[user_message, analysis_result]]
|
| 183 |
|
| 184 |
else:
|
| 185 |
-
return history + [[user_message, "Por favor, escribe 'Ok' para generar cinco prompts en **formato
|
| 186 |
|
| 187 |
with gr.Blocks() as demo:
|
| 188 |
gr.Markdown("## Generador de Prompts Hiperrealistas y Análisis de Código Python")
|
|
@@ -197,5 +225,4 @@ with gr.Blocks() as demo:
|
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
demo.launch(share=False)
|
| 200 |
-
|
| 201 |
|
|
|
|
| 31 |
tools = [analyze_python_code]
|
| 32 |
|
| 33 |
# Inicializa el agente con herramientas y modelo
|
| 34 |
+
# Se mantiene add_base_tools=False para evitar el error de dependencia 'ddgs'.
|
| 35 |
agent = CodeAgent(
|
| 36 |
tools=tools,
|
| 37 |
model=model,
|
| 38 |
add_base_tools=False
|
| 39 |
)
|
| 40 |
|
| 41 |
+
# DATOS PARA GENERACIÓN DE PERSONAJES INVENTADOS (TEMAS DE ROL ESPECÍFICOS)
|
| 42 |
FICTIONAL_ROLES = [
|
| 43 |
+
"Secretary", "Nurse", "Schoolgirl", "Maid", "Flight Attendant", "Nun"
|
|
|
|
| 44 |
]
|
| 45 |
HAIR_STYLES = [
|
| 46 |
+
"long wavy auburn hair", "short, tight black bun", "blonde pigtails",
|
| 47 |
+
"long cascading brunette hair", "high, professional chignon", "simple black veil over long hair"
|
|
|
|
| 48 |
]
|
| 49 |
+
# OUTFITS REVISADOS para ser ajustados/sugerentes y acordes al rol
|
| 50 |
OUTFIT_THEMES = [
|
| 51 |
+
"a tight pencil skirt and partially unbuttoned blouse",
|
| 52 |
+
"a fitted, short-hemline nurse's uniform dress",
|
| 53 |
+
"a classic plaid schoolgirl uniform with a short pleated skirt",
|
| 54 |
+
"a short black maid uniform with a tight corset and white lace apron",
|
| 55 |
+
"a fitted aeromoza jacket and pencil skirt",
|
| 56 |
+
"a severe black habit with exposed décolletage"
|
| 57 |
]
|
| 58 |
+
EYE_COLORS = ["gold", "iridescent blue", "vibrant purple", "deep emerald green", "flaming orange", "silver"]
|
|
|
|
| 59 |
|
| 60 |
+
# SETTINGS REVISADOS: Ambientes cotidianos, no Sci-Fi/Neon
|
| 61 |
SETTINGS = [
|
| 62 |
+
"vintage wood-paneled private office with an antique desk",
|
| 63 |
+
"hospital examining room during a quiet moment",
|
| 64 |
+
"empty classroom after hours, moonlight streaming through the window",
|
| 65 |
+
"opulent vintage hotel suite with plush velvet furniture",
|
| 66 |
+
"first-class airplane cabin during a long haul flight",
|
| 67 |
+
"silent, dimly lit stone chapel corridor"
|
| 68 |
]
|
| 69 |
|
| 70 |
+
# ACTIVITIES REVISADAS: Poses que revelan la ropa interior desde ángulos bajos
|
| 71 |
ACTIVITIES = [
|
| 72 |
+
"bending over a desk to pick up a dropped pen",
|
| 73 |
+
"climbing a short set of stairs, lifting the hemline slightly",
|
| 74 |
+
"adjusting a stocking while sitting casually on a chair",
|
| 75 |
+
"leaning over a counter to wipe a surface with a playful smirk",
|
| 76 |
+
"reaching for a top-shelf luggage compartment",
|
| 77 |
+
"kneeling to pray on a marble floor"
|
| 78 |
]
|
| 79 |
|
| 80 |
LINGERIE_COLORS = ["black", "red", "white", "navy blue", "deep burgundy"]
|
| 81 |
STOCKING_DETAILS = ["a delicate back seam", "intricate lace pattern", "classic fishnet design", "smooth satin finish", "subtle floral embroidery"]
|
| 82 |
HEEL_DETAILS = ["sharp stiletto heels", "elegant kitten heels", "strappy high heels", "sleek patent leather pumps", "classic pointed toe heels"]
|
| 83 |
POSES = ["confident stance, one hand on hip", "sitting casually on a desk", "leaning slightly forward", "standing with arms crossed", "walking with a playful smile"]
|
| 84 |
+
# EXPRESSIONS REVISADAS: Enfocadas en el deseo y contacto visual
|
| 85 |
+
EXPRESSIONS = [
|
| 86 |
+
"a knowing, seductive smile directed at the viewer",
|
| 87 |
+
"an intense, lustful gaze locking with the camera",
|
| 88 |
+
"a confident, alluring smirk and eye contact",
|
| 89 |
+
"a playful wink and inviting stare",
|
| 90 |
+
"a soft, inviting smile with direct eye contact"
|
| 91 |
+
]
|
| 92 |
|
| 93 |
def generate_prompt(role, hair_style, outfit_theme, eye_color, setting, activity, lingerie_color, stocking_detail, heel_detail, pose, expression, prompt_num):
|
| 94 |
"""
|
| 95 |
+
Genera un prompt en texto plano en inglés con enfoque en Low-Angle, lencería de encaje
|
| 96 |
+
y contacto visual seductor.
|
| 97 |
"""
|
| 98 |
+
|
| 99 |
+
# 1. Main prompt (Description)
|
| 100 |
+
main_prompt_start = "A beautiful perfect cosplay of a"
|
| 101 |
+
main_prompt_details = (
|
| 102 |
+
f"{main_prompt_start} **{role}** (Invented Character) in a hyper-realistic, high-fashion editorial photograph. "
|
| 103 |
+
f"Full body shot (Plano entero), **occupying the entire frame** with a perfect body proportion. "
|
| 104 |
+
f"Featuring **{hair_style}** and **{eye_color} eyes**. "
|
| 105 |
+
f"Her suggestive main attire is **{outfit_theme}**. "
|
| 106 |
+
f"Underneath, she is wearing a transparent **{lingerie_color} lace thong** and matching lace bra, "
|
| 107 |
+
f"accentuated by thigh-high stockings with {stocking_detail}. "
|
| 108 |
+
f"Paired with {heel_detail}. Posed in a {pose} and **{expression}** in a {setting}. "
|
| 109 |
+
f"The character is captured while **{activity}**.\n"
|
| 110 |
)
|
| 111 |
|
| 112 |
+
# 2. Technical and style modifiers
|
| 113 |
+
style_modifiers = [
|
| 114 |
+
"High-fashion editorial photography style",
|
| 115 |
+
"Hiper-realistic CGI by Blizzard Entertainment",
|
| 116 |
+
"Fotografía de Alexander Nanitchkov",
|
| 117 |
+
"Escaneado 3D de personaje AAA",
|
| 118 |
+
"Unreal Engine 5 Ray Tracing",
|
| 119 |
+
"Detalles epidérmicos con Mapas 8K"
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
# 3. Physics and Effects
|
| 123 |
+
# La fisiología se mantiene perfecta, pero se elimina la atmósfera sci-fi/neon
|
| 124 |
+
physics_effects = [
|
| 125 |
+
"Physiology: Enhanced Human Proportions (Athlete body, subtle supernatural modifications)",
|
| 126 |
+
"Texture: Realistic skin imperfections (pores, scars, blemishes), Sub-surface scattering reflections on skin",
|
| 127 |
+
"Clothing: Realistic fabric sheen, Wear and tear imperfections on clothes/props"
|
| 128 |
+
]
|
| 129 |
+
|
| 130 |
+
# 4. Negative prompt (coalesced)
|
| 131 |
+
negative_prompt_keywords = [
|
| 132 |
+
"cartoon", "blurry", "pixelated", "low-resolution", "watermark", "noise", "overexposed", "underexposed",
|
| 133 |
+
"unnatural shadows", "color banding", "oversaturation", "artificial textures", "disallowed artifacts"
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
+
# 5. Combining all parts into a cohesive text block
|
| 137 |
+
final_text = (
|
| 138 |
+
f"PROMPT {prompt_num} (Title: Editorial Shoot - {role}):\n\n"
|
| 139 |
+
f"{main_prompt_details}\n"
|
| 140 |
+
f"--- METADATA & ANGLES ---\n"
|
| 141 |
+
f"Aspect Ratio: 9:16. Shot Type: Full-Body Shot (Plano entero) - **Low-Angle (Worm's Eye View)**.\n"
|
| 142 |
+
f"Angle Focus: Shot from a very low position looking upward, creating visual lines toward the underwear area.\n"
|
| 143 |
+
f"Camera: Hasselblad H6D-400c with 80mm f/2.8 lens. Aperture: f/4 (Reduced Depth of Field).\n"
|
| 144 |
+
f"Lighting: Rembrandt lighting, ARRI SkyPanel S360-C illumination. Selective depth of field focusing on the area of interest.\n\n"
|
| 145 |
+
f"--- STYLES & REFERENCES ---\n"
|
| 146 |
+
f"{', '.join(style_modifiers)}\n\n"
|
| 147 |
+
f"--- PHYSICS & DETAILING ---\n"
|
| 148 |
+
f"{' | '.join(physics_effects)}\n\n"
|
| 149 |
+
f"--- NEGATIVE PROMPT ---\n"
|
| 150 |
+
f"Exclude: {', '.join(negative_prompt_keywords)}\n\n"
|
| 151 |
+
f"--- SIGNATURE ---\n"
|
| 152 |
+
f"Signature Tag: BATUTO'ART (Graffiti Tag, Top-Left, 5%)"
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
return final_text
|
| 156 |
|
| 157 |
def chat_with_agent(user_message, history):
|
| 158 |
user_message_clean = user_message.strip().lower()
|
|
|
|
| 164 |
# Selección única de componentes para asegurar 5 PROMPTS NO REPETIDOS
|
| 165 |
try:
|
| 166 |
# Componentes del personaje
|
| 167 |
+
# Usamos min(6, len(LISTA)) para garantizar que no falle si se reduce la lista de datos.
|
| 168 |
+
unique_roles = random.sample(FICTIONAL_ROLES, min(num_prompts, len(FICTIONAL_ROLES)))
|
| 169 |
+
unique_hair_styles = random.sample(HAIR_STYLES, min(num_prompts, len(HAIR_STYLES)))
|
| 170 |
+
unique_outfit_themes = random.sample(OUTFIT_THEMES, min(num_prompts, len(OUTFIT_THEMES)))
|
| 171 |
+
unique_eye_colors = random.sample(EYE_COLORS, min(num_prompts, len(EYE_COLORS)))
|
| 172 |
+
|
| 173 |
+
# Componentes de la escena
|
| 174 |
+
unique_settings = random.sample(SETTINGS, min(num_prompts, len(SETTINGS)))
|
| 175 |
+
unique_activities = random.sample(ACTIVITIES, min(num_prompts, len(ACTIVITIES)))
|
| 176 |
+
unique_lingerie_colors = random.sample(LINGERIE_COLORS, min(num_prompts, len(LINGERIE_COLORS)))
|
| 177 |
+
unique_stocking_details = random.sample(STOCKING_DETAILS, min(num_prompts, len(STOCKING_DETAILS)))
|
| 178 |
+
unique_heel_details = random.sample(HEEL_DETAILS, min(num_prompts, len(HEEL_DETAILS)))
|
| 179 |
+
unique_poses = random.sample(POSES, min(num_prompts, len(POSES)))
|
| 180 |
+
unique_expressions = random.sample(EXPRESSIONS, min(num_prompts, len(EXPRESSIONS)))
|
| 181 |
|
| 182 |
except ValueError as e:
|
| 183 |
+
return history + [[user_message, f"Error: Una de las listas de componentes tiene menos de {num_prompts} elementos y no se puede generar un set único de 5 prompts. Por favor, asegúrate de que las listas tengan al menos {num_prompts} elementos. Error detallado: {e}"]]
|
| 184 |
|
| 185 |
|
| 186 |
for i in range(num_prompts):
|
| 187 |
# Se llama a la función con el set de componentes único para el índice 'i'
|
| 188 |
+
prompt_text = generate_prompt(
|
| 189 |
unique_roles[i],
|
| 190 |
unique_hair_styles[i],
|
| 191 |
unique_outfit_themes[i],
|
| 192 |
unique_eye_colors[i],
|
| 193 |
unique_settings[i],
|
| 194 |
unique_activities[i],
|
| 195 |
+
unique_lingerie_colors[i % len(LINGERIE_COLORS)], # Usar módulo para listas más cortas
|
| 196 |
+
unique_stocking_details[i % len(STOCKING_DETAILS)],
|
| 197 |
+
unique_heel_details[i % len(HEEL_DETAILS)],
|
| 198 |
+
unique_poses[i % len(POSES)],
|
| 199 |
+
unique_expressions[i % len(EXPRESSIONS)],
|
| 200 |
i + 1
|
| 201 |
)
|
| 202 |
+
# Se envuelve la salida de texto plano en un bloque de código monoscape
|
| 203 |
+
prompts.append(f"\n```\n{prompt_text}\n```")
|
| 204 |
|
| 205 |
return history + [[user_message, "\n\n".join(prompts)]]
|
| 206 |
|
|
|
|
| 210 |
return history + [[user_message, analysis_result]]
|
| 211 |
|
| 212 |
else:
|
| 213 |
+
return history + [[user_message, "Por favor, escribe 'Ok' para generar cinco prompts en **formato de texto plano monoscape**, o 'codigo:' seguido del código Python para analizarlo y corregirlo."]]
|
| 214 |
|
| 215 |
with gr.Blocks() as demo:
|
| 216 |
gr.Markdown("## Generador de Prompts Hiperrealistas y Análisis de Código Python")
|
|
|
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
demo.launch(share=False)
|
|
|
|
| 228 |
|