mpandzo commited on
Commit
9879223
1 Parent(s): d8b1d95

Create app

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusion3Pipeline
3
+ import torch
4
+ import os
5
+ import psutil
6
+
7
+ pipe = StableDiffusion3Pipeline.from_pretrained(
8
+ "stabilityai/stable-diffusion-3.5-medium",
9
+ torch_dtype=torch.float16,
10
+ )
11
+
12
+
13
+ seed = None
14
+ if seed is None:
15
+ seed = int.from_bytes(os.urandom(2), "big")
16
+ print(f"Using seed: {seed}")
17
+ generator = torch.Generator(device=device).manual_seed(seed)
18
+
19
+ def generate_image(prompt):
20
+ with torch.device(device):
21
+ print(f"Current device: {torch.device(device)}")
22
+ image = pipe(
23
+ prompt=prompt,
24
+ height=(height := 512),
25
+ width=(width := 512),
26
+ num_inference_steps=28,
27
+ guidance_scale=7.0,
28
+ num_images_per_prompt=1,
29
+ generator=generator,
30
+ output_type="pil",
31
+ return_dict=True,
32
+ callback_on_step_end_tensor_inputs=["latents"],
33
+ ).images[0]
34
+ return image
35
+
36
+ iface = gr.Interface(
37
+ fn=generate_image,
38
+ inputs="text",
39
+ outputs="image",
40
+ title="Stable Diffusion 3.5",
41
+ description="Enter a prompt to generate an image using Stable Diffusion 3.5."
42
+ )
43
+
44
+ iface.launch()