File size: 1,649 Bytes
5142ba5
 
 
 
 
bf3a872
f4f4941
95e2f43
 
bf3a872
 
f4f4941
5142ba5
 
95e2f43
5142ba5
95e2f43
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
import gradio as gr
from diffusers import StableDiffusionPipeline
import torch
from PIL import Image
import io
from huggingface_hub import login
import os
from huggingface_hub import hf_hub_download


# Authenticate with Hugging Face
login(token=os.environ.get('your_huggingface_token_here'))

# Load the Stable Fast 3D model
# Try to download the model config to see if you have access
model_id = "stabilityai/stable-fast-3d"
try:
    config_file = hf_hub_download(repo_id=model_id, filename="config.json")
    print("Successfully accessed the model!")
except Exception as e:
    print(f"Error accessing the model: {e}")
    
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()