Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -29,16 +29,13 @@ hf_client = InferenceClient(
|
|
| 29 |
VLM_MODEL = "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"
|
| 30 |
|
| 31 |
SYSTEM_PROMPT_TEXT_ONLY = """You are an expert prompt engineer for FLUX.2 by Black Forest Labs. Rewrite user prompts to be more descriptive while strictly preserving their core subject and intent.
|
| 32 |
-
|
| 33 |
Guidelines:
|
| 34 |
1. Structure: Keep structured inputs structured (enhance within fields). Convert natural language to detailed paragraphs.
|
| 35 |
2. Details: Add concrete visual specifics - form, scale, textures, materials, lighting (quality, direction, color), shadows, spatial relationships, and environmental context.
|
| 36 |
3. Text in Images: Put ALL text in quotation marks, matching the prompt's language. Always provide explicit quoted text for objects that would contain text in reality (signs, labels, screens, etc.) - without it, the model generates gibberish.
|
| 37 |
-
|
| 38 |
Output only the revised prompt and nothing else."""
|
| 39 |
|
| 40 |
SYSTEM_PROMPT_WITH_IMAGES = """You are FLUX.2 by Black Forest Labs, an image-editing expert. You convert editing requests into one concise instruction (50-80 words, ~30 for brief requests).
|
| 41 |
-
|
| 42 |
Rules:
|
| 43 |
- Single instruction only, no commentary
|
| 44 |
- Use clear, analytical language (avoid "whimsical," "cascading," etc.)
|
|
@@ -47,7 +44,6 @@ Rules:
|
|
| 47 |
- Turn negatives into positives ("don't change X" → "keep X")
|
| 48 |
- Make abstractions concrete ("futuristic" → "glowing cyan neon, metallic panels")
|
| 49 |
- Keep content PG-13
|
| 50 |
-
|
| 51 |
Output only the final instruction in plain text and nothing else."""
|
| 52 |
|
| 53 |
def remote_text_encoder(prompts):
|
|
@@ -81,7 +77,11 @@ pipe = Flux2Pipeline.from_pretrained(
|
|
| 81 |
pipe.to(device)
|
| 82 |
|
| 83 |
# Pull pre-compiled Flux2 Transformer blocks from HF hub
|
| 84 |
-
spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
def image_to_data_uri(img):
|
| 87 |
buffered = io.BytesIO()
|
|
|
|
| 29 |
VLM_MODEL = "baidu/ERNIE-4.5-VL-424B-A47B-Base-PT"
|
| 30 |
|
| 31 |
SYSTEM_PROMPT_TEXT_ONLY = """You are an expert prompt engineer for FLUX.2 by Black Forest Labs. Rewrite user prompts to be more descriptive while strictly preserving their core subject and intent.
|
|
|
|
| 32 |
Guidelines:
|
| 33 |
1. Structure: Keep structured inputs structured (enhance within fields). Convert natural language to detailed paragraphs.
|
| 34 |
2. Details: Add concrete visual specifics - form, scale, textures, materials, lighting (quality, direction, color), shadows, spatial relationships, and environmental context.
|
| 35 |
3. Text in Images: Put ALL text in quotation marks, matching the prompt's language. Always provide explicit quoted text for objects that would contain text in reality (signs, labels, screens, etc.) - without it, the model generates gibberish.
|
|
|
|
| 36 |
Output only the revised prompt and nothing else."""
|
| 37 |
|
| 38 |
SYSTEM_PROMPT_WITH_IMAGES = """You are FLUX.2 by Black Forest Labs, an image-editing expert. You convert editing requests into one concise instruction (50-80 words, ~30 for brief requests).
|
|
|
|
| 39 |
Rules:
|
| 40 |
- Single instruction only, no commentary
|
| 41 |
- Use clear, analytical language (avoid "whimsical," "cascading," etc.)
|
|
|
|
| 44 |
- Turn negatives into positives ("don't change X" → "keep X")
|
| 45 |
- Make abstractions concrete ("futuristic" → "glowing cyan neon, metallic panels")
|
| 46 |
- Keep content PG-13
|
|
|
|
| 47 |
Output only the final instruction in plain text and nothing else."""
|
| 48 |
|
| 49 |
def remote_text_encoder(prompts):
|
|
|
|
| 77 |
pipe.to(device)
|
| 78 |
|
| 79 |
# Pull pre-compiled Flux2 Transformer blocks from HF hub
|
| 80 |
+
# spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="fa3")
|
| 81 |
+
|
| 82 |
+
# 禁用编译,使用 SDPA 注意力
|
| 83 |
+
# pipe.transformer.config._attn_implementation = "sdpa"
|
| 84 |
+
# spaces.aoti_blocks_load(pipe.transformer, "zerogpu-aoti/FLUX.2", variant="sdpa")
|
| 85 |
|
| 86 |
def image_to_data_uri(img):
|
| 87 |
buffered = io.BytesIO()
|