PSNbst commited on
Commit
9180f04
·
verified ·
1 Parent(s): 38f52fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -23
app.py CHANGED
@@ -10,12 +10,12 @@ from dotenv import load_dotenv
10
  load_dotenv()
11
 
12
  # ========== 默认选项和数据 ==========
13
- EXPRESSIONS = ["smiling", "determined", "surprised", "serene", "laughing", "angry", "pensive", "confident"]
14
- ITEMS = ["magic wand", "sword", "flower", "book of spells", "ancient scroll", "music instrument", "shield", "dagger", "staff", "potion"]
15
- OTHER_DETAILS = ["sparkles", "magical aura", "lens flare", "fireworks in the background", "smoke effects", "light trails", "falling leaves", "glowing embers"]
16
- SCENES = ["sunset beach", "rainy city street at night", "fantasy forest with glowing mushrooms", "futuristic skyline at dawn", "abandoned castle", "snowy mountain peak", "desert ruins", "underwater city"]
17
- CAMERA_ANGLES = ["low-angle shot", "close-up shot", "bird's-eye view", "wide-angle shot", "over-the-shoulder shot", "extreme close-up", "panoramic view", "dynamic tracking shot"]
18
- QUALITY_PROMPTS = ["cinematic lighting", "award-winning", "masterpiece", "vivid colors", "high dynamic range", "immersive", "studio quality", "fine art", "dreamlike", "8K", "HD", "high quality", "best quality"]
19
 
20
  # Hugging Face DTR 数据集路径
21
  DTR_DATASET_PATTERN = "https://huggingface.co/datasets/X779/Danbooruwildcards/resolve/main/*DTR*.txt"
@@ -70,9 +70,9 @@ def generate_natural_language_description(tags, api_key=None, base_url=None, mod
70
  {
71
  "role": "system",
72
  "content": (
73
- "You are a creative assistant that generates vivid and imaginative scene descriptions for painting prompts. "
74
  "Focus on the details provided and incorporate them into a cohesive narrative. "
75
- "Use at least three sentences."
76
  ),
77
  },
78
  {
@@ -89,23 +89,23 @@ def generate_natural_language_description(tags, api_key=None, base_url=None, mod
89
  def generate_prompt(
90
  action_file, style_file, artist_files, character_files, dtr_enabled, api_key, selected_categories,
91
  expression_count, item_count, detail_count, scene_count, angle_count, quality_count, action_count, style_count,
92
- use_deepseek, deepseek_key
93
  ):
94
  """
95
  生成随机提示词和描述。
96
  """
97
  actions = get_random_items(load_candidates_from_files([action_file]) if action_file else [], action_count)
98
  styles = get_random_items(load_candidates_from_files([style_file]) if style_file else [], style_count)
99
- artists = get_random_items(load_candidates_from_files(artist_files) if artist_files else [], 1)
100
  characters = get_random_items(load_candidates_from_files(character_files) if character_files else [], 1)
101
  dtr_candidates = get_random_items(load_dtr_from_huggingface() if dtr_enabled else [], 1)
102
 
103
- number_of_characters = ", ".join(selected_categories) if selected_categories else random.choice(["1girl", "1boy"])
104
 
105
  tags = {
106
  "number_of_characters": number_of_characters,
107
  "character_name": characters,
108
- "artist_prompt": f"(artist:{artists})",
109
  "style": styles,
110
  "scene": get_random_items(SCENES, scene_count),
111
  "camera_angle": get_random_items(CAMERA_ANGLES, angle_count),
@@ -148,7 +148,7 @@ def gradio_interface():
148
  type="password"
149
  )
150
 
151
- use_deepseek = gr.Checkbox(label="Use DeepSeek API")
152
 
153
  with gr.Row():
154
  action_file = gr.File(label="Upload Action File (Optional)", file_types=[".txt"])
@@ -158,7 +158,7 @@ def gradio_interface():
158
  artist_files = gr.Files(label="Upload Artist Files (Multiple Allowed)", file_types=[".txt"])
159
  character_files = gr.Files(label="Upload Character Files (Multiple Allowed)", file_types=[".txt"])
160
 
161
- dtr_enabled = gr.Checkbox(label="Enable DTR")
162
 
163
  selected_categories = gr.CheckboxGroup(
164
  ["1boy", "1girl", "furry", "mecha", "fantasy monster", "animal", "still life"],
@@ -166,16 +166,17 @@ def gradio_interface():
166
  )
167
 
168
  with gr.Row():
169
- expression_count = gr.Slider(label="Number of Expressions", minimum=1, maximum=5, step=1, value=1)
170
- item_count = gr.Slider(label="Number of Items", minimum=1, maximum=5, step=1, value=1)
171
- detail_count = gr.Slider(label="Number of Other Details", minimum=1, maximum=5, step=1, value=1)
172
- scene_count = gr.Slider(label="Number of Scenes", minimum=1, maximum=5, step=1, value=1)
173
 
174
  with gr.Row():
175
- angle_count = gr.Slider(label="Number of Camera Angles", minimum=1, maximum=5, step=1, value=1)
176
- quality_count = gr.Slider(label="Number of Quality Prompts", minimum=1, maximum=5, step=1, value=1)
177
- action_count = gr.Slider(label="Number of Actions", minimum=1, maximum=5, step=1, value=1)
178
- style_count = gr.Slider(label="Number of Styles", minimum=1, maximum=5, step=1, value=1)
 
179
 
180
  with gr.Row():
181
  tags_output = gr.Textbox(label="Generated Tags")
@@ -189,7 +190,7 @@ def gradio_interface():
189
  inputs=[
190
  action_file, style_file, artist_files, character_files, dtr_enabled, api_key_input, selected_categories,
191
  expression_count, item_count, detail_count, scene_count, angle_count, quality_count, action_count, style_count,
192
- use_deepseek, deepseek_key_input
193
  ],
194
  outputs=[tags_output, description_output, combined_output],
195
  )
 
10
  load_dotenv()
11
 
12
  # ========== 默认选项和数据 ==========
13
+ EXPRESSIONS = ["smiling", "determined", "surprised", "serene", "smug", "thinking", "looking back", "laughing", "angry", "pensive", "confident", "grinning", "thoughtful", "sad tears", "bewildered"]
14
+ ITEMS = ["magic wand", "sword", "flower", "book of spells", "earrings", "loincloth", "slippers", "ancient scroll", "music instrument", "shield", "dagger", "headband", "leg ties", "staff", "potion", "crystal ball", "anklet", "ribbon", "lantern", "amulet", "ring"]
15
+ OTHER_DETAILS = ["sparkles", "magical aura", "lens flare", "fireworks in the background", "smoke effects", "light trails", "falling leaves", "glowing embers", "floating particles", "rays of light", "shimmering mist", "ethereal glow"]
16
+ SCENES = ["sunset beach", "rainy city street at night", "floating ash land", "particles magic world", "high blue sky", "top of the building", "fantasy forest with glowing mushrooms", "futuristic skyline at dawn", "abandoned castle", "snowy mountain peak", "desert ruins", "underwater city", "enchanted meadow", "haunted mansion", "steampunk marketplace", "glacial cavern"]
17
+ CAMERA_ANGLES = ["low-angle shot", "close-up shot", "bird's-eye view", "wide-angle shot", "over-the-shoulder shot", "extreme close-up", "panoramic view", "dynamic tracking shot", "fisheye view", "point-of-view shot"]
18
+ QUALITY_PROMPTS = ["cinematic lighting", "sharp shadow", "award-winning", "masterpiece", "vivid colors", "high dynamic range", "immersive", "studio quality", "fine art", "dreamlike", "8K", "HD", "high quality", "best quality", "artistic", "vibrant"]
19
 
20
  # Hugging Face DTR 数据集路径
21
  DTR_DATASET_PATTERN = "https://huggingface.co/datasets/X779/Danbooruwildcards/resolve/main/*DTR*.txt"
 
70
  {
71
  "role": "system",
72
  "content": (
73
+ "You are a creative assistant that generates detailed and imaginative scene descriptions for AI generation prompts. "
74
  "Focus on the details provided and incorporate them into a cohesive narrative. "
75
+ "Use at least three sentences but no more than five sentences"
76
  ),
77
  },
78
  {
 
89
  def generate_prompt(
90
  action_file, style_file, artist_files, character_files, dtr_enabled, api_key, selected_categories,
91
  expression_count, item_count, detail_count, scene_count, angle_count, quality_count, action_count, style_count,
92
+ artist_count, use_deepseek, deepseek_key
93
  ):
94
  """
95
  生成随机提示词和描述。
96
  """
97
  actions = get_random_items(load_candidates_from_files([action_file]) if action_file else [], action_count)
98
  styles = get_random_items(load_candidates_from_files([style_file]) if style_file else [], style_count)
99
+ artists = get_random_items(load_candidates_from_files(artist_files) if artist_files else [], artist_count)
100
  characters = get_random_items(load_candidates_from_files(character_files) if character_files else [], 1)
101
  dtr_candidates = get_random_items(load_dtr_from_huggingface() if dtr_enabled else [], 1)
102
 
103
+ number_of_characters = ", ".join(selected_categories) if selected_categories else [])
104
 
105
  tags = {
106
  "number_of_characters": number_of_characters,
107
  "character_name": characters,
108
+ "artist_prompt": f"(artist:{', '.join(artists)})",
109
  "style": styles,
110
  "scene": get_random_items(SCENES, scene_count),
111
  "camera_angle": get_random_items(CAMERA_ANGLES, angle_count),
 
148
  type="password"
149
  )
150
 
151
+ use_deepseek = gr.Checkbox(label="Use DeepSeek API - 用DeepSeek别忘了勾选这个")
152
 
153
  with gr.Row():
154
  action_file = gr.File(label="Upload Action File (Optional)", file_types=[".txt"])
 
158
  artist_files = gr.Files(label="Upload Artist Files (Multiple Allowed)", file_types=[".txt"])
159
  character_files = gr.Files(label="Upload Character Files (Multiple Allowed)", file_types=[".txt"])
160
 
161
+ dtr_enabled = gr.Checkbox(label="Enable DTR - 当前不可用2025-01-12")
162
 
163
  selected_categories = gr.CheckboxGroup(
164
  ["1boy", "1girl", "furry", "mecha", "fantasy monster", "animal", "still life"],
 
166
  )
167
 
168
  with gr.Row():
169
+ expression_count = gr.Slider(label="Number of Expressions", minimum=0, maximum=10, step=1, value=1)
170
+ item_count = gr.Slider(label="Number of Items", minimum=0, maximum=10, step=1, value=1)
171
+ detail_count = gr.Slider(label="Number of Other Details", minimum=0, maximum=10, step=1, value=1)
172
+ scene_count = gr.Slider(label="Number of Scenes", minimum=0, maximum=10, step=1, value=1)
173
 
174
  with gr.Row():
175
+ angle_count = gr.Slider(label="Number of Camera Angles", minimum=0, maximum=10, step=1, value=1)
176
+ quality_count = gr.Slider(label="Number of Quality Prompts", minimum=0, maximum=10, step=1, value=1)
177
+ action_count = gr.Slider(label="Number of Actions", minimum=1, maximum=10, step=1, value=1)
178
+ style_count = gr.Slider(label="Number of Styles", minimum=1, maximum=10, step=1, value=1)
179
+ artist_count = gr.Slider(label="Number of Artists", minimum=1, maximum=10, step=1, value=1)
180
 
181
  with gr.Row():
182
  tags_output = gr.Textbox(label="Generated Tags")
 
190
  inputs=[
191
  action_file, style_file, artist_files, character_files, dtr_enabled, api_key_input, selected_categories,
192
  expression_count, item_count, detail_count, scene_count, angle_count, quality_count, action_count, style_count,
193
+ artist_count, use_deepseek, deepseek_key_input
194
  ],
195
  outputs=[tags_output, description_output, combined_output],
196
  )