import os import gradio as gr import huggingface_hub as hf from PIL import Image from modules import shared, processing, sd_models, scripts class Script(scripts.Script): def title(self): return 'PhotoMaker' def show(self, is_img2img): return True if shared.backend == shared.Backend.DIFFUSERS else False def load_images(self, files): init_images = [] for file in files or []: try: if isinstance(file, str): from modules.api.api import decode_base64_to_image image = decode_base64_to_image(file) elif isinstance(file, Image.Image): image = file elif isinstance(file, dict) and 'name' in file: image = Image.open(file['name']) # _TemporaryFileWrapper from gr.Files elif hasattr(file, 'name'): image = Image.open(file.name) # _TemporaryFileWrapper from gr.Files else: raise ValueError(f'PhotoMaker unknown input: {file}') init_images.append(image) except Exception as e: shared.log.warning(f'PhotoMaker failed to load image: {e}') return init_images def ui(self, _is_img2img): with gr.Row(): trigger = gr.Text(label='Trigger word', value="person") strength = gr.Slider(label='Strength', minimum=0.0, maximum=2.0, step=0.01, value=1.0) start = gr.Slider(label='Start', minimum=0.0, maximum=1.0, step=0.01, value=0.5) with gr.Row(): files = gr.File(label='Input images', file_count='multiple', file_types=['image'], type='file', interactive=True, height=100) with gr.Row(): gallery = gr.Gallery(show_label=False, value=[]) with gr.Row(): gr.HTML('