harshasoftware commited on
Commit
5142ba5
·
verified ·
1 Parent(s): 4506ee7

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import StableDiffusionPipeline
3
+ import torch
4
+ from PIL import Image
5
+ import io
6
+
7
+ # Load the Stable Fast 3D model
8
+ model_id = "stabilityai/stable-fast-3d"
9
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
10
+ pipe = pipe.to("cuda")
11
+
12
+ def convert_2d_to_3d(input_image, prompt):
13
+ # Prepare the input image
14
+ if input_image is not None:
15
+ input_image = Image.open(io.BytesIO(input_image))
16
+ input_image = input_image.resize((512, 512))
17
+
18
+ # Generate the 3D preview
19
+ output_image = pipe(
20
+ prompt=prompt,
21
+ image=input_image,
22
+ num_inference_steps=50,
23
+ guidance_scale=7.5
24
+ ).images[0]
25
+
26
+ return output_image
27
+
28
+ # Create the Gradio interface
29
+ iface = gr.Interface(
30
+ fn=convert_2d_to_3d,
31
+ inputs=[
32
+ gr.Image(type="filepath", label="Upload 2D Floor Layout"),
33
+ gr.Textbox(label="Prompt (e.g., '3D render of a modern apartment floor plan')")
34
+ ],
35
+ outputs=gr.Image(type="pil", label="3D Preview"),
36
+ title="2D to 3D Floor Layout Converter",
37
+ description="Upload a 2D floor layout image and get a 3D preview using Stable Fast 3D model."
38
+ )
39
+
40
+ # Launch the app
41
+ iface.launch()