Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionPipeline, StableDiffusionDepth2ImgPipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
+
import open3d as o3d
|
| 6 |
+
|
| 7 |
+
# Initialize the pipelines
|
| 8 |
+
sd_pipeline = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype="float16")
|
| 9 |
+
sd_pipeline.to("cuda")
|
| 10 |
+
depth_pipeline = StableDiffusionDepth2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-depth2img", torch_dtype="float16")
|
| 11 |
+
depth_pipeline.to("cuda")
|
| 12 |
+
|
| 13 |
+
def generate_images(prompt):
|
| 14 |
+
# Generate the base image
|
| 15 |
+
image = sd_pipeline(prompt).images[0]
|
| 16 |
+
# Generate the depth map
|
| 17 |
+
depth_image = depth_pipeline(prompt=prompt, image=image).images[0]
|
| 18 |
+
return image, depth_image
|
| 19 |
+
|
| 20 |
+
# Define Gradio interface
|
| 21 |
+
iface = gr.Interface(
|
| 22 |
+
fn=generate_images,
|
| 23 |
+
inputs=gr.Textbox(label="Enter your prompt"),
|
| 24 |
+
outputs=[
|
| 25 |
+
gr.Image(label="Bas-relief Image"),
|
| 26 |
+
gr.Image(label="Depth Map Image")
|
| 27 |
+
],
|
| 28 |
+
title="Text to Bas-Relief and Depth Map Generator"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
iface.launch()
|