Update app.py
Browse files
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 |
-
#
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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}")
|