Pontonkid commited on
Commit
3e75dc6
·
verified ·
1 Parent(s): b729574

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,24 +1,25 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusionPipeline
4
 
5
- # RAPIDE: Utilisation d'un modèle plus léger pour la génération rapide
6
- model_id = "stabilityai/stable-diffusion-2-1-base"
7
- pipe = StableDiffusionPipeline.from_pretrained(
8
- model_id,
9
- torch_dtype=torch.float16
 
 
10
  )
11
- pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
12
 
13
- # Fonction pour générer l'image + suggestion
14
  def generate_outfit(weather, activity, style):
15
  try:
16
  prompt = (
17
  f"A realistic full-body outfit for {weather} weather, "
18
- f"{activity} activity, {style} style, front view, full body, fashion style"
19
  )
20
- result = pipe(prompt, guidance_scale=7.5)
21
- image = result.images[0] # Toujours prendre la première image
22
 
23
  suggestion_text = (
24
  f"💡 Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
@@ -31,7 +32,7 @@ def generate_outfit(weather, activity, style):
31
  except Exception as e:
32
  return None, f"❌ Error generating outfit: {str(e)}"
33
 
34
- # UI Gradio
35
  custom_css = """
36
  body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
37
  .gradio-container {max-width: 900px !important; margin: auto;}
@@ -74,3 +75,4 @@ with gr.Blocks(css=custom_css) as app:
74
  app.launch(share=True)
75
 
76
 
 
 
1
  import gradio as gr
2
  import torch
3
+ from diffusers import DiffusionPipeline
4
 
5
+ # Load the new model
6
+ # Use bfloat16 for speed and CUDA if available
7
+ device = "cuda" if torch.cuda.is_available() else "cpu"
8
+ pipe = DiffusionPipeline.from_pretrained(
9
+ "black-forest-labs/FLUX.1-dev",
10
+ dtype=torch.bfloat16,
11
+ device_map=device
12
  )
 
13
 
14
+ # Function to generate outfit image + suggestion
15
  def generate_outfit(weather, activity, style):
16
  try:
17
  prompt = (
18
  f"A realistic full-body outfit for {weather} weather, "
19
+ f"{activity} activity, {style} style, front view, fashion style, full body"
20
  )
21
+ result = pipe(prompt)
22
+ image = result.images[0]
23
 
24
  suggestion_text = (
25
  f"💡 Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
 
32
  except Exception as e:
33
  return None, f"❌ Error generating outfit: {str(e)}"
34
 
35
+ # Gradio UI
36
  custom_css = """
37
  body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
38
  .gradio-container {max-width: 900px !important; margin: auto;}
 
75
  app.launch(share=True)
76
 
77
 
78
+