=Apyhtml20 commited on
Commit
d098b29
·
1 Parent(s): fad99c2

Initial commit

Browse files
Files changed (1) hide show
  1. app.py +14 -29
app.py CHANGED
@@ -2,40 +2,35 @@ import gradio as gr
2
  import torch
3
  import numpy as np
4
  import random
5
- from diffusers import FluxImg2ImgPipeline
6
  from PIL import Image
7
 
8
- dtype = torch.bfloat16
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  MAX_SEED = np.iinfo(np.int32).max
11
 
12
- MODEL_ID = "black-forest-labs/FLUX.1-schnell"
13
- LORA_REPO = "alvdansen/flux-koda"
14
- LORA_FILE = "flux_dev_koda_araminta_k.safetensors"
15
 
16
  STYLES = {
17
  "Anime": {
18
- "lora": "alvdansen/flux-koda",
19
- "file": "flux_dev_koda_araminta_k.safetensors",
20
- "prompt": "anime style portrait, detailed face, vibrant colors, high quality"
21
  },
22
  "Pixel Art": {
23
- "lora": "nerijs/pixel-art-xl",
24
- "file": "pixel-art-xl.safetensors",
25
- "prompt": "pixel art avatar, 16-bit style, retro game character"
26
  },
27
  "Ghibli": {
28
- "lora": "aleksa-codes/flux-ghibsky-illustration",
29
- "file": "flux_ghibsky_illustration.safetensors",
30
- "prompt": "ghibli studio style illustration, soft colors, dreamy atmosphere"
31
  },
32
  }
33
 
34
  print("Chargement du modèle...")
35
- pipe = FluxImg2ImgPipeline.from_pretrained(MODEL_ID, torch_dtype=dtype)
 
 
 
 
36
  pipe.to(device)
37
-
38
- current_style = None
39
 
40
  def generate_avatar(
41
  input_image,
@@ -45,33 +40,23 @@ def generate_avatar(
45
  randomize_seed,
46
  progress=gr.Progress(track_tqdm=True)
47
  ):
48
- global current_style
49
-
50
  if input_image is None:
51
  raise gr.Error("Veuillez uploader une photo !")
52
 
53
- # Charger le bon LoRA selon le style
54
- if style_name != current_style:
55
- style = STYLES[style_name]
56
- pipe.unload_lora_weights()
57
- pipe.load_lora_weights(style["lora"], weight_name=style["file"])
58
- current_style = style_name
59
-
60
  if randomize_seed:
61
  seed = random.randint(0, MAX_SEED)
62
 
63
  generator = torch.Generator(device=device).manual_seed(seed)
64
  prompt = STYLES[style_name]["prompt"]
65
 
66
- # Redimensionner l'image input
67
  input_image = input_image.resize((512, 512))
68
 
69
  result = pipe(
70
  prompt=prompt,
71
  image=input_image,
72
- strength=strength, # 0.5 = garde ressemblance, 0.9 = full style
73
  num_inference_steps=20,
74
- guidance_scale=3.5,
75
  generator=generator,
76
  ).images[0]
77
 
 
2
  import torch
3
  import numpy as np
4
  import random
5
+ from diffusers import StableDiffusionImg2ImgPipeline
6
  from PIL import Image
7
 
8
+ dtype = torch.float16
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
  MAX_SEED = np.iinfo(np.int32).max
11
 
12
+ MODEL_ID = "runwayml/stable-diffusion-v1-5"
 
 
13
 
14
  STYLES = {
15
  "Anime": {
16
+ "prompt": "anime style portrait, detailed face, vibrant colors, high quality, studio ghibli"
 
 
17
  },
18
  "Pixel Art": {
19
+ "prompt": "pixel art avatar, 16-bit style, retro game character, sharp pixels"
 
 
20
  },
21
  "Ghibli": {
22
+ "prompt": "ghibli studio style illustration, soft colors, dreamy atmosphere, watercolor"
 
 
23
  },
24
  }
25
 
26
  print("Chargement du modèle...")
27
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
28
+ MODEL_ID,
29
+ torch_dtype=dtype,
30
+ safety_checker=None
31
+ )
32
  pipe.to(device)
33
+ print("Modèle chargé !")
 
34
 
35
  def generate_avatar(
36
  input_image,
 
40
  randomize_seed,
41
  progress=gr.Progress(track_tqdm=True)
42
  ):
 
 
43
  if input_image is None:
44
  raise gr.Error("Veuillez uploader une photo !")
45
 
 
 
 
 
 
 
 
46
  if randomize_seed:
47
  seed = random.randint(0, MAX_SEED)
48
 
49
  generator = torch.Generator(device=device).manual_seed(seed)
50
  prompt = STYLES[style_name]["prompt"]
51
 
 
52
  input_image = input_image.resize((512, 512))
53
 
54
  result = pipe(
55
  prompt=prompt,
56
  image=input_image,
57
+ strength=strength,
58
  num_inference_steps=20,
59
+ guidance_scale=7.5,
60
  generator=generator,
61
  ).images[0]
62