Pontonkid commited on
Commit
b729574
·
verified ·
1 Parent(s): 5ea3481

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,29 +1,25 @@
1
  import gradio as gr
2
  import torch
3
- from diffusers import StableDiffusionXLPipeline
4
 
5
- # Load SDXL model
6
- model_id = "stabilityai/stable-diffusion-xl-base-1.0"
7
- pipe = StableDiffusionXLPipeline.from_pretrained(
8
  model_id,
9
- torch_dtype=torch.float16,
10
- safety_checker=None # Disable safety checker for hackathon demo
11
  )
12
  pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
13
 
14
- # Function to generate outfit image + suggestion
15
  def generate_outfit(weather, activity, style):
16
  try:
17
- # Build prompt
18
  prompt = (
19
  f"A realistic full-body outfit for {weather} weather, "
20
- f"{activity} activity, {style} style, front view, 30-degree angle, highly detailed, full body"
21
  )
22
- # SDXL generates output as a list of PIL images
23
  result = pipe(prompt, guidance_scale=7.5)
24
- image = result.images[0] # take the first image
25
 
26
- # Outfit suggestion
27
  suggestion_text = (
28
  f"💡 Suggested outfit for {weather} weather, {activity} activity, {style} style:\n"
29
  "- Top: light breathable shirt or jacket depending on weather\n"
@@ -32,11 +28,10 @@ def generate_outfit(weather, activity, style):
32
  "- Accessories: hat, sunglasses, or scarf depending on weather"
33
  )
34
  return image, suggestion_text
35
-
36
  except Exception as e:
37
  return None, f"❌ Error generating outfit: {str(e)}"
38
 
39
- # Gradio UI
40
  custom_css = """
41
  body {background: linear-gradient(135deg, #232526, #414345); color: white; font-family: 'Poppins', sans-serif;}
42
  .gradio-container {max-width: 900px !important; margin: auto;}
@@ -47,8 +42,8 @@ h1,h2,h3 {text-align:center; color:#fff;}
47
  """
48
 
49
  with gr.Blocks(css=custom_css) as app:
50
- gr.Markdown("<h1 style='text-align:center;'>👗 ClothCast - AI Outfit Forecaster</h1>")
51
- gr.Markdown("<p style='text-align:center;'>Select your weather, activity, and style to generate an AI outfit!</p>")
52
 
53
  with gr.Row():
54
  with gr.Column(scale=1):
@@ -78,3 +73,4 @@ with gr.Blocks(css=custom_css) as app:
78
 
79
  app.launch(share=True)
80
 
 
 
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"
25
  "- Top: light breathable shirt or jacket depending on weather\n"
 
28
  "- Accessories: hat, sunglasses, or scarf depending on weather"
29
  )
30
  return image, suggestion_text
 
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;}
 
42
  """
43
 
44
  with gr.Blocks(css=custom_css) as app:
45
+ gr.Markdown("<h1 style='text-align:center;'>👗 ClothCast - AI Outfit Forecaster (Fast)</h1>")
46
+ gr.Markdown("<p style='text-align:center;'>Select your weather, activity, and style to generate an AI outfit quickly!</p>")
47
 
48
  with gr.Row():
49
  with gr.Column(scale=1):
 
73
 
74
  app.launch(share=True)
75
 
76
+