from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler import gradio as gr import torch from transformers import pipeline from PIL import Image model_id = 'Extraphy/mustafa-kemal-ataturkv2' prefix = 'Atatürk' scheduler = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder="scheduler") pipe = StableDiffusionPipeline.from_pretrained( model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32, scheduler=scheduler) #pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained( #model_id, #torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32, # scheduler=scheduler) if torch.cuda.is_available(): pipe = pipe.to("cuda") #pipe_i2i = pipe_i2i.to("cuda") def error_str(error, title="Error"): return f"""#### {title} {error}""" if error else "" def inference(prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt="", auto_prefix=False): generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None prompt = f"{prefix} {prompt}" if auto_prefix else prompt try: return txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator), None except Exception as e: return None, error_str(e) def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator): result = pipe( prompt, negative_prompt = neg_prompt, num_inference_steps = int(steps), guidance_scale = guidance, width = width, height = height, generator = generator) return result.images[0] css = """ .button, input, optgroup, select, textarea { font-family: 'Source Sans Pro'; font-size: 80%; font-weight: inherit; line-height: inherit; color: orangered; margin: 0; padding: 0; font-weight: 600; } .gr-form { display: contents; flex-direction: column; align-items: center; justify-content: center; width: 50%; line-height: 0.9rem; } .gr-label { font-size: 1.2rem; margin-bottom: 0.5rem; } .gr-input, .gr-select { width: 100%; font-size: 0.8rem; border: 1px solid #f78900; border-radius: 0.15rem; } .gr-input[type="number"] { width: fit-content; } .gr-button { font-size: 1.2rem; padding: 1.5rem 0.2rem; border: none; border-radius: 0.25rem; background-image: linear-gradient(0deg, rgb(15, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%); background: linear-gradient(0deg, rgb(185, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%); color: #f3f3f3; cursor: copy; } .gr-button:hover { background-color: Red; } } .main-div div { display: inline-flex; align-items: center; gap: .8rem; font-size: 1.75rem; } .main-div div h1 { font-weight: 1000; margin-bottom: 7px; } .main-div p { margin-bottom: 10px; font-size: 94%; } a { text-decoration: underline; } .tabs { margin-top: 0; margin-bottom: 0; } #gallery { min-height: 20rem; } .container { width: 70%; } .hcontainer { width: 80%; display: flex; overflow: auto; min-height: 185px; align-items: center; flex-direction: column; justify-content: flex-start; } .hcontainer1 { top: 20px; right: 0px; width: 100%; height: 90px; display: flex; position: absolute; align-items: flex-start; border-radius: var(--dl-radius-radius-radius8); justify-content: flex-start; } .hcontainer2 { top: 20px; right: 0px; width: 100%; height: 100%; display: flex; position: absolute; align-items: flex-start; border-radius: var(--dl-radius-radius-radius8); justify-content: flex-start; background-image: linear-gradient(0deg, rgb(185, 54, 96) 0.00%,rgb(252, 133, 123) 99.00%); } .home-image { top: 0px; right: var(--dl-space-space-halfunit); width: 50%; bottom: 0px; margin: auto; position: absolute; object-fit: cover; } .home-image1 { top: 17px; left: 23px; width: 348px; height: 52px; margin: auto; position: absolute; align-self: flex-start; object-fit: cover; } :root { --dl-color-gray-500: #595959; --dl-color-gray-700: #999999; --dl-color-gray-900: #D9D9D9; --dl-size-size-large: 144px; --dl-size-size-small: 48px; --dl-color-danger-300: #A22020; --dl-color-danger-500: #BF2626; --dl-color-danger-700: #E14747; --dl-color-gray-black: #000000; --dl-color-gray-white: #FFFFFF; --dl-size-size-medium: 96px; --dl-size-size-xlarge: 192px; --dl-size-size-xsmall: 16px; --dl-space-space-unit: 16px; --dl-color-primary-100: #003EB3; --dl-color-primary-300: #0074F0; --dl-color-primary-500: #14A9FF; --dl-color-primary-700: #85DCFF; --dl-color-success-300: #199033; --dl-color-success-500: #32A94C; --dl-color-success-700: #4CC366; --dl-size-size-xxlarge: 288px; --dl-radius-radius-round: 50%; --dl-space-space-halfunit: 8px; --dl-space-space-sixunits: 96px; --dl-space-space-twounits: 32px; --dl-radius-radius-radius2: 2px; --dl-radius-radius-radius4: 4px; --dl-radius-radius-radius8: 8px; --dl-space-space-fiveunits: 80px; --dl-space-space-fourunits: 64px; --dl-space-space-threeunits: 48px; --dl-space-space-oneandhalfunits: 24px; } """ with gr.Blocks(css=css) as demo: gr.HTML( f"""