File size: 1,317 Bytes
5142ba5
 
 
 
 
bf3a872
 
 
 
5142ba5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
from PIL import Image
import io
from huggingface_hub import login

# Authenticate with Hugging Face
login(token="your_huggingface_token_here")

# Load the Stable Fast 3D model
model_id = "stabilityai/stable-fast-3d"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")

def convert_2d_to_3d(input_image, prompt):
    # Prepare the input image
    if input_image is not None:
        input_image = Image.open(io.BytesIO(input_image))
        input_image = input_image.resize((512, 512))
    
    # Generate the 3D preview
    output_image = pipe(
        prompt=prompt,
        image=input_image,
        num_inference_steps=50,
        guidance_scale=7.5
    ).images[0]
    
    return output_image

# Create the Gradio interface
iface = gr.Interface(
    fn=convert_2d_to_3d,
    inputs=[
        gr.Image(type="filepath", label="Upload 2D Floor Layout"),
        gr.Textbox(label="Prompt (e.g., '3D render of a modern apartment floor plan')")
    ],
    outputs=gr.Image(type="pil", label="3D Preview"),
    title="2D to 3D Floor Layout Converter",
    description="Upload a 2D floor layout image and get a 3D preview using Stable Fast 3D model."
)

# Launch the app
iface.launch()