|
import gradio as gr |
|
import torch |
|
from PIL import Image |
|
from diffusers import StableDiffusionInstructPix2PixPipeline |
|
|
|
|
|
model_path = "/content/uberRealisticPornMerge_urpmv12.instruct-pix2pix.safetensors" |
|
|
|
|
|
safe_pipe = torch.load(model_path, map_location=torch.device('cuda')) |
|
|
|
def generate_edited_image(input_image): |
|
|
|
input_image_pil = Image.fromarray(input_image.astype('uint8'), 'RGB') |
|
|
|
|
|
edited_image = safe_pipe(instruction="", image=input_image_pil, num_inference_steps=50).images[0] |
|
|
|
|
|
edited_image_gradio = edited_image.cpu().numpy().astype('uint8') |
|
|
|
return edited_image_gradio |
|
|
|
|
|
input_image = gr.inputs.Image(label="Upload an Input Image") |
|
output_image = gr.outputs.Image(label="Edited Image") |
|
|
|
|
|
gr.Interface( |
|
fn=generate_edited_image, |
|
inputs=input_image, |
|
outputs=output_image, |
|
title="SafeTensor Image Editing", |
|
description="Upload an image and generate an edited image using a SafeTensor model.", |
|
capture_session=True |
|
).launch() |
|
|