ptx0 commited on
Commit
1393f77
1 Parent(s): 68dc9bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
app.py CHANGED
@@ -1,23 +1,41 @@
1
- import spaces, torch
2
  from diffusers import DiffusionPipeline
3
  import gradio as gr
4
 
 
5
  pipe = DiffusionPipeline.from_pretrained('ptx0/terminus-xl-velocity-v2', torch_dtype=torch.bfloat16)
6
- #pipe.unet = torch.compile(pipe.unet)
7
  pipe.to('cuda')
8
 
9
- @spaces.GPU
10
- def generate(prompt):
11
- return pipe(
12
- prompt,
13
- negative_prompt="underexposed, blurry, ugly, washed-out",
14
- guidance_rescale=0.7,
15
- guidance_scale=9.5,
16
- num_inference_steps=30,
17
- ).images
 
 
18
 
19
- gr.Interface(
 
 
 
 
 
 
 
 
20
  fn=generate,
21
- inputs=gr.Text(),
22
- outputs=gr.Gallery(),
 
 
 
 
 
 
 
 
23
  ).launch()
 
1
+ import torch
2
  from diffusers import DiffusionPipeline
3
  import gradio as gr
4
 
5
+ # Load the pre-trained diffusion model
6
  pipe = DiffusionPipeline.from_pretrained('ptx0/terminus-xl-velocity-v2', torch_dtype=torch.bfloat16)
 
7
  pipe.to('cuda')
8
 
9
+ # Define the image generation function with adjustable parameters and a progress bar
10
+ def generate(prompt, guidance_scale, num_inference_steps, negative_prompt):
11
+ with gr.Progress(steps=num_inference_steps) as progress:
12
+ for i in range(num_inference_steps):
13
+ progress.update(progress=i)
14
+ return pipe(
15
+ prompt,
16
+ negative_prompt=negative_prompt,
17
+ guidance_scale=guidance_scale,
18
+ num_inference_steps=num_inference_steps
19
+ ).images
20
 
21
+ # Example prompts to demonstrate the model's capabilities
22
+ example_prompts = [
23
+ ["A futuristic cityscape at night under a starry sky", 7.5, 25, "blurry, overexposed"],
24
+ ["A serene landscape with a flowing river and autumn trees", 8.0, 20, "crowded, noisy"],
25
+ ["An abstract painting of joy and energy in bright colors", 9.0, 30, "dark, dull"]
26
+ ]
27
+
28
+ # Create a Gradio interface
29
+ iface = gr.Interface(
30
  fn=generate,
31
+ inputs=[
32
+ gr.Text(label="Enter your prompt"),
33
+ gr.Slider(5, 10, step=0.1, label="Guidance Scale", default=7.5),
34
+ gr.Slider(10, 50, step=5, label="Number of Inference Steps", default=25),
35
+ gr.Text(value="underexposed, blurry, ugly, washed-out", label="Negative Prompt")
36
+ ],
37
+ outputs=gr.Gallery(height=512, width=512, columns=2),
38
+ examples=example_prompts,
39
+ title="Image Generation with Diffusion Model",
40
+ description="Generate images based on textual prompts. Adjust the parameters to see how they affect the outcome."
41
  ).launch()