Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,8 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
|
13 |
|
14 |
# --- Configuration Principale ---
|
15 |
KRYPTO_LORA = {"repo": "Econogoat/Krypt0_LORA", "trigger": "Krypt0", "adapter_name": "krypt0"}
|
16 |
-
|
|
|
17 |
BASE_IMAGE_MODEL = "black-forest-labs/FLUX.1-dev"
|
18 |
|
19 |
# --- Pré-chargement sur CPU des éléments légers UNIQUEMENT ---
|
@@ -41,7 +42,6 @@ def run_generation(prompt, enhance_prompt, lora_scale, cfg_scale, steps, randomi
|
|
41 |
final_prompt = prompt
|
42 |
|
43 |
# --- Chargement à la demande ("Lazy Loading") des modèles sur le GPU ---
|
44 |
-
# Cette section ne s'exécute qu'une seule fois, lors du premier appel.
|
45 |
if pipe is None:
|
46 |
print("Premier appel : Chargement du pipeline d'image sur GPU...")
|
47 |
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device_gpu)
|
@@ -50,12 +50,12 @@ def run_generation(prompt, enhance_prompt, lora_scale, cfg_scale, steps, randomi
|
|
50 |
print("Chargement du LoRA sur le pipeline GPU...")
|
51 |
pipe.load_lora_weights(KRYPTO_LORA['repo'], low_cpu_mem_usage=False, adapter_name=KRYPTO_LORA['adapter_name'], token=HF_TOKEN)
|
52 |
print("Pipeline d'image prêt.")
|
53 |
-
# Monkey-patch pour la prévisualisation
|
54 |
pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
55 |
|
56 |
if enhance_prompt:
|
57 |
if gemma_model is None:
|
58 |
-
print(f"Premier appel d'amélioration : Chargement de {GEMMA_MODEL_ID} sur GPU
|
|
|
59 |
bnb_config_gpu = BitsAndBytesConfig(
|
60 |
load_in_4bit=True,
|
61 |
bnb_4bit_quant_type="nf4",
|
@@ -104,7 +104,6 @@ def run_generation(prompt, enhance_prompt, lora_scale, cfg_scale, steps, randomi
|
|
104 |
|
105 |
yield final_image, seed, gr.update(visible=False)
|
106 |
|
107 |
-
# Le reste du code (fonctions d'aide et UI) reste le même
|
108 |
def calculate_dimensions(aspect_ratio, resolution):
|
109 |
resolution = int(resolution)
|
110 |
if aspect_ratio == "Square (1:1)": width, height = resolution, resolution
|
|
|
13 |
|
14 |
# --- Configuration Principale ---
|
15 |
KRYPTO_LORA = {"repo": "Econogoat/Krypt0_LORA", "trigger": "Krypt0", "adapter_name": "krypt0"}
|
16 |
+
# --- CORRECTION DÉFINITIVE : Utilisation du bon ID de modèle, comme vous l'avez demandé ---
|
17 |
+
GEMMA_MODEL_ID = "google/gemma-1.1-2b-it"
|
18 |
BASE_IMAGE_MODEL = "black-forest-labs/FLUX.1-dev"
|
19 |
|
20 |
# --- Pré-chargement sur CPU des éléments légers UNIQUEMENT ---
|
|
|
42 |
final_prompt = prompt
|
43 |
|
44 |
# --- Chargement à la demande ("Lazy Loading") des modèles sur le GPU ---
|
|
|
45 |
if pipe is None:
|
46 |
print("Premier appel : Chargement du pipeline d'image sur GPU...")
|
47 |
taef1 = AutoencoderTiny.from_pretrained("madebyollin/taef1", torch_dtype=dtype).to(device_gpu)
|
|
|
50 |
print("Chargement du LoRA sur le pipeline GPU...")
|
51 |
pipe.load_lora_weights(KRYPTO_LORA['repo'], low_cpu_mem_usage=False, adapter_name=KRYPTO_LORA['adapter_name'], token=HF_TOKEN)
|
52 |
print("Pipeline d'image prêt.")
|
|
|
53 |
pipe.flux_pipe_call_that_returns_an_iterable_of_images = flux_pipe_call_that_returns_an_iterable_of_images.__get__(pipe)
|
54 |
|
55 |
if enhance_prompt:
|
56 |
if gemma_model is None:
|
57 |
+
print(f"Premier appel d'amélioration : Chargement de {GEMMA_MODEL_ID} sur GPU...")
|
58 |
+
# La quantization est moins critique pour ce petit modèle, mais reste une bonne pratique.
|
59 |
bnb_config_gpu = BitsAndBytesConfig(
|
60 |
load_in_4bit=True,
|
61 |
bnb_4bit_quant_type="nf4",
|
|
|
104 |
|
105 |
yield final_image, seed, gr.update(visible=False)
|
106 |
|
|
|
107 |
def calculate_dimensions(aspect_ratio, resolution):
|
108 |
resolution = int(resolution)
|
109 |
if aspect_ratio == "Square (1:1)": width, height = resolution, resolution
|