ivanoctaviogaitansantos commited on
Commit
7134057
·
verified ·
1 Parent(s): 62a5c8c

Actualizar app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -199
app.py CHANGED
@@ -1,203 +1,97 @@
1
  import os
2
  import random
3
- import json
4
- from typing import Dict, Any, Optional
5
-
6
- class SimpleJSONCache:
7
- def __init__(self, filepath: str):
8
- self.filepath = filepath
9
- self._cache = self._load()
10
-
11
- def _load(self):
12
- if os.path.exists(self.filepath):
13
- try:
14
- with open(self.filepath, 'r', encoding='utf-8') as f:
15
- return json.load(f)
16
- except Exception:
17
- return {}
18
- else:
19
- return {}
20
-
21
- def get(self, key, default=None):
22
- return self._cache.get(key, default)
23
-
24
- def set(self, key, value):
25
- self._cache[key] = value
26
- try:
27
- with open(self.filepath, 'w', encoding='utf-8') as f:
28
- json.dump(self._cache, f, indent=2)
29
- except Exception as e:
30
- print(f"Error saving cache: {e}")
31
-
32
- class PromptGenerator:
33
- CACHE_KEY = "generated_prompts"
34
-
35
- def __init__(self, cache_path: str = "prompt_cache.json") -> None:
36
- self.cache = SimpleJSONCache(cache_path)
37
- self._load_defaults()
38
-
39
- def _load_defaults(self) -> None:
40
- self.ROLES = [
41
- "nurse", "nun", "doctor", "secretary", "teacher", "schoolgirl", "lawyer",
42
- "yoga instructor", "policewoman", "female military officer in gala uniform",
43
- "WWII-era secretary", "1960s flight attendant", "boudoir model",
44
- "elegant judge", "seductive librarian", "sensual model", "alluring secretary",
45
- "elegant flight attendant", "seductive maid", "mysterious nurse",
46
- "captivating schoolgirl", "business executive", "fitness model"
47
- ]
48
-
49
- self.HAIR_COLORS = [
50
- "deep sapphire blue", "silver platinum", "vibrant ruby red", "glossy jet black",
51
- "luxurious chestnut brown", "emerald green", "vivid amethyst purple",
52
- "chocolate brown", "honey blonde", "burgundy red"
53
- ]
54
-
55
- self.EYE_COLORS = [
56
- "intense brown", "bright sapphire blue", "emerald green", "golden amber",
57
- "fascinating hazel", "deep violet", "piercing emerald", "deep sapphire",
58
- "intense amber", "hypnotic hazel", "vibrant violet", "mysterious gray"
59
- ]
60
-
61
- self.HAIR_STYLES = [
62
- "long flowing chestnut hair styled in soft waves", "sleek straight long black hair",
63
- "luxurious long blonde curls", "elegant updo with loose cascading strands",
64
- "glossy long brunette hair parted in the middle", "long flowing waves",
65
- "luxurious straight hair", "voluminous curls", "elegant updo with cascading strands",
66
- "thick braid over the shoulder", "loose and silky layers", "messy chic bun"
67
- ]
68
-
69
- self.OUTFIT_TEMPLATES = {
70
- "nurse": "a classic short nurse dress, thigh-high stockings, semi-transparent lace panties subtly slipping down as if accidentally revealed beneath a skirt, no bra, elegant high heels",
71
- "nun": "a sensual interpretation of a nun's habit with a revealing long robe and thigh-high stockings, semi-transparent lace panties suggesting a playful accidental reveal, no bra, black stiletto heels",
72
- "doctor": "a daring white lab coat minidress left slightly open, thigh-high stockings, semi-transparent lace panties exposed subtly as if by chance, no bra, high heels",
73
- "secretary": "a provocative office pencil skirt and sheer blouse, thigh-high stockings, semi-transparent lace panties hinted at from a natural skirt shift, no bra, red high heels",
74
- "teacher": "a fitted blazer over a silk blouse and short skirt, thigh-high stockings, delicate lace panties subtly visible during natural movement, no bra, classic pumps",
75
- "schoolgirl": "a short pleated skirt and white blouse, thigh-high stockings, classic black lace panties slipping into view during casual poses, no bra, black loafers",
76
- "lawyer": "a tailored suit with skirt cut above knees, silk blouse unbuttoned slightly, thigh-high stockings, lace panties revealed subtly when seated, no bra, leather pumps",
77
- "yoga instructor": "form-fitting athletic wear that hugs curves, moisture-wicking fabric, lace panty lines subtly visible through tight clothing, sports bra barely containing",
78
- "policewoman": "a fitted police uniform with short skirt, thigh-high stockings, lace panties subtly showing during action poses, no bra, polished combat boots",
79
- "female military officer in gala uniform": "a ceremonial uniform with decorative elements, thigh-high stockings, lace panties hinted beneath tailored skirt, no bra, dress shoes",
80
- "WWII-era secretary": "vintage styled dress with seamed stockings, lace panties from era subtly revealed when bending, no bra, period-appropriate heels",
81
- "1960s flight attendant": "retro uniform with pillbox hat, thigh-high stockings, vintage lace panties subtly visible during graceful movements, no bra, classic heels",
82
- "boudoir model": "silk robe falling open, thigh-high stockings, intricate lace panties prominently displayed, no bra, feathered mules",
83
- "elegant judge": "judicial robes over a sophisticated dress, thigh-high stockings, luxury lace panties subtly revealed when robes part, no bra, court heels",
84
- "seductive librarian": "tight sweater and pencil skirt, thigh-high stockings, lace panties subtly visible when reaching for books, no bra, reading glasses",
85
- "sensual model": "designer evening gown with thigh slit, thigh-high stockings, luxury lace panties showcased during photo shoot poses, no bra, runway heels",
86
- "alluring secretary": "bodycon dress and blazer, thigh-high stockings, lace panties clearly outlined beneath fabric, no bra, stiletto pumps",
87
- "elegant flight attendant": "modern uniform with scarf, thigh-high stockings, lace panties subtly visible during boarding gestures, no bra, airline heels",
88
- "seductive maid": "traditional french maid costume shortened, thigh-high stockings, lace panties prominently displayed during cleaning poses, no bra,mary janes",
89
- "mysterious nurse": "night shift uniform with cape, thigh-high stockings, lace panties revealed during urgent movements, no bra, silent shoes",
90
- "captivating schoolgirl": "a short skirt and blouse with thigh-high stockings, classic black lace panties slipping into view, no bra, black patent heels",
91
- "business executive": "power suit with mini skirt, thigh-high stockings, luxury lace panties visible during confident walking, no bra, executive heels",
92
- "fitness model": "performance activewear, thigh-high athletic socks, sporty lace panties outlined during exercise poses, no bra, training shoes"
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
- generator = PromptGenerator()
199
- print("Generating 5 hyperrealistic humanized full-body prompts for individual characters:\n")
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
+