import torch import requests import rembg import random import gradio as gr import numpy from PIL import Image from diffusers import DiffusionPipeline, EulerAncestralDiscreteScheduler # Load the pipeline pipeline = DiffusionPipeline.from_pretrained( "sudo-ai/zero123plus-v1.1", custom_pipeline="sudo-ai/zero123plus-pipeline", torch_dtype=torch.float16 ) # Feel free to tune the scheduler! # `timestep_spacing` parameter is not supported in older versions of `diffusers` # so there may be performance degradations # We recommend using `diffusers==0.20.2` pipeline.scheduler = EulerAncestralDiscreteScheduler.from_config( pipeline.scheduler.config, timestep_spacing='trailing' ) pipeline.to('cuda:0') def inference(input_img, num_inference_steps, guidance_scale, seed ): # Download an example image. cond = Image.open(input_img) if seed==0: seed = random.randint(1, 1000000) # Run the pipeline! #result = pipeline(cond, num_inference_steps=75).images[0] result = pipeline(cond, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, generator=torch.Generator(pipeline.device).manual_seed(int(seed))).images[0] # for general real and synthetic images of general objects # usually it is enough to have around 28 inference steps # for images with delicate details like faces (real or anime) # you may need 75-100 steps for the details to construct #result.show() #result.save("output.png") return result def remove_background(result): print(type(result)) # Check if the variable is a PIL Image if isinstance(result, Image.Image): result = rembg.remove(result) # Check if the variable is a str filepath elif isinstance(result, str): result = Image.open(result) result = rembg.remove(result) elif isinstance(result, numpy.ndarray): print('here ELIF 2') # Convert the NumPy array to a PIL Image result = Image.fromarray(result) result = rembg.remove(result) return result abstract = '''Zero123++ is an image-conditioned diffusion model for generating 3D-consistent multi-view images from a single input view. To take full advantage of pretrained 2D generative priors, authors have developed various conditioning and training schemes to minimize the effort of finetuning from off-the-shelf image diffusion models such as Stable Diffusion. Zero123++ excels in producing high-quality, consistent multi-view images from a single image, overcoming common issues like texture degradation and geometric misalignment. Furthermore, authors showcase the feasibility of training a ControlNet on Zero123++ for enhanced control over the generation process. ''' # Create a Gradio interface for the Zero123++ model with gr.Blocks() as demo: # Display a title gr.HTML("