mrestrepo commited on
Commit
50431f7
·
1 Parent(s): c116622

Add input fields guidance and inference - Convert image to jpg

Browse files
Files changed (1) hide show
  1. app.py +17 -10
app.py CHANGED
@@ -6,6 +6,8 @@ import os
6
  from diffusers import AutoPipelineForText2Image
7
  import torch
8
  from huggingface_hub import snapshot_download
 
 
9
 
10
  SPACE_USERNAME = 'KR_4dmin'
11
  SPACE_PASSWORD = 'KR_4dmin'
@@ -22,20 +24,23 @@ MAX_IMAGE_SIZE = 1024
22
 
23
 
24
  @spaces.GPU
25
- def infer(prompt, height, width):
26
-
27
- # init_image = refer_image.resize((1024, 1024))
28
 
29
  image = pipeline(
30
  prompt=prompt,
31
- # guidance_scale=guidance_scale,
32
- # num_inference_steps=num_inference_steps,
33
  width=width,
34
  height=height,
35
  # image=refer_image
36
  # generator=generator
37
  ).images[0]
38
 
 
 
 
 
 
39
  return image
40
 
41
 
@@ -107,20 +112,22 @@ with gr.Blocks(css=css) as demo:
107
 
108
  guidance_scale = gr.Slider(
109
  label="Guidance scale",
 
110
  minimum=0.0,
111
  maximum=10.0,
112
  step=0.1,
113
- value=0.0, # Replace with defaults that work for your model
114
- visible=False
115
  )
116
 
117
  num_inference_steps = gr.Slider(
118
  label="Number of inference steps",
 
119
  minimum=1,
120
  maximum=50,
121
  step=1,
122
- value=2, # Replace with defaults that work for your model
123
- visible=False
124
  )
125
 
126
  gr.Examples(
@@ -131,7 +138,7 @@ with gr.Blocks(css=css) as demo:
131
  gr.on(
132
  triggers=[run_button.click, prompt.submit],
133
  fn=infer,
134
- inputs=[prompt, height, width],
135
  outputs=[result]
136
  )
137
 
 
6
  from diffusers import AutoPipelineForText2Image
7
  import torch
8
  from huggingface_hub import snapshot_download
9
+ from io import BytesIO
10
+ from PIL import Image
11
 
12
  SPACE_USERNAME = 'KR_4dmin'
13
  SPACE_PASSWORD = 'KR_4dmin'
 
24
 
25
 
26
  @spaces.GPU
27
+ def infer(prompt, height, width, guidance_scale, num_inference_steps):
 
 
28
 
29
  image = pipeline(
30
  prompt=prompt,
31
+ guidance_scale=guidance_scale,
32
+ num_inference_steps=num_inference_steps,
33
  width=width,
34
  height=height,
35
  # image=refer_image
36
  # generator=generator
37
  ).images[0]
38
 
39
+ # Convert the image to JPG format
40
+ img_byte_arr = BytesIO()
41
+ image.save(img_byte_arr, format='JPEG')
42
+ img_byte_arr = img_byte_arr.getvalue()
43
+
44
  return image
45
 
46
 
 
112
 
113
  guidance_scale = gr.Slider(
114
  label="Guidance scale",
115
+ info="Valores mas altos se apega mas al prompt, la calidad del resultado baja. Valores bajos permite creatividad pero se aleja del prompt",
116
  minimum=0.0,
117
  maximum=10.0,
118
  step=0.1,
119
+ value=7.0,
120
+ visible=True
121
  )
122
 
123
  num_inference_steps = gr.Slider(
124
  label="Number of inference steps",
125
+ info="Entre mas numeros de inferencia mejor calidad de la imagen. Toma mas tiempo generar la imagen.",
126
  minimum=1,
127
  maximum=50,
128
  step=1,
129
+ value=50,
130
+ visible=True
131
  )
132
 
133
  gr.Examples(
 
138
  gr.on(
139
  triggers=[run_button.click, prompt.submit],
140
  fn=infer,
141
+ inputs=[prompt, height, width, guidance_scale, num_inference_steps],
142
  outputs=[result]
143
  )
144