Leteint commited on
Commit
d8acf02
·
verified ·
1 Parent(s): 2ad51f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -38
app.py CHANGED
@@ -15,37 +15,31 @@ if hf_token:
15
 
16
  model_id = "black-forest-labs/FLUX.1-schnell"
17
 
18
- # Repository LoRA par défaut (à adapter selon votre repository)
19
- DEFAULT_LORA_REPO = "XLabs-AI/flux-RealismLora" # Exemple de repo avec LoRA photoréaliste
 
 
 
 
 
 
 
20
 
21
  lora_repo = None
22
  lora_path = None
23
 
24
- # Styles disponibles
25
- STYLES = {
26
- "Photoréaliste": "lora", # Le fichier s'appelle souvent "lora.safetensors"
27
- "Artistique": "artistic",
28
- "Anime": "anime",
29
- "3D Render": "3d_render",
30
- "Peinture à l'huile": "oil_painting",
31
- "Aquarelle": "watercolor",
32
- "Cyberpunk": "cyberpunk",
33
- "Fantasy": "fantasy"
34
- }
35
-
36
- # Prompt par défaut
37
- DEFAULT_PROMPT = "A stunning portrait of a woman with flowing red hair, piercing green eyes, natural lighting, ultra detailed, 8k quality, professional photography"
38
-
39
- def load_lora(repo_id, style_key):
40
  global lora_repo, lora_path
 
 
 
41
  try:
42
- style_filename = STYLES.get(style_key, style_key)
43
- filename = f"{style_filename}_lora.safetensors"
44
  lora_path = hf_hub_download(repo_id=repo_id, filename=filename)
45
  lora_repo = repo_id
46
- return f"✅ LoRA chargé : {repo_id} - Style: {style_key} ({filename})"
47
  except Exception as e:
48
- return f"❌ Erreur : {str(e)}"
49
 
50
  @spaces.GPU(duration=120)
51
  def generate(prompt, negative_prompt="", width=1024, height=1024, steps=4, seed=-1, lora_scale=0.8):
@@ -100,17 +94,24 @@ with gr.Blocks(title="Flux Schnell + LoRA") as demo:
100
  with gr.Row():
101
  with gr.Column():
102
  # LoRA
103
- gr.Markdown("### Charger un LoRA (optionnel)")
 
 
 
 
 
 
 
 
104
  lora_repo_input = gr.Textbox(
105
  label="Repository LoRA",
106
- placeholder="username/repo-name",
107
- value=DEFAULT_LORA_REPO
108
  )
109
- lora_style_dropdown = gr.Dropdown(
110
- choices=list(STYLES.keys()),
111
- label="Style",
112
- value="Photoréaliste",
113
- interactive=True
114
  )
115
  load_btn = gr.Button("Charger LoRA")
116
  lora_status = gr.Textbox(label="Status", interactive=False)
@@ -142,21 +143,22 @@ with gr.Blocks(title="Flux Schnell + LoRA") as demo:
142
 
143
  with gr.Column():
144
  output_image = gr.Image(label="Image générée", type="pil")
145
- gr.Markdown("### Conseils")
146
  gr.Markdown("""
147
- - **Repository LoRA par défaut** : XLabs-AI/flux-RealismLora
148
- - **Photoréaliste** : Idéal pour portraits et photos réalistes
149
- - **Steps recommandés** : 4 pour Schnell (rapide)
150
- - **Résolution** : 1024x1024 par défaut, ajustez selon besoin
151
 
152
- 💡 **Note** : Le repository `black-forest-labs/FLUX.1-schnell` est le modèle de base,
153
- pas un repository LoRA. Pour utiliser des LoRA, trouvez des repositories dédiés sur HuggingFace.
 
154
  """)
155
 
156
  # Actions
157
  load_btn.click(
158
  fn=load_lora,
159
- inputs=[lora_repo_input, lora_style_dropdown],
160
  outputs=lora_status
161
  )
162
 
 
15
 
16
  model_id = "black-forest-labs/FLUX.1-schnell"
17
 
18
+ # Prompt par défaut
19
+ DEFAULT_PROMPT = "A stunning portrait of a woman with flowing red hair, piercing green eyes, natural lighting, ultra detailed, 8k quality, professional photography"
20
+
21
+ # Note: FLUX.1-schnell n'utilise PAS de LoRA par défaut
22
+ # Le modèle de base est déjà optimisé pour la génération rapide
23
+ # Si vous voulez ajouter des LoRA, utilisez des repositories communautaires comme:
24
+ # - XLabs-AI/flux-RealismLora
25
+ # - Shakker-Labs/FLUX.1-dev-LoRA-collections
26
+ # etc.
27
 
28
  lora_repo = None
29
  lora_path = None
30
 
31
+ def load_lora(repo_id, filename):
32
+ """Charge un LoRA depuis un repository HuggingFace"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  global lora_repo, lora_path
34
+ if not repo_id or not filename:
35
+ return "⚠️ Veuillez renseigner le repository ET le nom du fichier"
36
+
37
  try:
 
 
38
  lora_path = hf_hub_download(repo_id=repo_id, filename=filename)
39
  lora_repo = repo_id
40
+ return f"✅ LoRA chargé : {repo_id}/{filename}"
41
  except Exception as e:
42
+ return f"❌ Erreur : {str(e)}\n\nVérifiez que le repository contient bien ce fichier."
43
 
44
  @spaces.GPU(duration=120)
45
  def generate(prompt, negative_prompt="", width=1024, height=1024, steps=4, seed=-1, lora_scale=0.8):
 
94
  with gr.Row():
95
  with gr.Column():
96
  # LoRA
97
+ gr.Markdown("### 🎨 Ajouter un LoRA (optionnel)")
98
+ gr.Markdown("""
99
+ ⚠️ **Important** : Le modèle de base FLUX.1-schnell fonctionne **sans LoRA**.
100
+
101
+ Si vous voulez ajouter un style avec un LoRA, utilisez des repositories communautaires :
102
+ - `XLabs-AI/flux-RealismLora` (fichier: `lora.safetensors`)
103
+ - `Shakker-Labs/FLUX.1-dev-LoRA-add-details` (fichier: `FLUX-dev-lora-add_details.safetensors`)
104
+ """)
105
+
106
  lora_repo_input = gr.Textbox(
107
  label="Repository LoRA",
108
+ placeholder="Ex: XLabs-AI/flux-RealismLora",
109
+ value=""
110
  )
111
+ lora_filename = gr.Textbox(
112
+ label="Nom du fichier LoRA",
113
+ placeholder="Ex: lora.safetensors",
114
+ value=""
 
115
  )
116
  load_btn = gr.Button("Charger LoRA")
117
  lora_status = gr.Textbox(label="Status", interactive=False)
 
143
 
144
  with gr.Column():
145
  output_image = gr.Image(label="Image générée", type="pil")
146
+ gr.Markdown("### 💡 Conseils")
147
  gr.Markdown("""
148
+ - **Modèle de base** : FLUX.1-schnell (rapide, sans LoRA nécessaire)
149
+ - **Steps recommandés** : 4 pour Schnell
150
+ - **Résolution** : 1024x1024 par défaut
151
+ - **LoRA Scale** : 0.8 pour un effet équilibré (ajustez entre 0-1)
152
 
153
+ **Exemples de repositories LoRA compatibles :**
154
+ - [XLabs-AI/flux-RealismLora](https://huggingface.co/XLabs-AI/flux-RealismLora)
155
+ - [Shakker-Labs collections](https://huggingface.co/Shakker-Labs)
156
  """)
157
 
158
  # Actions
159
  load_btn.click(
160
  fn=load_lora,
161
+ inputs=[lora_repo_input, lora_filename],
162
  outputs=lora_status
163
  )
164