throaway2854 commited on
Commit
8ca7af9
1 Parent(s): f6ecefe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+
4
+ def generate_prompt(scene_tags, num_people, position_tags, characters, outfit_tags, camera_tags, concept_tags, lora_tags, num_tags=3):
5
+ all_tags = {
6
+ "scene": scene_tags.split(','),
7
+ "position": position_tags.split(','),
8
+ "outfit": outfit_tags.split(','),
9
+ "camera": camera_tags.split(','),
10
+ "concept": concept_tags.split(','),
11
+ }
12
+
13
+ # Remove empty strings and strip whitespace
14
+ for category in all_tags:
15
+ all_tags[category] = [tag.strip() for tag in all_tags[category] if tag.strip()]
16
+
17
+ # Process characters
18
+ character_list = [char.strip() for char in characters.split(';') if char.strip()]
19
+ character_prompts = []
20
+ for i, character in enumerate(character_list):
21
+ char_tags = character.split(',')
22
+ char_name = char_tags[0].strip()
23
+ char_traits = [tag.strip() for tag in char_tags[1:] if tag.strip()]
24
+ char_prompt = f"{char_name}, " + ", ".join(random.sample(char_traits, min(num_tags, len(char_traits))))
25
+ character_prompts.append(char_prompt)
26
+
27
+ # Generate main prompt
28
+ selected_tags = []
29
+ for category, tags in all_tags.items():
30
+ if tags:
31
+ selected_tags.extend(f"{tag}:{random.uniform(0.8, 1.2):.2f}" for tag in random.sample(tags, min(num_tags, len(tags))))
32
+
33
+ # Add number of people
34
+ if num_people.strip():
35
+ selected_tags.append(f"{num_people} people:1.1")
36
+
37
+ # Combine all parts of the prompt
38
+ prompt_parts = character_prompts + selected_tags
39
+ random.shuffle(prompt_parts)
40
+ main_prompt = ", ".join(prompt_parts)
41
+
42
+ # Add LORA tags
43
+ lora_list = [lora.strip() for lora in lora_tags.split(',') if lora.strip()]
44
+ lora_prompt = " ".join(f"<lora:{lora}:1>" for lora in lora_list)
45
+
46
+ # Add fixed tags at the end
47
+ fixed_tags = "source_anime, score_9, score_8_up, score_7_up, masterpiece, best quality, very aesthetic, absurdres, anime artwork, anime style, vibrant, studio anime, highly detailed"
48
+
49
+ full_prompt = f"{main_prompt}, {fixed_tags} {lora_prompt}".strip()
50
+ return full_prompt
51
+
52
+ def create_ui():
53
+ with gr.Blocks() as demo:
54
+ gr.Markdown("# Advanced Pony SDXL Prompt Generator")
55
+
56
+ with gr.Row():
57
+ with gr.Column():
58
+ scene_input = gr.Textbox(label="Scene Tags (comma-separated)")
59
+ num_people_input = gr.Textbox(label="Number of People")
60
+ position_input = gr.Textbox(label="Position Tags (comma-separated)")
61
+ characters_input = gr.Textbox(label="Characters (Format: Name, Trait1, Trait2; Name2, Trait1, Trait2)")
62
+ outfit_input = gr.Textbox(label="Outfit Tags (comma-separated)")
63
+ camera_input = gr.Textbox(label="Camera View/Angle Tags (comma-separated)")
64
+ concept_input = gr.Textbox(label="Concept Tags (comma-separated)")
65
+ lora_input = gr.Textbox(label="LORA Tags (comma-separated)")
66
+ num_tags_slider = gr.Slider(minimum=1, maximum=5, step=1, value=3, label="Number of tags per category")
67
+ generate_button = gr.Button("Generate Prompt")
68
+
69
+ with gr.Column():
70
+ output = gr.Textbox(label="Generated Prompt", lines=5)
71
+
72
+ generate_button.click(
73
+ generate_prompt,
74
+ inputs=[scene_input, num_people_input, position_input, characters_input, outfit_input, camera_input, concept_input, lora_input, num_tags_slider],
75
+ outputs=[output]
76
+ )
77
+
78
+ return demo
79
+
80
+ if __name__ == "__main__":
81
+ demo = create_ui()
82
+ demo.launch()