DreamingOracle commited on
Commit
9d00a7f
·
verified ·
1 Parent(s): d6d2d41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -17
app.py CHANGED
@@ -27,7 +27,7 @@ MAX_SEED = np.iinfo(np.int32).max
27
  MAX_IMAGE_SIZE = 1024 # @spaces.GPU #[uncomment to use ZeroGPU]
28
 
29
  def infer(
30
- prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, scheduler_name="PNDM", progress=gr.Progress(track_tqdm=True),):
31
  if randomize_seed:
32
  seed = random.randint(0, MAX_SEED)
33
  generator = torch.Generator().manual_seed(seed)
@@ -39,18 +39,21 @@ def infer(
39
  image = pipe(
40
  prompt=prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, width=width, height=height, generator=generator,
41
  ).images[0]
 
 
 
42
  return image, seed
43
 
44
  examples = [
45
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
46
- "An astronaut riding a green horse",
47
- "A delicious ceviche cheesecake slice",]
48
 
49
  css = """#col-container { margin: 0 auto; max-width: 640px;}"""
50
 
51
  with gr.Blocks(css=css) as demo:
52
  with gr.Column(elem_id="col-container"):
53
- gr.Markdown(" # Text-to-Image Gradio Template")
54
  with gr.Row():
55
  prompt = gr.Text(
56
  label="Prompt", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False,
@@ -59,7 +62,7 @@ with gr.Blocks(css=css) as demo:
59
  result = gr.Image(label="Result", show_label=False)
60
  with gr.Accordion("Advanced Settings", open=False):
61
  negative_prompt = gr.Text(
62
- label="Negative prompt", max_lines=1, placeholder="Enter a negative prompt", visible=False,
63
  )
64
  seed = gr.Slider(
65
  label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0,
@@ -67,30 +70,33 @@ with gr.Blocks(css=css) as demo:
67
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
68
  with gr.Row():
69
  width = gr.Slider(
70
- label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512, # Replace with defaults that work for your model
71
  )
72
  height = gr.Slider(
73
- label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512, # Replace with defaults that work for your model
74
  )
75
  with gr.Row():
76
  guidance_scale = gr.Slider(
77
- label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=7.5, # Replace with defaults that work for your model
78
  )
79
  num_inference_steps = gr.Slider(
80
- label="Number of inference steps", minimum=1, maximum=50, step=1, value=50, # Replace with defaults that work for your model
81
- )
82
- scheduler = gr.Dropdown(
83
- label="Sampler/Scheduler",
84
- choices=list(SCHEDULERS.keys()),
85
- value="PNDM",
86
- info="Try Euler or DPM++ 2M Karras for better quality"
87
  )
 
 
 
 
 
 
 
 
 
88
  gr.Examples(examples=examples, inputs=[prompt])
89
  gr.on(
90
  triggers=[run_button.click, prompt.submit],
91
  fn=infer,
92
  inputs=[
93
- prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, scheduler,
94
  ],
95
  outputs=[result, seed],
96
  )
 
27
  MAX_IMAGE_SIZE = 1024 # @spaces.GPU #[uncomment to use ZeroGPU]
28
 
29
  def infer(
30
+ prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, scheduler_name="PNDM", save_format="png", progress=gr.Progress(track_tqdm=True),):
31
  if randomize_seed:
32
  seed = random.randint(0, MAX_SEED)
33
  generator = torch.Generator().manual_seed(seed)
 
39
  image = pipe(
40
  prompt=prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, width=width, height=height, generator=generator,
41
  ).images[0]
42
+ # Save in selected format for download consistency
43
+ output_path = f"generated_image.{save_format}"
44
+ image.save(output_path, format=save_format.upper())
45
  return image, seed
46
 
47
  examples = [
48
+ "photorealistic portrait of a young woman, cinematic rim lighting, soft golden hour backlight, detailed skin pores, realistic eyelashes, 85mm lens, shallow depth of field, ultra-detailed, high dynamic range, film grain, detailed, 8k",
49
+ "full body portrait of a futuristic armored soldier, worn brushed metal armor with neon blue accents, realistic cloth under-armor, weathering and scratches, volumetric rim light, cinematic pose, high detail, photoreal",
50
+ "neon cyberpunk street at night, wet pavement reflecting lights, pedestrians with umbrellas, dense signage in the distance, cinematic composition, realistic depth, crisp details, atmospheric fog, long lens compression",]
51
 
52
  css = """#col-container { margin: 0 auto; max-width: 640px;}"""
53
 
54
  with gr.Blocks(css=css) as demo:
55
  with gr.Column(elem_id="col-container"):
56
+ gr.Markdown(" # DPS-Quagmaform AI txt2img")
57
  with gr.Row():
58
  prompt = gr.Text(
59
  label="Prompt", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False,
 
62
  result = gr.Image(label="Result", show_label=False)
63
  with gr.Accordion("Advanced Settings", open=False):
64
  negative_prompt = gr.Text(
65
+ label="Negative prompt", max_lines=1, placeholder="Enter a negative prompt", visible=True,
66
  )
67
  seed = gr.Slider(
68
  label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0,
 
70
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
71
  with gr.Row():
72
  width = gr.Slider(
73
+ label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=768, # Replace with defaults that work for your model
74
  )
75
  height = gr.Slider(
76
+ label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024, # Replace with defaults that work for your model
77
  )
78
  with gr.Row():
79
  guidance_scale = gr.Slider(
80
+ label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=5, # Replace with defaults that work for your model
81
  )
82
  num_inference_steps = gr.Slider(
83
+ label="Number of inference steps", minimum=1, maximum=50, step=1, value=22, # Replace with defaults that work for your model
 
 
 
 
 
 
84
  )
85
+ scheduler = gr.Dropdown(
86
+ label="Sampler/Scheduler",
87
+ choices=list(SCHEDULERS.keys()),
88
+ value="PNDM",
89
+ info="Change this setting for better quality in some situations"
90
+ )
91
+ save_format = gr.Dropdown(
92
+ choices=["png", "jpg"], value="png", label="Select Output Format"
93
+ )
94
  gr.Examples(examples=examples, inputs=[prompt])
95
  gr.on(
96
  triggers=[run_button.click, prompt.submit],
97
  fn=infer,
98
  inputs=[
99
+ prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, scheduler, save_format,
100
  ],
101
  outputs=[result, seed],
102
  )