Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -715,19 +715,61 @@ def generate_prompt_with_glm(image_description: str, user_request: str, style: s
|
|
| 715 |
if not image_description or image_description.startswith("Please") or image_description.startswith("Error") or image_description.startswith("GLM API") or image_description.startswith("Could not"):
|
| 716 |
return "Please analyze the image first."
|
| 717 |
|
| 718 |
-
|
| 719 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 720 |
|
| 721 |
client = get_deepseek_client()
|
| 722 |
if not client:
|
| 723 |
return "DeepSeek API key not configured. Please add DEEPSEEK_API_KEY to space secrets."
|
| 724 |
|
| 725 |
-
style_hint = f" Apply style: {style}." if style and style != "None" else ""
|
| 726 |
desc = image_description[:MAX_DESCRIPTION_LENGTH] if len(image_description) > MAX_DESCRIPTION_LENGTH else image_description
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
|
| 728 |
-
|
|
|
|
| 729 |
|
| 730 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
|
| 732 |
GLOBAL RULE: Your output text CANNOT exceed 4000 TOKENS. This is a strict limit. Output ONLY the prompt text itself.
|
| 733 |
|
|
@@ -739,13 +781,8 @@ ABSOLUTELY FORBIDDEN - NEVER OUTPUT THESE:
|
|
| 739 |
- Word counting or token counting
|
| 740 |
- ANY text that is not the actual image prompt
|
| 741 |
|
| 742 |
-
|
| 743 |
-
"
|
| 744 |
-
"Here is the transformed prompt: A beautiful sunset..."
|
| 745 |
-
"The key elements to include are: lighting, colors..."
|
| 746 |
-
|
| 747 |
-
CORRECT (pure prompt only):
|
| 748 |
-
"A majestic ballroom scene rendered in vibrant anime style, elegant dancers in flowing silk gowns with rich velvet textures, crystal chandeliers casting warm golden light, polished marble floor with soft reflections, romantic atmosphere with floating rose petals"
|
| 749 |
|
| 750 |
OUTPUT THE IMAGE PROMPT NOW - NOTHING ELSE:"""
|
| 751 |
|
|
@@ -755,7 +792,7 @@ OUTPUT THE IMAGE PROMPT NOW - NOTHING ELSE:"""
|
|
| 755 |
max_tokens=4000,
|
| 756 |
messages=[
|
| 757 |
{"role": "system", "content": system_prompt},
|
| 758 |
-
{"role": "user", "content":
|
| 759 |
],
|
| 760 |
)
|
| 761 |
|
|
|
|
| 715 |
if not image_description or image_description.startswith("Please") or image_description.startswith("Error") or image_description.startswith("GLM API") or image_description.startswith("Could not"):
|
| 716 |
return "Please analyze the image first."
|
| 717 |
|
| 718 |
+
has_style = style and style != "None"
|
| 719 |
+
has_request = user_request and user_request.strip()
|
| 720 |
+
|
| 721 |
+
# Allow style-only generation (no user request needed if style is selected)
|
| 722 |
+
if not has_request and not has_style:
|
| 723 |
+
return "Please describe what changes you want or select a style."
|
| 724 |
|
| 725 |
client = get_deepseek_client()
|
| 726 |
if not client:
|
| 727 |
return "DeepSeek API key not configured. Please add DEEPSEEK_API_KEY to space secrets."
|
| 728 |
|
|
|
|
| 729 |
desc = image_description[:MAX_DESCRIPTION_LENGTH] if len(image_description) > MAX_DESCRIPTION_LENGTH else image_description
|
| 730 |
+
|
| 731 |
+
# Get the full style details from STYLE_SUFFIXES
|
| 732 |
+
style_details = STYLE_SUFFIXES.get(style, "").lstrip(", ").strip() if has_style else ""
|
| 733 |
+
|
| 734 |
+
# Build the user message based on what's provided
|
| 735 |
+
if has_style and has_request:
|
| 736 |
+
# Both style and custom request
|
| 737 |
+
user_content = f"""ORIGINAL IMAGE DESCRIPTION:
|
| 738 |
+
{desc}
|
| 739 |
+
|
| 740 |
+
STYLE TO APPLY: {style}
|
| 741 |
+
STYLE DETAILS (use these painting techniques): {style_details}
|
| 742 |
+
|
| 743 |
+
ADDITIONAL CHANGES REQUESTED: {user_request}
|
| 744 |
+
|
| 745 |
+
Generate a prompt that transforms the image into this painting style while incorporating the requested changes."""
|
| 746 |
+
elif has_style:
|
| 747 |
+
# Style only - no custom request
|
| 748 |
+
user_content = f"""ORIGINAL IMAGE DESCRIPTION:
|
| 749 |
+
{desc}
|
| 750 |
|
| 751 |
+
STYLE TO APPLY: {style}
|
| 752 |
+
STYLE DETAILS (use these painting techniques): {style_details}
|
| 753 |
|
| 754 |
+
Generate a prompt that transforms this image into a {style}. Describe the scene as it would appear painted in this style, incorporating all the painting techniques and visual characteristics listed above."""
|
| 755 |
+
else:
|
| 756 |
+
# Custom request only - no style
|
| 757 |
+
user_content = f"""ORIGINAL IMAGE DESCRIPTION:
|
| 758 |
+
{desc}
|
| 759 |
+
|
| 760 |
+
REQUESTED CHANGES: {user_request}
|
| 761 |
+
|
| 762 |
+
Generate a prompt that describes the transformed image."""
|
| 763 |
+
|
| 764 |
+
system_prompt = """You are an image prompt generator specialized in painting style transformations. Output ONLY the final prompt - nothing else.
|
| 765 |
+
|
| 766 |
+
TASK: Generate a detailed image prompt that describes how the original image would look after transformation.
|
| 767 |
+
|
| 768 |
+
When a PAINTING STYLE is specified (Van Gogh, Picasso, etc.):
|
| 769 |
+
- You MUST incorporate ALL the painting technique details provided
|
| 770 |
+
- Describe the scene AS A PAINTING with visible brushstrokes, paint textures, canvas texture
|
| 771 |
+
- Include the specific color palette, brushwork style, and artistic characteristics of that painter
|
| 772 |
+
- The output should clearly be a PAINTING, not a photo
|
| 773 |
|
| 774 |
GLOBAL RULE: Your output text CANNOT exceed 4000 TOKENS. This is a strict limit. Output ONLY the prompt text itself.
|
| 775 |
|
|
|
|
| 781 |
- Word counting or token counting
|
| 782 |
- ANY text that is not the actual image prompt
|
| 783 |
|
| 784 |
+
CORRECT OUTPUT EXAMPLE (Van Gogh style):
|
| 785 |
+
"A post-impressionist oil painting of a ballroom scene in the style of Vincent van Gogh, elegant dancers rendered with thick impasto brushstrokes, swirling dynamic patterns in the ceiling and walls, vibrant cadmium yellows and cobalt blues in the chandeliers creating luminous glowing halos, visible canvas texture beneath bold expressive paint layers, the figures painted with short choppy directional marks, emotional intensity through saturated complementary colors"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
|
| 787 |
OUTPUT THE IMAGE PROMPT NOW - NOTHING ELSE:"""
|
| 788 |
|
|
|
|
| 792 |
max_tokens=4000,
|
| 793 |
messages=[
|
| 794 |
{"role": "system", "content": system_prompt},
|
| 795 |
+
{"role": "user", "content": user_content}
|
| 796 |
],
|
| 797 |
)
|
| 798 |
|