Severian commited on
Commit
750c9c8
·
verified ·
1 Parent(s): 3afff73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -188,7 +188,7 @@ def generate_caption(text_model, tokenizer, image_features, prompt_str: str, max
188
  @torch.no_grad()
189
  def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str, caption_length: str | int, lens_type: str = "", film_stock: str = "", composition_style: str = "", lighting_aspect: str = "", special_technique: str = "", color_effect: str = "") -> str:
190
  """
191
- Generate a caption or style prompt based on the input image and parameters.
192
  """
193
  torch.cuda.empty_cache()
194
 
@@ -206,23 +206,39 @@ def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str,
206
  if prompt_key not in CAPTION_TYPE_MAP:
207
  raise ValueError(f"Invalid caption type: {prompt_key}")
208
 
209
- prompt_str = CAPTION_TYPE_MAP[prompt_key][0].format(length=length, word_count=length)
210
-
211
  if caption_type == "style_prompt":
212
- # Extract the key from the dropdown value
213
- lens_type_key = lens_type.split(":")[0].strip() if lens_type else ""
214
- film_stock_key = film_stock.split(":")[0].strip() if film_stock else ""
215
- composition_style_key = composition_style.split(":")[0].strip() if composition_style else ""
216
- lighting_aspect_key = lighting_aspect.split(":")[0].strip() if lighting_aspect else ""
217
- special_technique_key = special_technique.split(":")[0].strip() if special_technique else ""
218
- color_effect_key = color_effect.split(":")[0].strip() if color_effect else ""
219
-
220
- prompt_str += f" Lens type: {lens_type_key} ({lens_types_info[lens_type_key]}). " if lens_type_key else ""
221
- prompt_str += f"Film stock: {film_stock_key} ({film_stocks_info[film_stock_key]}). " if film_stock_key else ""
222
- prompt_str += f"Composition style: {composition_style_key} ({composition_styles_info[composition_style_key]}). " if composition_style_key else ""
223
- prompt_str += f"Lighting aspect: {lighting_aspect_key} ({lighting_aspects_info[lighting_aspect_key]}). " if lighting_aspect_key else ""
224
- prompt_str += f"Special technique: {special_technique_key} ({special_techniques_info[special_technique_key]}). " if special_technique_key else ""
225
- prompt_str += f"Color effect: {color_effect_key} ({color_effects_info[color_effect_key]})." if color_effect_key else ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  # Debugging: Print the constructed prompt string
228
  print(f"Constructed Prompt: {prompt_str}")
 
188
  @torch.no_grad()
189
  def stream_chat(input_image: Image.Image, caption_type: str, caption_tone: str, caption_length: str | int, lens_type: str = "", film_stock: str = "", composition_style: str = "", lighting_aspect: str = "", special_technique: str = "", color_effect: str = "") -> str:
190
  """
191
+ Generate a caption, training prompt, tags, or a style prompt for image generation based on the input image and parameters.
192
  """
193
  torch.cuda.empty_cache()
194
 
 
206
  if prompt_key not in CAPTION_TYPE_MAP:
207
  raise ValueError(f"Invalid caption type: {prompt_key}")
208
 
 
 
209
  if caption_type == "style_prompt":
210
+ # For style prompt, we'll create a custom prompt for the LLM
211
+ base_prompt = "Analyze the given image and create a detailed Stable Diffusion prompt for generating a new, creative image inspired by it. "
212
+ base_prompt += "The prompt should describe the main elements, style, and mood of the image, "
213
+ base_prompt += "but also introduce creative variations or enhancements. "
214
+ base_prompt += "Include specific details about the composition, lighting, and overall atmosphere. "
215
+
216
+ # Add custom settings to the prompt
217
+ if lens_type:
218
+ lens_type_key = lens_type.split(":")[0].strip()
219
+ base_prompt += f"Incorporate the effect of a {lens_type_key} lens ({lens_types_info[lens_type_key]}). "
220
+ if film_stock:
221
+ film_stock_key = film_stock.split(":")[0].strip()
222
+ base_prompt += f"Apply the characteristics of {film_stock_key} film stock ({film_stocks_info[film_stock_key]}). "
223
+ if composition_style:
224
+ composition_style_key = composition_style.split(":")[0].strip()
225
+ base_prompt += f"Use a {composition_style_key} composition style ({composition_styles_info[composition_style_key]}). "
226
+ if lighting_aspect:
227
+ lighting_aspect_key = lighting_aspect.split(":")[0].strip()
228
+ base_prompt += f"Implement {lighting_aspect_key} lighting ({lighting_aspects_info[lighting_aspect_key]}). "
229
+ if special_technique:
230
+ special_technique_key = special_technique.split(":")[0].strip()
231
+ base_prompt += f"Apply the {special_technique_key} technique ({special_techniques_info[special_technique_key]}). "
232
+ if color_effect:
233
+ color_effect_key = color_effect.split(":")[0].strip()
234
+ base_prompt += f"Use a {color_effect_key} color effect ({color_effects_info[color_effect_key]}). "
235
+
236
+ base_prompt += f"The final prompt should be approximately {length} words long. "
237
+ base_prompt += "Format the output as a single paragraph without numbering or bullet points."
238
+
239
+ prompt_str = base_prompt
240
+ else:
241
+ prompt_str = CAPTION_TYPE_MAP[prompt_key][0].format(length=length, word_count=length)
242
 
243
  # Debugging: Print the constructed prompt string
244
  print(f"Constructed Prompt: {prompt_str}")