!pip install diffusers
!pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
!pip install transformers
!pip install accelerate
!pip install safetensors
#%%
from diffusers import StableDiffusionPipeline
import torch
model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusionv1-4").to("cuda")
prompt = 'A beautiful landscape painting in the style of Van Gogh'
image = model(prompt).images[0]
image.show()
prompt = 'A beautiful painting in M F hussain style'
image = model(prompt).images[0]
image.show()
prompt = 'A fantasy castle in the cloud, ultra-detailed'
image = model(prompt).images[0]
image.show()


import torch
from diffusers import StableDiffusionInpaintPipeline
from PIL import Image

# Load Stable Diffusion Inpainting Model in FP16
device = "cuda" if torch.cuda.is_available() else "cpu"
pipe = StableDiffusionInpaintPipeline.from_pretrained(
 "runwayml/stable-diffusion-inpainting",
 torch_dtype = torch.float16, # Enables FP16 precision for faster
inference
).to(device)
# Load Input Image and Mask
image = Image.open("sketch1.jpg").convert("RGB")
mask_image = Image.open("mask.jpg").convert("L")
# Define the text prompt
prompt = "A real life face"
# Run the inpainting model with *reduced inference steps**
result = pipe(
 prompt = prompt,
 image = image,
 mask_image = mask_image,
 num_inference_steps = 30, # Reduce steps for faster generation
(Default: 50)
).images[0]
# Save and Show the Result
result.save("inpainted_image.jpg")
result.show()
print("AI-generated inpainted image saved as 'inpainted_image.jpg'")