Actualizar app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,6 @@ def analyze_python_code(code: str) -> str:
|
|
| 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,
|
|
@@ -92,136 +91,123 @@ EXPRESSIONS = [
|
|
| 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
|
| 96 |
-
y contacto visual seductor.
|
| 97 |
"""
|
| 98 |
|
| 99 |
-
# 1. Main prompt (
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
f"
|
| 103 |
-
f"
|
| 104 |
-
f"
|
| 105 |
-
f"
|
| 106 |
-
f"
|
| 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
|
| 113 |
-
|
| 114 |
-
"
|
| 115 |
-
"
|
| 116 |
-
"
|
| 117 |
-
"Escaneado 3D de personaje AAA"
|
| 118 |
-
"
|
| 119 |
-
|
| 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 |
-
#
|
| 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"
|
| 139 |
-
f"{
|
| 140 |
-
f"
|
| 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()
|
| 159 |
|
| 160 |
-
if user_message_clean
|
| 161 |
-
prompts = []
|
| 162 |
-
num_prompts = 5
|
| 163 |
-
|
| 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 |
-
|
| 207 |
-
elif user_message_clean.startswith("codigo:") or user_message_clean.startswith("code:"):
|
| 208 |
code_to_analyze = user_message.split(":", 1)[1].strip()
|
| 209 |
analysis_result = analyze_python_code(code_to_analyze)
|
| 210 |
return history + [[user_message, analysis_result]]
|
| 211 |
|
| 212 |
else:
|
| 213 |
-
return history + [[user_message, "Por favor, escribe '
|
| 214 |
|
| 215 |
with gr.Blocks() as demo:
|
| 216 |
gr.Markdown("## Generador de Prompts Hiperrealistas y Análisis de Código Python")
|
| 217 |
chatbot = gr.Chatbot(label="Historial de Conversación", height=400)
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
msg.submit(chat_with_agent, [msg, chatbot], chatbot, queue=False).then(
|
| 222 |
lambda: gr.update(value="", interactive=True), None, msg, queue=False
|
| 223 |
)
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
if __name__ == "__main__":
|
| 227 |
demo.launch(share=False)
|
|
|
|
| 31 |
tools = [analyze_python_code]
|
| 32 |
|
| 33 |
# Inicializa el agente con herramientas y modelo
|
|
|
|
| 34 |
agent = CodeAgent(
|
| 35 |
tools=tools,
|
| 36 |
model=model,
|
|
|
|
| 91 |
|
| 92 |
def generate_prompt(role, hair_style, outfit_theme, eye_color, setting, activity, lingerie_color, stocking_detail, heel_detail, pose, expression, prompt_num):
|
| 93 |
"""
|
| 94 |
+
Genera un prompt en texto plano, humanizado y optimizado en inglés.
|
|
|
|
| 95 |
"""
|
| 96 |
|
| 97 |
+
# 1. Main prompt (Humanized and integrated)
|
| 98 |
+
main_prompt = (
|
| 99 |
+
f"A beautiful perfect cosplay of a {role} (Invented Character). Full body shot, Low-Angle (Worm's Eye View). The character is captured while {activity} in a {setting}. "
|
| 100 |
+
f"The shot is taken from a very low position looking upward, creating strong visual lines toward the underwear area. "
|
| 101 |
+
f"She has {hair_style} and {eye_color} eyes, with a perfect athlete body proportion. "
|
| 102 |
+
f"Her suggestive attire is {outfit_theme}. Underneath, she wears a transparent {lingerie_color} lace thong and matching lace bra, "
|
| 103 |
+
f"accentuated by thigh-high stockings with {stocking_detail} and {heel_detail}. "
|
| 104 |
+
f"The character is posed in a {pose} and maintains {expression}, always looking at the viewer with desire. "
|
|
|
|
|
|
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
+
# 2. Technical and Style Modifiers (Optimized for flow)
|
| 108 |
+
technical_and_style = (
|
| 109 |
+
f"Technical Details: Aspect Ratio: 9:16. Shot Type: Full-Body Shot (Plano entero). Camera: Hasselblad H6D-400c with 80mm f/2.8 lens. "
|
| 110 |
+
f"Lighting: Rembrandt lighting, ARRI SkyPanel S360-C illumination. Aperture: f/4 (Reduced Depth of Field). "
|
| 111 |
+
f"Focus: Selective depth of field focusing on the area of interest. "
|
| 112 |
+
f"Style: High-fashion editorial photography, Hiper-realistic CGI by Blizzard Entertainment, Fotografía de Alexander Nanitchkov, Escaneado 3D de personaje AAA, Unreal Engine 5 Ray Tracing, Detalles epidérmicos con Mapas 8K. "
|
| 113 |
+
f"Physics: Enhanced Human Proportions, Realistic skin imperfections (pores, scars, blemishes), Sub-surface scattering reflections on skin, Realistic fabric sheen. "
|
| 114 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
# 3. Negative prompt (Clean list)
|
| 117 |
negative_prompt_keywords = [
|
| 118 |
"cartoon", "blurry", "pixelated", "low-resolution", "watermark", "noise", "overexposed", "underexposed",
|
| 119 |
"unnatural shadows", "color banding", "oversaturation", "artificial textures", "disallowed artifacts"
|
| 120 |
]
|
| 121 |
|
|
|
|
| 122 |
final_text = (
|
| 123 |
+
f"{main_prompt} "
|
| 124 |
+
f"{technical_and_style} "
|
| 125 |
+
f"Negative Prompt: {', '.join(negative_prompt_keywords)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
return final_text
|
| 129 |
|
| 130 |
+
# Nueva función para generar los prompts sin entrada de usuario "Ok"
|
| 131 |
+
def generate_five_prompts(history):
|
| 132 |
+
prompts = []
|
| 133 |
+
num_prompts = 5
|
| 134 |
+
|
| 135 |
+
# Selección única de componentes para asegurar 5 PROMPTS NO REPETIDOS
|
| 136 |
+
try:
|
| 137 |
+
# Componentes del personaje
|
| 138 |
+
unique_roles = random.sample(FICTIONAL_ROLES, min(num_prompts, len(FICTIONAL_ROLES)))
|
| 139 |
+
unique_hair_styles = random.sample(HAIR_STYLES, min(num_prompts, len(HAIR_STYLES)))
|
| 140 |
+
unique_outfit_themes = random.sample(OUTFIT_THEMES, min(num_prompts, len(OUTFIT_THEMES)))
|
| 141 |
+
unique_eye_colors = random.sample(EYE_COLORS, min(num_prompts, len(EYE_COLORS)))
|
| 142 |
+
|
| 143 |
+
# Componentes de la escena
|
| 144 |
+
unique_settings = random.sample(SETTINGS, min(num_prompts, len(SETTINGS)))
|
| 145 |
+
unique_activities = random.sample(ACTIVITIES, min(num_prompts, len(ACTIVITIES)))
|
| 146 |
+
unique_lingerie_colors = random.sample(LINGERIE_COLORS, min(num_prompts, len(LINGERIE_COLORS)))
|
| 147 |
+
unique_stocking_details = random.sample(STOCKING_DETAILS, min(num_prompts, len(STOCKING_DETAILS)))
|
| 148 |
+
unique_heel_details = random.sample(HEEL_DETAILS, min(num_prompts, len(HEEL_DETAILS)))
|
| 149 |
+
unique_poses = random.sample(POSES, min(num_prompts, len(POSES)))
|
| 150 |
+
unique_expressions = random.sample(EXPRESSIONS, min(num_prompts, len(EXPRESSIONS)))
|
| 151 |
+
|
| 152 |
+
except ValueError as e:
|
| 153 |
+
# Simplemente devuelve un error sin agregar al historial si la generación falla
|
| 154 |
+
return history + [["", f"Error de generación: Una de las listas de componentes es demasiado corta. Error: {e}"]]
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
for i in range(num_prompts):
|
| 158 |
+
prompt_text = generate_prompt(
|
| 159 |
+
unique_roles[i],
|
| 160 |
+
unique_hair_styles[i],
|
| 161 |
+
unique_outfit_themes[i],
|
| 162 |
+
unique_eye_colors[i],
|
| 163 |
+
unique_settings[i],
|
| 164 |
+
unique_activities[i],
|
| 165 |
+
unique_lingerie_colors[i % len(LINGERIE_COLORS)],
|
| 166 |
+
unique_stocking_details[i % len(STOCKING_DETAILS)],
|
| 167 |
+
unique_heel_details[i % len(HEEL_DETAILS)],
|
| 168 |
+
unique_poses[i % len(POSES)],
|
| 169 |
+
unique_expressions[i % len(EXPRESSIONS)],
|
| 170 |
+
i + 1
|
| 171 |
+
)
|
| 172 |
+
# Se genera la salida para el chat
|
| 173 |
+
prompts.append(f"### PROMPT {i + 1} ({unique_roles[i].upper()}):\n{prompt_text}\n")
|
| 174 |
+
|
| 175 |
+
# Se añade la salida al historial como si el agente hubiera respondido
|
| 176 |
+
# La parte del usuario se deja vacía o se puede poner una etiqueta
|
| 177 |
+
return history + [["Generación Automática Solicitada", "\n\n".join(prompts)]]
|
| 178 |
+
|
| 179 |
+
|
| 180 |
def chat_with_agent(user_message, history):
|
| 181 |
user_message_clean = user_message.strip().lower()
|
| 182 |
|
| 183 |
+
if user_message_clean.startswith("codigo:") or user_message_clean.startswith("code:"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
code_to_analyze = user_message.split(":", 1)[1].strip()
|
| 185 |
analysis_result = analyze_python_code(code_to_analyze)
|
| 186 |
return history + [[user_message, analysis_result]]
|
| 187 |
|
| 188 |
else:
|
| 189 |
+
return history + [[user_message, "Por favor, escribe 'codigo:' seguido del código Python para analizarlo y corregirlo, o haz clic en **'Generar Prompts'**."]]
|
| 190 |
|
| 191 |
with gr.Blocks() as demo:
|
| 192 |
gr.Markdown("## Generador de Prompts Hiperrealistas y Análisis de Código Python")
|
| 193 |
chatbot = gr.Chatbot(label="Historial de Conversación", height=400)
|
| 194 |
+
|
| 195 |
+
# Contenedor para el botón y la caja de texto
|
| 196 |
+
with gr.Row():
|
| 197 |
+
msg = gr.Textbox(label="Escribe 'codigo:' seguido del código Python para análisis", scale=4)
|
| 198 |
+
generate_btn = gr.Button("Generar Prompts", scale=1)
|
| 199 |
+
clear_btn = gr.Button("Limpiar", scale=1)
|
| 200 |
+
|
| 201 |
+
# Lógica de envío de la caja de texto (solo para código)
|
| 202 |
msg.submit(chat_with_agent, [msg, chatbot], chatbot, queue=False).then(
|
| 203 |
lambda: gr.update(value="", interactive=True), None, msg, queue=False
|
| 204 |
)
|
| 205 |
+
|
| 206 |
+
# Lógica del nuevo botón (para generación automática)
|
| 207 |
+
generate_btn.click(generate_five_prompts, [chatbot], chatbot, queue=False)
|
| 208 |
+
|
| 209 |
+
# Lógica del botón de limpiar
|
| 210 |
+
clear_btn.click(lambda: None, None, chatbot, queue=False)
|
| 211 |
|
| 212 |
if __name__ == "__main__":
|
| 213 |
demo.launch(share=False)
|