Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
e814de0
1
Parent(s):
b9877bd
next
Browse files- prompt_generator.py +2 -5
- ui_components.py +26 -19
prompt_generator.py
CHANGED
|
@@ -113,7 +113,6 @@ class PromptGenerator:
|
|
| 113 |
def load_next_data(self):
|
| 114 |
next_data = {}
|
| 115 |
next_path = os.path.join("data", "next")
|
| 116 |
-
print(f"Loading next data from: {next_path}")
|
| 117 |
for category in os.listdir(next_path):
|
| 118 |
category_path = os.path.join(next_path, category)
|
| 119 |
if os.path.isdir(category_path):
|
|
@@ -121,15 +120,12 @@ class PromptGenerator:
|
|
| 121 |
for file in os.listdir(category_path):
|
| 122 |
if file.endswith(".json"):
|
| 123 |
file_path = os.path.join(category_path, file)
|
| 124 |
-
print(f"Loading file: {file_path}")
|
| 125 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 126 |
json_data = json.load(f)
|
| 127 |
next_data[category][file[:-5]] = json_data
|
| 128 |
-
print(f"Loaded next_data: {next_data}")
|
| 129 |
return next_data
|
| 130 |
|
| 131 |
def process_next_data(self, prompt, separator, category, field, value):
|
| 132 |
-
print(f"Processing next data: category={category}, field={field}, value={value}")
|
| 133 |
if category in self.next_data and field in self.next_data[category]:
|
| 134 |
field_data = self.next_data[category][field]
|
| 135 |
|
|
@@ -328,7 +324,8 @@ class PromptGenerator:
|
|
| 328 |
combined_prompt = replaced + " " + " ".join(next_prompts)
|
| 329 |
combined_prompt = self.clean_consecutive_commas(combined_prompt)
|
| 330 |
|
| 331 |
-
|
|
|
|
| 332 |
|
| 333 |
def add_caption_to_prompt(self, prompt, caption):
|
| 334 |
if caption:
|
|
|
|
| 113 |
def load_next_data(self):
|
| 114 |
next_data = {}
|
| 115 |
next_path = os.path.join("data", "next")
|
|
|
|
| 116 |
for category in os.listdir(next_path):
|
| 117 |
category_path = os.path.join(next_path, category)
|
| 118 |
if os.path.isdir(category_path):
|
|
|
|
| 120 |
for file in os.listdir(category_path):
|
| 121 |
if file.endswith(".json"):
|
| 122 |
file_path = os.path.join(category_path, file)
|
|
|
|
| 123 |
with open(file_path, "r", encoding="utf-8") as f:
|
| 124 |
json_data = json.load(f)
|
| 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 |
|
|
|
|
| 324 |
combined_prompt = replaced + " " + " ".join(next_prompts)
|
| 325 |
combined_prompt = self.clean_consecutive_commas(combined_prompt)
|
| 326 |
|
| 327 |
+
# Return the processed string including next prompts
|
| 328 |
+
return self.process_string(combined_prompt.strip(), seed)
|
| 329 |
|
| 330 |
def add_caption_to_prompt(self, prompt, caption):
|
| 331 |
if caption:
|
ui_components.py
CHANGED
|
@@ -61,6 +61,22 @@ def create_interface():
|
|
| 61 |
photographer = gr.Dropdown(["disabled", "random"] + PHOTOGRAPHER, label="Photographer", value="disabled")
|
| 62 |
artist = gr.Dropdown(["disabled", "random"] + ARTIST, label="Artist", value="disabled")
|
| 63 |
digital_artform = gr.Dropdown(["disabled", "random"] + DIGITAL_ARTFORM, label="Digital Artform", value="disabled")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
generate_button = gr.Button("Generate Prompt")
|
| 66 |
|
|
@@ -102,20 +118,7 @@ def create_interface():
|
|
| 102 |
outputs=[caption_output]
|
| 103 |
)
|
| 104 |
|
| 105 |
-
|
| 106 |
-
next_components = {}
|
| 107 |
-
for category, fields in prompt_generator.next_data.items():
|
| 108 |
-
with gr.Accordion(f"{category.capitalize()} Options", open=False):
|
| 109 |
-
category_components = {}
|
| 110 |
-
for field, data in fields.items():
|
| 111 |
-
if isinstance(data, list):
|
| 112 |
-
options = ["None", "Random", "Multiple Random"] + data
|
| 113 |
-
elif isinstance(data, dict):
|
| 114 |
-
options = ["None", "Random", "Multiple Random"] + data.get("items", [])
|
| 115 |
-
else:
|
| 116 |
-
options = ["None", "Random", "Multiple Random"]
|
| 117 |
-
category_components[field] = gr.Dropdown(options, label=field.capitalize(), value="None")
|
| 118 |
-
next_components[category] = category_components
|
| 119 |
|
| 120 |
def generate_prompt_with_dynamic_seed(*args, **kwargs):
|
| 121 |
dynamic_seed = random.randint(0, 1000000)
|
|
@@ -125,19 +128,23 @@ def create_interface():
|
|
| 125 |
|
| 126 |
# Extract next_params
|
| 127 |
next_params = {}
|
|
|
|
|
|
|
| 128 |
for category, fields in prompt_generator.next_data.items():
|
| 129 |
category_params = {}
|
| 130 |
for field in fields:
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
| 133 |
if category_params:
|
| 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 |
-
|
| 140 |
-
main_prompt = result[0]
|
| 141 |
|
| 142 |
return [dynamic_seed] + list(result)
|
| 143 |
|
|
|
|
| 61 |
photographer = gr.Dropdown(["disabled", "random"] + PHOTOGRAPHER, label="Photographer", value="disabled")
|
| 62 |
artist = gr.Dropdown(["disabled", "random"] + ARTIST, label="Artist", value="disabled")
|
| 63 |
digital_artform = gr.Dropdown(["disabled", "random"] + DIGITAL_ARTFORM, label="Digital Artform", value="disabled")
|
| 64 |
+
|
| 65 |
+
# Add Next components
|
| 66 |
+
with gr.Accordion("More Detailed Prompt Options", open=False):
|
| 67 |
+
next_components = {}
|
| 68 |
+
for category, fields in prompt_generator.next_data.items():
|
| 69 |
+
with gr.Accordion(f"{category.capitalize()} Options", open=False):
|
| 70 |
+
category_components = {}
|
| 71 |
+
for field, data in fields.items():
|
| 72 |
+
if isinstance(data, list):
|
| 73 |
+
options = ["None", "Random", "Multiple Random"] + data
|
| 74 |
+
elif isinstance(data, dict):
|
| 75 |
+
options = ["None", "Random", "Multiple Random"] + data.get("items", [])
|
| 76 |
+
else:
|
| 77 |
+
options = ["None", "Random", "Multiple Random"]
|
| 78 |
+
category_components[field] = gr.Dropdown(options, label=field.capitalize(), value="None")
|
| 79 |
+
next_components[category] = category_components
|
| 80 |
|
| 81 |
generate_button = gr.Button("Generate Prompt")
|
| 82 |
|
|
|
|
| 118 |
outputs=[caption_output]
|
| 119 |
)
|
| 120 |
|
| 121 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
def generate_prompt_with_dynamic_seed(*args, **kwargs):
|
| 124 |
dynamic_seed = random.randint(0, 1000000)
|
|
|
|
| 128 |
|
| 129 |
# Extract next_params
|
| 130 |
next_params = {}
|
| 131 |
+
next_args = args[22:] # All arguments after the main ones are for next_params
|
| 132 |
+
next_arg_index = 0
|
| 133 |
for category, fields in prompt_generator.next_data.items():
|
| 134 |
category_params = {}
|
| 135 |
for field in fields:
|
| 136 |
+
value = next_args[next_arg_index]
|
| 137 |
+
# Include all values, even "None", "Random", and "Multiple Random"
|
| 138 |
+
category_params[field] = value
|
| 139 |
+
next_arg_index += 1
|
| 140 |
if category_params:
|
| 141 |
next_params[category] = category_params
|
| 142 |
|
| 143 |
+
print(next_params)
|
| 144 |
# Call generate_prompt with the correct arguments
|
| 145 |
result = prompt_generator.generate_prompt(dynamic_seed, *main_args, next_params=next_params)
|
| 146 |
+
|
| 147 |
+
print(result)
|
|
|
|
| 148 |
|
| 149 |
return [dynamic_seed] + list(result)
|
| 150 |
|