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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
import random
|
| 5 |
+
|
| 6 |
+
# Pipeline optimizado para CPU
|
| 7 |
+
generator = pipeline(
|
| 8 |
+
"text-generation",
|
| 9 |
+
model="gpt2",
|
| 10 |
+
max_new_tokens=100,
|
| 11 |
+
device=-1, # CPU
|
| 12 |
+
torch_dtype=torch.float32
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Plantilla base y listas
|
| 16 |
+
base_template = """
|
| 17 |
+
A hyper-realistic full-body portrait of {subject}, embodying the essence of {theme}. Rendered in {style} style with anatomical accuracy and lifelike skin texture.
|
| 18 |
+
|
| 19 |
+
The subject wears {outfit}, showing realistic fabric weave and soft transparency. Posing {pose}, {expression}. Gaze directed {gaze}. Set in {environment}, with {mood}. Cinematic lighting, HDR tone mapping, subsurface scattering, and fine material rendering.
|
| 20 |
+
|
| 21 |
+
**TECHNICAL SPECS:**
|
| 22 |
+
- Camera: {camera}
|
| 23 |
+
- Lens: {lens}
|
| 24 |
+
- Settings: {aperture}, {iso}, {shutter}
|
| 25 |
+
- Rendering: Unreal Engine 5.4, path tracing, PBR materials, micro-displacement
|
| 26 |
+
- Post-processing: Film color grading, subtle grain, HDR finish
|
| 27 |
+
|
| 28 |
+
**KEYWORDS:** ultra-detailed, photorealistic, cinematic, accurate anatomy, depth of field, realistic reflections, 8K resolution --ar 9:16 --style raw
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
subjects = [
|
| 32 |
+
"a sensual fitness instructor with honey-blonde wavy hair",
|
| 33 |
+
"a young woman with freckles and emerald eyes",
|
| 34 |
+
"an elegant secretary in a white silk blouse",
|
| 35 |
+
"a confident dancer in sheer black outfit",
|
| 36 |
+
"a seductive nurse with soft brown curls"
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
themes = ["serene confidence", "alluring mystery", "quiet elegance", "sensual focus", "feminine power"]
|
| 40 |
+
styles = ["cinematic realism", "hyperrealistic photography", "studio portrait lighting"]
|
| 41 |
+
outfits = [
|
| 42 |
+
"semi-transparent white lycra sportswear revealing a black lace thong",
|
| 43 |
+
"delicate lace corset and silk robe",
|
| 44 |
+
"tight pencil skirt and satin blouse",
|
| 45 |
+
"black sheer bodysuit with lace trim",
|
| 46 |
+
"minimal athletic top and form-fitting shorts"
|
| 47 |
+
]
|
| 48 |
+
poses = [
|
| 49 |
+
"stretching arms overhead, body slightly arched",
|
| 50 |
+
"leaning on a desk gracefully",
|
| 51 |
+
"sitting with crossed legs and soft posture",
|
| 52 |
+
"standing confidently with hands on hips",
|
| 53 |
+
"gently turning, one hand adjusting hair"
|
| 54 |
+
]
|
| 55 |
+
expressions = [
|
| 56 |
+
"a calm, inviting smile",
|
| 57 |
+
"a confident and alluring stare",
|
| 58 |
+
"a subtle, dreamy look",
|
| 59 |
+
"a playful smirk",
|
| 60 |
+
"a serene, introspective expression"
|
| 61 |
+
]
|
| 62 |
+
gazes = ["towards camera", "slightly to the side", "downwards softly", "upwards in thought"]
|
| 63 |
+
environments = [
|
| 64 |
+
"a modern gym with mirrored walls",
|
| 65 |
+
"a sunlit luxury bedroom",
|
| 66 |
+
"a high-end studio with soft backlight",
|
| 67 |
+
"a minimalist white room with reflections",
|
| 68 |
+
"a cinematic loft with ambient glow"
|
| 69 |
+
]
|
| 70 |
+
moods = ["peaceful and sensual", "intimate and cinematic", "warm and inviting", "bold and elegant"]
|
| 71 |
+
cameras = ["Canon EOS R5", "Sony α7R V", "Nikon Z9", "Fujifilm GFX 100S"]
|
| 72 |
+
lenses = ["RF 85mm f/1.2L", "FE 50mm f/1.4 GM", "Nikkor Z 70-200mm f/2.8"]
|
| 73 |
+
apertures = ["f/1.4", "f/1.8", "f/2.2"]
|
| 74 |
+
isos = ["ISO 100", "ISO 400", "ISO 800"]
|
| 75 |
+
shutters = ["1/200s", "1/250s", "1/320s"]
|
| 76 |
+
|
| 77 |
+
def generate_prompts_list(count, user_input=""):
|
| 78 |
+
count = max(1, min(int(count), 10))
|
| 79 |
+
prompts = []
|
| 80 |
+
subject = user_input.strip() if user_input else random.choice(subjects)
|
| 81 |
+
|
| 82 |
+
for i in range(count):
|
| 83 |
+
filled = base_template.format(
|
| 84 |
+
subject=subject,
|
| 85 |
+
theme=random.choice(themes),
|
| 86 |
+
style=random.choice(styles),
|
| 87 |
+
outfit=random.choice(outfits),
|
| 88 |
+
pose=random.choice(poses),
|
| 89 |
+
expression=random.choice(expressions),
|
| 90 |
+
gaze=random.choice(gazes),
|
| 91 |
+
environment=random.choice(environments),
|
| 92 |
+
mood=random.choice(moods),
|
| 93 |
+
camera=random.choice(cameras),
|
| 94 |
+
lens=random.choice(lenses),
|
| 95 |
+
aperture=random.choice(apertures),
|
| 96 |
+
iso=random.choice(isos),
|
| 97 |
+
shutter=random.choice(shutters)
|
| 98 |
+
)
|
| 99 |
+
try:
|
| 100 |
+
with torch.no_grad():
|
| 101 |
+
ai_output = generator(
|
| 102 |
+
f"Refine this prompt in natural English tone:\n{filled}",
|
| 103 |
+
do_sample=True,
|
| 104 |
+
temperature=0.7
|
| 105 |
+
)[0]["generated_text"]
|
| 106 |
+
except Exception as e:
|
| 107 |
+
ai_output = f"Error: {str(e)}\nOriginal: {filled}"
|
| 108 |
+
prompts.append(ai_output.strip())
|
| 109 |
+
return prompts
|
| 110 |
+
|
| 111 |
+
def create_prompt_blocks(count, user_input):
|
| 112 |
+
prompts = generate_prompts_list(count, user_input)
|
| 113 |
+
|
| 114 |
+
with gr.Blocks() as blocks_ui:
|
| 115 |
+
for i, prompt in enumerate(prompts, 1):
|
| 116 |
+
with gr.Group():
|
| 117 |
+
gr.Markdown(f"### Prompt #{i}")
|
| 118 |
+
with gr.Row():
|
| 119 |
+
textbox = gr.Textbox(
|
| 120 |
+
value=prompt,
|
| 121 |
+
lines=8,
|
| 122 |
+
max_lines=12,
|
| 123 |
+
show_copy_button=True,
|
| 124 |
+
container=False,
|
| 125 |
+
show_label=False
|
| 126 |
+
)
|
| 127 |
+
gr.Markdown("---")
|
| 128 |
+
|
| 129 |
+
return blocks_ui
|
| 130 |
+
|
| 131 |
+
with gr.Blocks(title="BATUTO - Generador de Prompts Hiperrealistas", theme=gr.themes.Soft()) as demo:
|
| 132 |
+
gr.Markdown("""
|
| 133 |
+
# 🎨 BATUTO - Generador de Prompts Hiperrealistas
|
| 134 |
+
Genera prompts detallados para crear imágenes hiperrealistas con IA
|
| 135 |
+
""")
|
| 136 |
+
|
| 137 |
+
with gr.Row():
|
| 138 |
+
with gr.Column(scale=3):
|
| 139 |
+
input_text = gr.Textbox(
|
| 140 |
+
label="Describe tu idea o personaje",
|
| 141 |
+
placeholder="Ejemplo: 'una mujer joven con cabello rojo en un estudio fotográfico'",
|
| 142 |
+
lines=2
|
| 143 |
+
)
|
| 144 |
+
with gr.Column(scale=1):
|
| 145 |
+
count_spinner = gr.Slider(
|
| 146 |
+
minimum=1,
|
| 147 |
+
maximum=10,
|
| 148 |
+
step=1,
|
| 149 |
+
value=3,
|
| 150 |
+
label="Número de prompts a generar"
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
generar_btn = gr.Button("✨ Generar Prompts", variant="primary", size="lg")
|
| 154 |
+
|
| 155 |
+
gr.Markdown("## 📝 Prompts Generados")
|
| 156 |
+
blocks_output = gr.HTML()
|
| 157 |
+
|
| 158 |
+
@generar_btn.click(inputs=[count_spinner, input_text], outputs=blocks_output)
|
| 159 |
+
def update_blocks(count, user_input):
|
| 160 |
+
prompts = generate_prompts_list(count, user_input)
|
| 161 |
+
|
| 162 |
+
html_blocks = ""
|
| 163 |
+
for i, prompt in enumerate(prompts, 1):
|
| 164 |
+
html_blocks += f"""
|
| 165 |
+
<div style="margin-bottom: 2rem; padding: 1.5rem; border: 1px solid #e0e0e0; border-radius: 10px; background: white;">
|
| 166 |
+
<h3 style="margin-top: 0; color: #2d3748;">Prompt #{i}</h3>
|
| 167 |
+
<div style="position: relative;">
|
| 168 |
+
<textarea
|
| 169 |
+
id="prompt-{i}"
|
| 170 |
+
style="width: 100%; height: 200px; padding: 1rem; border: 1px solid #d1d5db; border-radius: 8px; font-family: monospace; resize: vertical;"
|
| 171 |
+
readonly
|
| 172 |
+
>{prompt}</textarea>
|
| 173 |
+
<button
|
| 174 |
+
onclick="copyPrompt({i})"
|
| 175 |
+
style="position: absolute; top: 0.5rem; right: 0.5rem; padding: 0.5rem 1rem; background: #4f46e5; color: white; border: none; border-radius: 6px; cursor: pointer;"
|
| 176 |
+
>
|
| 177 |
+
📋 Copiar
|
| 178 |
+
</button>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
"""
|
| 182 |
+
|
| 183 |
+
# Añadir el script JavaScript para copiar
|
| 184 |
+
html_blocks += """
|
| 185 |
+
<script>
|
| 186 |
+
function copyPrompt(id) {
|
| 187 |
+
const textarea = document.getElementById('prompt-' + id);
|
| 188 |
+
textarea.select();
|
| 189 |
+
textarea.setSelectionRange(0, 99999);
|
| 190 |
+
document.execCommand('copy');
|
| 191 |
+
|
| 192 |
+
// Feedback visual
|
| 193 |
+
const button = event.target;
|
| 194 |
+
const originalText = button.textContent;
|
| 195 |
+
button.textContent = '✅ Copiado!';
|
| 196 |
+
button.style.background = '#10b981';
|
| 197 |
+
|
| 198 |
+
setTimeout(() => {
|
| 199 |
+
button.textContent = originalText;
|
| 200 |
+
button.style.background = '#4f46e5';
|
| 201 |
+
}, 2000);
|
| 202 |
+
}
|
| 203 |
+
</script>
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
return html_blocks
|
| 207 |
+
|
| 208 |
+
if __name__ == "__main__":
|
| 209 |
+
demo.launch()
|