Update app.py
Browse files
app.py
CHANGED
|
@@ -17,13 +17,29 @@ model_id = "black-forest-labs/FLUX.1-schnell"
|
|
| 17 |
lora_repo = None
|
| 18 |
lora_path = None
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
global lora_repo, lora_path
|
| 22 |
try:
|
| 23 |
-
|
|
|
|
| 24 |
lora_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 25 |
lora_repo = repo_id
|
| 26 |
-
return f"✅ LoRA chargé : {repo_id} ({filename})"
|
| 27 |
except Exception as e:
|
| 28 |
return f"❌ Erreur : {str(e)}"
|
| 29 |
|
|
@@ -75,6 +91,7 @@ def generate(prompt, negative_prompt="", width=1024, height=1024, steps=4, seed=
|
|
| 75 |
# Interface Gradio
|
| 76 |
with gr.Blocks(title="Flux Schnell + LoRA") as demo:
|
| 77 |
gr.Markdown("# 🎨 Générateur Flux Schnell + LoRA")
|
|
|
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column():
|
|
@@ -84,10 +101,11 @@ with gr.Blocks(title="Flux Schnell + LoRA") as demo:
|
|
| 84 |
label="Repository LoRA",
|
| 85 |
placeholder="username/repo-name"
|
| 86 |
)
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
value="
|
|
|
|
| 91 |
)
|
| 92 |
load_btn = gr.Button("Charger LoRA")
|
| 93 |
lora_status = gr.Textbox(label="Status", interactive=False)
|
|
@@ -97,11 +115,12 @@ with gr.Blocks(title="Flux Schnell + LoRA") as demo:
|
|
| 97 |
prompt = gr.Textbox(
|
| 98 |
label="Prompt",
|
| 99 |
placeholder="Décrivez votre image...",
|
| 100 |
-
lines=3
|
|
|
|
| 101 |
)
|
| 102 |
negative_prompt = gr.Textbox(
|
| 103 |
label="Negative Prompt (optionnel)",
|
| 104 |
-
placeholder="
|
| 105 |
lines=2
|
| 106 |
)
|
| 107 |
|
|
@@ -118,11 +137,17 @@ with gr.Blocks(title="Flux Schnell + LoRA") as demo:
|
|
| 118 |
|
| 119 |
with gr.Column():
|
| 120 |
output_image = gr.Image(label="Image générée", type="pil")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Actions
|
| 123 |
load_btn.click(
|
| 124 |
fn=load_lora,
|
| 125 |
-
inputs=[lora_repo_input,
|
| 126 |
outputs=lora_status
|
| 127 |
)
|
| 128 |
|
|
|
|
| 17 |
lora_repo = None
|
| 18 |
lora_path = None
|
| 19 |
|
| 20 |
+
# Styles disponibles
|
| 21 |
+
STYLES = {
|
| 22 |
+
"Photoréaliste": "photorealistic",
|
| 23 |
+
"Artistique": "artistic",
|
| 24 |
+
"Anime": "anime",
|
| 25 |
+
"3D Render": "3d_render",
|
| 26 |
+
"Peinture à l'huile": "oil_painting",
|
| 27 |
+
"Aquarelle": "watercolor",
|
| 28 |
+
"Cyberpunk": "cyberpunk",
|
| 29 |
+
"Fantasy": "fantasy"
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
# Prompt par défaut
|
| 33 |
+
DEFAULT_PROMPT = "A stunning portrait of a woman with flowing red hair, piercing green eyes, natural lighting, ultra detailed, 8k quality, professional photography"
|
| 34 |
+
|
| 35 |
+
def load_lora(repo_id, style_key):
|
| 36 |
global lora_repo, lora_path
|
| 37 |
try:
|
| 38 |
+
style_filename = STYLES.get(style_key, style_key)
|
| 39 |
+
filename = f"{style_filename}_lora.safetensors"
|
| 40 |
lora_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 41 |
lora_repo = repo_id
|
| 42 |
+
return f"✅ LoRA chargé : {repo_id} - Style: {style_key} ({filename})"
|
| 43 |
except Exception as e:
|
| 44 |
return f"❌ Erreur : {str(e)}"
|
| 45 |
|
|
|
|
| 91 |
# Interface Gradio
|
| 92 |
with gr.Blocks(title="Flux Schnell + LoRA") as demo:
|
| 93 |
gr.Markdown("# 🎨 Générateur Flux Schnell + LoRA")
|
| 94 |
+
gr.Markdown(f"**Modèle :** `{model_id}`")
|
| 95 |
|
| 96 |
with gr.Row():
|
| 97 |
with gr.Column():
|
|
|
|
| 101 |
label="Repository LoRA",
|
| 102 |
placeholder="username/repo-name"
|
| 103 |
)
|
| 104 |
+
lora_style_dropdown = gr.Dropdown(
|
| 105 |
+
choices=list(STYLES.keys()),
|
| 106 |
+
label="Style",
|
| 107 |
+
value="Photoréaliste",
|
| 108 |
+
interactive=True
|
| 109 |
)
|
| 110 |
load_btn = gr.Button("Charger LoRA")
|
| 111 |
lora_status = gr.Textbox(label="Status", interactive=False)
|
|
|
|
| 115 |
prompt = gr.Textbox(
|
| 116 |
label="Prompt",
|
| 117 |
placeholder="Décrivez votre image...",
|
| 118 |
+
lines=3,
|
| 119 |
+
value=DEFAULT_PROMPT
|
| 120 |
)
|
| 121 |
negative_prompt = gr.Textbox(
|
| 122 |
label="Negative Prompt (optionnel)",
|
| 123 |
+
placeholder="blurry, low quality, distorted, ugly",
|
| 124 |
lines=2
|
| 125 |
)
|
| 126 |
|
|
|
|
| 137 |
|
| 138 |
with gr.Column():
|
| 139 |
output_image = gr.Image(label="Image générée", type="pil")
|
| 140 |
+
gr.Markdown("### Conseils")
|
| 141 |
+
gr.Markdown("""
|
| 142 |
+
- **Photoréaliste** : Idéal pour portraits et photos réalistes
|
| 143 |
+
- **Steps recommandés** : 4 pour Schnell (rapide)
|
| 144 |
+
- **Résolution** : 1024x1024 par défaut, ajustez selon besoin
|
| 145 |
+
""")
|
| 146 |
|
| 147 |
# Actions
|
| 148 |
load_btn.click(
|
| 149 |
fn=load_lora,
|
| 150 |
+
inputs=[lora_repo_input, lora_style_dropdown],
|
| 151 |
outputs=lora_status
|
| 152 |
)
|
| 153 |
|