abhinit21 commited on
Commit
eaf25de
1 Parent(s): f171fec

:sparkles: add gradio interface

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from diffusers import StableDiffusionLDM3DPipeline
4
+
5
+ # Load the model. Do this once to avoid reloading on every request.
6
+ pipe = StableDiffusionLDM3DPipeline.from_pretrained("Intel/ldm3d-pano")
7
+ pipe.to("cuda")
8
+
9
+
10
+ def generate_images(prompt, guidance_scale=7.0, num_inference_steps=50):
11
+ output = pipe(
12
+ prompt,
13
+ width=1024,
14
+ height=512,
15
+ guidance_scale=guidance_scale,
16
+ num_inference_steps=num_inference_steps,
17
+ )
18
+
19
+ rgb_image, depth_image = output.rgb, output.depth
20
+
21
+ # Convert to PIL Images for Gradio compatibility
22
+ rgb_image = Image.fromarray(rgb_image[0])
23
+ depth_image = Image.fromarray(depth_image[0])
24
+
25
+ return rgb_image, depth_image
26
+
27
+
28
+ iface = gr.Interface(
29
+ fn=generate_images,
30
+ inputs=[
31
+ "text",
32
+ gr.Slider(0, 20, value=7.0, label="Guidance Scale"),
33
+ gr.Slider(0, 100, value=50, label="Inference Steps")
34
+ ],
35
+ outputs=["image", "image"],
36
+ title="ldm3d-pano Image Generator"
37
+ )
38
+
39
+ iface.launch()