Spaces:
Runtime error
Runtime error
gokaygokay
commited on
Commit
•
64a5a18
1
Parent(s):
e1a5eb1
next
Browse files- prompt_generator.py +5 -32
- ui_components.py +1 -1
prompt_generator.py
CHANGED
@@ -125,20 +125,14 @@ class PromptGenerator:
|
|
125 |
next_data[category][file[:-5]] = json_data
|
126 |
return next_data
|
127 |
|
128 |
-
def process_next_data(self, prompt, separator, category, field, value
|
129 |
if category in self.next_data and field in self.next_data[category]:
|
130 |
field_data = self.next_data[category][field]
|
131 |
|
132 |
if isinstance(field_data, list):
|
133 |
items = field_data
|
134 |
-
preprompt = ""
|
135 |
-
field_separator = ", "
|
136 |
-
endprompt = ""
|
137 |
elif isinstance(field_data, dict):
|
138 |
items = field_data.get("items", [])
|
139 |
-
preprompt = str(field_data.get("preprompt", "")).strip()
|
140 |
-
field_separator = f" {str(field_data.get('separator', ', ')).strip()} "
|
141 |
-
endprompt = str(field_data.get("endprompt", "")).strip()
|
142 |
else:
|
143 |
return prompt
|
144 |
|
@@ -152,35 +146,14 @@ class PromptGenerator:
|
|
152 |
else:
|
153 |
selected_items = [value]
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
item_str = str(item)
|
158 |
-
if attributes and "attributes" in field_data and item_str in field_data["attributes"]:
|
159 |
-
item_attributes = field_data["attributes"].get(item_str, [])
|
160 |
-
if item_attributes:
|
161 |
-
selected_attributes = self.rng.sample(item_attributes, min(3, len(item_attributes)))
|
162 |
-
formatted_items.append(f"{item_str} ({', '.join(map(str, selected_attributes))})")
|
163 |
-
else:
|
164 |
-
formatted_items.append(item_str)
|
165 |
-
else:
|
166 |
-
formatted_items.append(item_str)
|
167 |
-
|
168 |
-
formatted_values = field_separator.join(formatted_items)
|
169 |
-
formatted_addition = []
|
170 |
-
if preprompt:
|
171 |
-
formatted_addition.append(preprompt)
|
172 |
-
formatted_addition.append(formatted_values)
|
173 |
-
if endprompt:
|
174 |
-
formatted_addition.append(endprompt)
|
175 |
-
|
176 |
-
formatted_output = " ".join(formatted_addition).strip()
|
177 |
-
prompt += f" {formatted_output}"
|
178 |
|
179 |
return prompt
|
180 |
|
181 |
def generate_prompt(self, seed, custom, subject, gender, artform, photo_type, body_types, default_tags, roles, hairstyles,
|
182 |
-
|
183 |
-
|
184 |
kwargs = locals()
|
185 |
del kwargs['self']
|
186 |
del kwargs['next_params']
|
|
|
125 |
next_data[category][file[:-5]] = json_data
|
126 |
return next_data
|
127 |
|
128 |
+
def process_next_data(self, prompt, separator, category, field, value):
|
129 |
if category in self.next_data and field in self.next_data[category]:
|
130 |
field_data = self.next_data[category][field]
|
131 |
|
132 |
if isinstance(field_data, list):
|
133 |
items = field_data
|
|
|
|
|
|
|
134 |
elif isinstance(field_data, dict):
|
135 |
items = field_data.get("items", [])
|
|
|
|
|
|
|
136 |
else:
|
137 |
return prompt
|
138 |
|
|
|
146 |
else:
|
147 |
selected_items = [value]
|
148 |
|
149 |
+
formatted_values = separator.join(selected_items)
|
150 |
+
prompt += f"{separator}{formatted_values}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
return prompt
|
153 |
|
154 |
def generate_prompt(self, seed, custom, subject, gender, artform, photo_type, body_types, default_tags, roles, hairstyles,
|
155 |
+
additional_details, photography_styles, device, photographer, artist, digital_artform,
|
156 |
+
place, lighting, clothing, composition, pose, background, input_image, **next_params):
|
157 |
kwargs = locals()
|
158 |
del kwargs['self']
|
159 |
del kwargs['next_params']
|
ui_components.py
CHANGED
@@ -134,7 +134,7 @@ def create_interface():
|
|
134 |
next_params[category] = category_params
|
135 |
|
136 |
# Call generate_prompt with the correct arguments
|
137 |
-
result = prompt_generator.generate_prompt(dynamic_seed, *main_args,
|
138 |
|
139 |
return [dynamic_seed] + list(result)
|
140 |
|
|
|
134 |
next_params[category] = category_params
|
135 |
|
136 |
# Call generate_prompt with the correct arguments
|
137 |
+
result = prompt_generator.generate_prompt(dynamic_seed, *main_args, next_params=next_params)
|
138 |
|
139 |
return [dynamic_seed] + list(result)
|
140 |
|