Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,16 @@ def load_model():
|
|
| 19 |
"""Load the model on CPU first, then move to GPU when needed"""
|
| 20 |
global pipe
|
| 21 |
if pipe is None:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
return pipe
|
| 27 |
|
| 28 |
# --- Core Inference Function for ChatInterface ---
|
|
@@ -80,20 +86,8 @@ guidance_slider = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, s
|
|
| 80 |
steps_slider = gr.Slider(label="Steps", minimum=1, maximum=30, value=28, step=1)
|
| 81 |
|
| 82 |
# --- Examples without external URLs ---
|
| 83 |
-
examples
|
| 84 |
-
|
| 85 |
-
{"text": "A cute robot reading a book in a cozy library", "files": []},
|
| 86 |
-
42, False, 2.5, 28
|
| 87 |
-
],
|
| 88 |
-
[
|
| 89 |
-
{"text": "A majestic lion standing on a rocky cliff at sunset", "files": []},
|
| 90 |
-
12345, False, 3.0, 25
|
| 91 |
-
],
|
| 92 |
-
[
|
| 93 |
-
{"text": "A futuristic cityscape with flying cars and neon lights", "files": []},
|
| 94 |
-
54321, False, 2.0, 30
|
| 95 |
-
],
|
| 96 |
-
]
|
| 97 |
|
| 98 |
demo = gr.ChatInterface(
|
| 99 |
fn=chat_fn,
|
|
|
|
| 19 |
"""Load the model on CPU first, then move to GPU when needed"""
|
| 20 |
global pipe
|
| 21 |
if pipe is None:
|
| 22 |
+
# Get token from environment variable
|
| 23 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 24 |
+
if hf_token:
|
| 25 |
+
pipe = FluxKontextPipeline.from_pretrained(
|
| 26 |
+
"black-forest-labs/FLUX.1-Kontext-dev",
|
| 27 |
+
torch_dtype=torch.bfloat16,
|
| 28 |
+
token=hf_token,
|
| 29 |
+
)
|
| 30 |
+
else:
|
| 31 |
+
raise gr.Error("HF_TOKEN environment variable not found. Please add your Hugging Face token to the Space settings.")
|
| 32 |
return pipe
|
| 33 |
|
| 34 |
# --- Core Inference Function for ChatInterface ---
|
|
|
|
| 86 |
steps_slider = gr.Slider(label="Steps", minimum=1, maximum=30, value=28, step=1)
|
| 87 |
|
| 88 |
# --- Examples without external URLs ---
|
| 89 |
+
# Remove examples temporarily to avoid format issues
|
| 90 |
+
examples = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
demo = gr.ChatInterface(
|
| 93 |
fn=chat_fn,
|