Prgckwb commited on
Commit
9ef80c7
1 Parent(s): bb1c525

:tada: change

Browse files
Files changed (1) hide show
  1. app.py +31 -13
app.py CHANGED
@@ -4,20 +4,28 @@ import torch
4
  from PIL import Image
5
  from diffusers import DiffusionPipeline
6
 
7
- MODEL_CHOICES = [
8
  "stabilityai/stable-diffusion-3-medium-diffusers",
9
  "stabilityai/stable-diffusion-xl-base-1.0",
10
  "stabilityai/stable-diffusion-2-1",
11
  "runwayml/stable-diffusion-v1-5",
12
  ]
13
 
 
 
 
 
 
 
14
  # Global Variables
15
  current_model_id = "stabilityai/stable-diffusion-3-medium-diffusers"
16
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
- pipe = DiffusionPipeline.from_pretrained(
18
- current_model_id,
19
- torch_dtype=torch.float16,
20
- ).to(device)
 
 
21
 
22
 
23
  @spaces.GPU()
@@ -26,6 +34,10 @@ def inference(
26
  model_id: str,
27
  prompt: str,
28
  negative_prompt: str = "",
 
 
 
 
29
  progress=gr.Progress(track_tqdm=True),
30
  ) -> Image.Image:
31
  global current_model_id, pipe
@@ -43,6 +55,10 @@ def inference(
43
  image = pipe(
44
  prompt,
45
  negative_prompt=negative_prompt,
 
 
 
 
46
  ).images[0]
47
 
48
  return image
@@ -65,13 +81,15 @@ if __name__ == "__main__":
65
  ]
66
 
67
  with gr.Accordion("Additional Settings (W.I.P)", open=False):
 
 
 
 
68
  additional_inputs = [
69
- gr.Text(
70
- label="Model URL",
71
- lines=2,
72
- placeholder="e.g. ) https://civitai.com/api/download/models/177164?type=Model&format=SafeTensor&size=full&fp=fp16"
73
- ),
74
- gr.Number(label="Num Inference Steps", value=None, minimum=1, maximum=1000, step=1)
75
  ]
76
 
77
  with gr.Column():
@@ -87,6 +105,6 @@ if __name__ == "__main__":
87
  )
88
 
89
  btn = gr.Button("Generate")
90
- btn.click(fn=inference, inputs=inputs, outputs=outputs)
91
 
92
  demo.queue().launch()
 
4
  from PIL import Image
5
  from diffusers import DiffusionPipeline
6
 
7
+ DIFFUSERS_MODEL_IDS = [
8
  "stabilityai/stable-diffusion-3-medium-diffusers",
9
  "stabilityai/stable-diffusion-xl-base-1.0",
10
  "stabilityai/stable-diffusion-2-1",
11
  "runwayml/stable-diffusion-v1-5",
12
  ]
13
 
14
+ EXTERNAL_MODEL_URL_MAPPING = {
15
+ "Beautiful Realistic Asians": "https://civitai.com/api/download/models/177164?type=Model&format=SafeTensor&size=full&fp=fp16",
16
+ }
17
+
18
+ MODEL_CHOICES = DIFFUSERS_MODEL_IDS + list(EXTERNAL_MODEL_URL_MAPPING.keys())
19
+
20
  # Global Variables
21
  current_model_id = "stabilityai/stable-diffusion-3-medium-diffusers"
22
+ device = "cuda" if torch.cuda.is_available() else "cpu"
23
+
24
+ if device == 'cuda':
25
+ pipe = DiffusionPipeline.from_pretrained(
26
+ current_model_id,
27
+ torch_dtype=torch.float16,
28
+ ).to(device)
29
 
30
 
31
  @spaces.GPU()
 
34
  model_id: str,
35
  prompt: str,
36
  negative_prompt: str = "",
37
+ width: int = 512,
38
+ height: int = 512,
39
+ guidance_scale: float = 7.5,
40
+ num_inference_steps: int | None = None,
41
  progress=gr.Progress(track_tqdm=True),
42
  ) -> Image.Image:
43
  global current_model_id, pipe
 
55
  image = pipe(
56
  prompt,
57
  negative_prompt=negative_prompt,
58
+ width=width,
59
+ height=height,
60
+ guidance_scale=guidance_scale,
61
+ num_inference_steps=num_inference_steps,
62
  ).images[0]
63
 
64
  return image
 
81
  ]
82
 
83
  with gr.Accordion("Additional Settings (W.I.P)", open=False):
84
+ with gr.Row():
85
+ width = gr.Number(label="Width", value=512, step=64, minimum=64, maximum=1024)
86
+ height = gr.Number(label="Height", value=512, step=64, minimum=64, maximum=1024)
87
+
88
  additional_inputs = [
89
+ width,
90
+ height,
91
+ gr.Number(label="Guidance Scale", value=7.5, step=0.5, minimum=0, maximum=10),
92
+ gr.Slider(label="Num Inference Steps", value=None, minimum=1, maximum=1000, step=1)
 
 
93
  ]
94
 
95
  with gr.Column():
 
105
  )
106
 
107
  btn = gr.Button("Generate")
108
+ btn.click(fn=inference, inputs=inputs + additional_inputs, outputs=outputs)
109
 
110
  demo.queue().launch()