# import torch # import numpy as np # from diffusers import StableDiffusionImg2ImgPipeline # from PIL import Image # import gradio as gr # # Load Stable Diffusion Image-to-Image Pipeline # pipe = StableDiffusionImg2ImgPipeline.from_pretrained( # "CompVis/stable-diffusion-v1-4", # torch_dtype=torch.float16 # ) # pipe.to("cuda" if torch.cuda.is_available() else "cpu") # Use GPU if available # def generate_headshot(image): # # Convert NumPy array to PIL Image # if isinstance(image, np.ndarray): # image = Image.fromarray(image) # # Define the AI prompt for professional headshots # prompt = "A professional corporate headshot, studio lighting, high resolution, DSLR quality" # # Generate the AI-enhanced headshot # generated_image = pipe(prompt=prompt, image=image, strength=0.7).images[0] # return generated_image # # Create Gradio UI # iface = gr.Interface(fn=generate_headshot, inputs="image", outputs="image") # iface.launch() # =================================== import torch import numpy as np from diffusers import StableDiffusionImg2ImgPipeline from PIL import Image import gradio as gr # Load Stable Diffusion Image-to-Image Pipeline pipe = StableDiffusionImg2ImgPipeline.from_pretrained( "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float32 # Use float32 for CPU ) # Force execution on CPU (since no GPU is available) pipe.to("cpu") # Define function to generate professional headshots def generate_headshot(image): if isinstance(image, np.ndarray): image = Image.fromarray(image) prompt = "Ultra-realistic professional headshot, studio lighting, 4K resolution, " "sharp details, DSLR quality, corporate portrait, neutral background, " "perfect skin texture, cinematic lighting" # Generate image (Lower strength for subtle changes) generated_image = pipe(prompt=prompt, image=image, strength=0.5).images[0] return generated_image # Create Gradio UI iface = gr.Interface(fn=generate_headshot, inputs="image", outputs="image") iface.launch()