iresidentevil commited on
Commit
54e56b5
·
verified ·
1 Parent(s): 36168c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -7,22 +7,27 @@ from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
 
 
 
 
 
 
 
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
14
  else:
15
  torch_dtype = torch.float32
16
 
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
-
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
 
24
  # @spaces.GPU #[uncomment to use ZeroGPU]
25
  def infer(
 
26
  prompt,
27
  negative_prompt,
28
  seed,
@@ -37,6 +42,10 @@ def infer(
37
  seed = random.randint(0, MAX_SEED)
38
 
39
  generator = torch.Generator().manual_seed(seed)
 
 
 
 
40
 
41
  image = pipe(
42
  prompt=prompt,
@@ -68,6 +77,12 @@ with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
  gr.Markdown(" # Text-to-Image Gradio Template")
70
 
 
 
 
 
 
 
71
  with gr.Row():
72
  prompt = gr.Text(
73
  label="Prompt",
@@ -86,7 +101,8 @@ with gr.Blocks(css=css) as demo:
86
  label="Negative prompt",
87
  max_lines=1,
88
  placeholder="Enter a negative prompt",
89
- visible=False,
 
90
  )
91
 
92
  seed = gr.Slider(
@@ -138,6 +154,7 @@ with gr.Blocks(css=css) as demo:
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,
140
  inputs=[
 
141
  prompt,
142
  negative_prompt,
143
  seed,
 
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ # model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
+
12
+ MODEL_OPTIONS = [
13
+ ("stabilityai/sdxl-turbo", "SDXL Turbo (Быстро)"),
14
+ ("CompVis/stable-diffusion-v1-4", "Stable Diffusion v1-4 (Классика)"),
15
+ ("Qwen/Qwen-Image", "Топ модель, но долго"),
16
+ ]
17
+ DEFAULT_MODEL_ID = "stabilityai/sdxl-turbo"
18
 
19
  if torch.cuda.is_available():
20
  torch_dtype = torch.float16
21
  else:
22
  torch_dtype = torch.float32
23
 
 
 
 
24
  MAX_SEED = np.iinfo(np.int32).max
25
  MAX_IMAGE_SIZE = 1024
26
 
27
 
28
  # @spaces.GPU #[uncomment to use ZeroGPU]
29
  def infer(
30
+ model_id, # Добавил
31
  prompt,
32
  negative_prompt,
33
  seed,
 
42
  seed = random.randint(0, MAX_SEED)
43
 
44
  generator = torch.Generator().manual_seed(seed)
45
+
46
+ pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch_dtype)
47
+ pipe = pipe.to(device)
48
+
49
 
50
  image = pipe(
51
  prompt=prompt,
 
77
  with gr.Column(elem_id="col-container"):
78
  gr.Markdown(" # Text-to-Image Gradio Template")
79
 
80
+ model_id = gr.Dropdown(
81
+ choices=[m[0] for m in MODEL_OPTIONS],
82
+ label="Model",
83
+ value=DEFAULT_MODEL_ID,
84
+ )
85
+
86
  with gr.Row():
87
  prompt = gr.Text(
88
  label="Prompt",
 
101
  label="Negative prompt",
102
  max_lines=1,
103
  placeholder="Enter a negative prompt",
104
+ visible=True,
105
+ value="dog, cat"
106
  )
107
 
108
  seed = gr.Slider(
 
154
  triggers=[run_button.click, prompt.submit],
155
  fn=infer,
156
  inputs=[
157
+ model_id,
158
  prompt,
159
  negative_prompt,
160
  seed,