Spaces:
Running
on
Zero
Running
on
Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1019,10 +1019,31 @@ def do_polish_prompt(prompt: str, style: str, do_polish: bool, mode: str = "gene
|
|
| 1019 |
return final_prompt, polished
|
| 1020 |
|
| 1021 |
def do_polish_transform_prompt(prompt: str, style: str, do_polish: bool) -> Tuple[str, str]:
|
| 1022 |
-
"""Polish prompt for transformation (style-focused).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1023 |
if not do_polish:
|
| 1024 |
-
base = prompt.strip()
|
| 1025 |
-
final = base +
|
| 1026 |
return final, ""
|
| 1027 |
|
| 1028 |
return do_polish_prompt(prompt, style, True, mode="transform")
|
|
@@ -1075,8 +1096,13 @@ def generate_with_polish(prompt: str, style: str, do_polish: bool, ratio: str, s
|
|
| 1075 |
def transform_with_polish(input_image: Optional[Image.Image], prompt: str, style: str, do_polish: bool, strength: float, steps: int, seed: int, randomize: bool):
|
| 1076 |
"""Unified transform with progress feedback using generator.
|
| 1077 |
Yields intermediate status updates with timer so user knows what's happening.
|
|
|
|
|
|
|
|
|
|
| 1078 |
"""
|
| 1079 |
-
|
|
|
|
|
|
|
| 1080 |
|
| 1081 |
# Start timer
|
| 1082 |
timer = GenerationTimer()
|
|
@@ -1086,8 +1112,11 @@ def transform_with_polish(input_image: Optional[Image.Image], prompt: str, style
|
|
| 1086 |
yield None, create_status_html("Please upload an image first", timer.format(), is_generating=False).replace("✅", "❌"), 0
|
| 1087 |
return
|
| 1088 |
|
| 1089 |
-
#
|
| 1090 |
-
if
|
|
|
|
|
|
|
|
|
|
| 1091 |
yield None, create_status_html("Enhancing prompt with DeepSeek Reasoner", timer.format()), 0
|
| 1092 |
else:
|
| 1093 |
yield None, create_status_html("Preparing transformation", timer.format()), 0
|
|
@@ -2053,7 +2082,7 @@ with gr.Blocks(title="Z Image Turbo", css=css, theme=dark_theme) as demo:
|
|
| 2053 |
with gr.Row():
|
| 2054 |
with gr.Column(scale=2):
|
| 2055 |
trans_input = gr.Image(label="Upload Image", type="pil", height=300)
|
| 2056 |
-
trans_prompt = gr.Textbox(label="Transformation Prompt", placeholder="
|
| 2057 |
trans_polish = gr.Checkbox(label="Prompt+ by deepseek-reasoner", value=False)
|
| 2058 |
with gr.Row():
|
| 2059 |
trans_style = gr.Dropdown(choices=STYLES, value="None", label="Style")
|
|
|
|
| 1019 |
return final_prompt, polished
|
| 1020 |
|
| 1021 |
def do_polish_transform_prompt(prompt: str, style: str, do_polish: bool) -> Tuple[str, str]:
|
| 1022 |
+
"""Polish prompt for transformation (style-focused).
|
| 1023 |
+
|
| 1024 |
+
When a style is selected without a prompt, the style suffix contains all the
|
| 1025 |
+
information needed to guide the transformation. No prompt is required.
|
| 1026 |
+
"""
|
| 1027 |
+
style_suffix = STYLE_SUFFIXES.get(style, "")
|
| 1028 |
+
has_prompt = prompt and prompt.strip()
|
| 1029 |
+
has_style = style and style != "None" and style_suffix
|
| 1030 |
+
|
| 1031 |
+
# Style-only transformation: use style as the complete transformation guide
|
| 1032 |
+
if not has_prompt and has_style:
|
| 1033 |
+
# Remove leading comma and space from suffix to make it a primary prompt
|
| 1034 |
+
style_prompt = style_suffix.lstrip(", ").strip()
|
| 1035 |
+
display = f"[{style} Style] {style_prompt[:100]}..." if len(style_prompt) > 100 else f"[{style} Style] {style_prompt}"
|
| 1036 |
+
logger.info(f"do_polish_transform_prompt: Style-only transform with {style}")
|
| 1037 |
+
return style_prompt, display
|
| 1038 |
+
|
| 1039 |
+
# No prompt and no style - use generic enhancement
|
| 1040 |
+
if not has_prompt and not has_style:
|
| 1041 |
+
return "high quality image, enhanced details, professional quality", ""
|
| 1042 |
+
|
| 1043 |
+
# Has prompt - proceed with normal flow
|
| 1044 |
if not do_polish:
|
| 1045 |
+
base = prompt.strip()
|
| 1046 |
+
final = base + style_suffix
|
| 1047 |
return final, ""
|
| 1048 |
|
| 1049 |
return do_polish_prompt(prompt, style, True, mode="transform")
|
|
|
|
| 1096 |
def transform_with_polish(input_image: Optional[Image.Image], prompt: str, style: str, do_polish: bool, strength: float, steps: int, seed: int, randomize: bool):
|
| 1097 |
"""Unified transform with progress feedback using generator.
|
| 1098 |
Yields intermediate status updates with timer so user knows what's happening.
|
| 1099 |
+
|
| 1100 |
+
Style-only transformation: When a style is selected without a prompt, the style
|
| 1101 |
+
suffix contains all the information needed to guide the transformation.
|
| 1102 |
"""
|
| 1103 |
+
has_prompt = prompt and prompt.strip()
|
| 1104 |
+
has_style = style and style != "None"
|
| 1105 |
+
logger.info(f"transform_with_polish: do_polish={do_polish}, style={style}, has_prompt={has_prompt}, has_style={has_style}")
|
| 1106 |
|
| 1107 |
# Start timer
|
| 1108 |
timer = GenerationTimer()
|
|
|
|
| 1112 |
yield None, create_status_html("Please upload an image first", timer.format(), is_generating=False).replace("✅", "❌"), 0
|
| 1113 |
return
|
| 1114 |
|
| 1115 |
+
# Show appropriate initial status based on transformation type
|
| 1116 |
+
if not has_prompt and has_style:
|
| 1117 |
+
# Style-only transformation
|
| 1118 |
+
yield None, create_status_html(f"Applying {style} style transformation", timer.format()), 0
|
| 1119 |
+
elif do_polish and has_prompt:
|
| 1120 |
yield None, create_status_html("Enhancing prompt with DeepSeek Reasoner", timer.format()), 0
|
| 1121 |
else:
|
| 1122 |
yield None, create_status_html("Preparing transformation", timer.format()), 0
|
|
|
|
| 2082 |
with gr.Row():
|
| 2083 |
with gr.Column(scale=2):
|
| 2084 |
trans_input = gr.Image(label="Upload Image", type="pil", height=300)
|
| 2085 |
+
trans_prompt = gr.Textbox(label="Transformation Prompt (optional if style selected)", placeholder="Optional: describe changes, or just select a Style below (Van Gogh, Picasso, etc.)", lines=3)
|
| 2086 |
trans_polish = gr.Checkbox(label="Prompt+ by deepseek-reasoner", value=False)
|
| 2087 |
with gr.Row():
|
| 2088 |
trans_style = gr.Dropdown(choices=STYLES, value="None", label="Style")
|