Spaces:
Running
on
Zero
Running
on
Zero
File size: 4,222 Bytes
6975d9d 111d52a 6975d9d 05d6764 6975d9d fa03680 6975d9d 05d6764 6975d9d 05d6764 ef9bd00 f0c8de8 1da767b 6975d9d 05d6764 6975d9d b601b6b 6975d9d 111d52a 6975d9d 05d6764 6975d9d 7a7adfe 6975d9d 0812180 0f33a11 8d30381 af168f5 6975d9d ef9bd00 6975d9d 1babf2b f42bc2e 6975d9d 67bad40 ef9bd00 67bad40 6975d9d 67bad40 85686bc 6975d9d 67bad40 f42bc2e 111d52a 7c71d69 67bad40 0812180 6975d9d ef9bd00 c136a2e 934e538 ef9bd00 0f33a11 6975d9d b601b6b 6975d9d 5101352 6975d9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
import torch
import spaces
from diffusers import StableDiffusionPipeline, DDIMScheduler, AutoencoderKL
from transformers import AutoFeatureExtractor
from controlnet.callable_functions import process_single_image_both_ways,make_stylecode,use_stylecode
from huggingface_hub import hf_hub_download
import gradio as gr
import cv2
import os
ip_ckpt = hf_hub_download(repo_id="CiaraRowles/stylecodes", filename="stylecodes_sd15_v1.bin", repo_type="model")
device = "cuda"
example_path = os.path.join(os.path.dirname(__file__), 'test_images')
list_dir = os.listdir(example_path)
list_path = [os.path.join(example_path,img) for img in list_dir]
print("all paths ", list_path)
cv2.setNumThreads(1)
@spaces.GPU(enable_queue=True)
def generate_image(images, prompt, negative_prompt,stylecode,strength,additional_prompt, seed, progress=gr.Progress(track_tqdm=True)):
full_prompt=prompt + additional_prompt
image = images
yield None
base_size = 512
# Calculate new width and height
image = use_stylecode(ip_ckpt,image_path="",prompt=full_prompt,negative_prompt=negative_prompt,num_inference_steps=20,image=image,stylecode=stylecode,seed=seed)
yield image
@spaces.GPU(enable_queue=True)
def make_stylecode_gui (images, progress=gr.Progress(track_tqdm=True)):
yield None
code = make_stylecode(ip_ckpt,image_path=None,image=images)
yield code[0]
def swap_to_gallery(images):
return gr.update(value=images, visible=True), gr.update(visible=True), gr.update(visible=False)
def remove_back_to_files():
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
css = '''
h1{margin-bottom: 0 !important}
'''
with gr.Blocks(css=css) as demo:
gr.Markdown("# stylecodes demo")
gr.Markdown("Demo for the [CiaraRowles/stylecodes model](https://huggingface.co./CiaraRowles/stylecodes)")
with gr.Row():
with gr.Column():
files = gr.Image(
label="Input image",
type="pil"
)
uploaded_files = gr.Gallery(label="Your image", visible=False, columns=5, rows=1, height=125)
with gr.Column(visible=False) as clear_button:
remove_and_reupload = gr.ClearButton(value="Remove and upload new ones", components=files, size="sm")
stylecode = gr.Textbox(label="stylecode")
stylecode_gen = gr.Button("Make stylecode")
prompt = gr.Textbox(label="Prompt",
info="Try something like 'a photo of a man/woman/person'",
placeholder="A photo of a [man/woman/person]...")
negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="low quality")
with gr.Accordion(open=False, label="Advanced Options"):
strength = gr.Slider(label="strength", value=0.9, step=0.05, minimum=0, maximum=1)
additional_prompt = gr.Textbox(label="additional prompt",placeholder ="highly detailed ,simple background")
seed = gr.Number(label="seed",value = -1)
submit = gr.Button("Use stylecode")
with gr.Column():
gallery = gr.Gallery(label="Generated Images")
examples = gr.Examples(
inputs=files,
examples_per_page=6,
examples=list_path
)
stylecode_gen.click(fn=make_stylecode_gui,inputs=[files],outputs=stylecode)
submit.click(fn=generate_image,
inputs=[files, prompt, negative_prompt,stylecode,strength,additional_prompt,seed],
outputs=gallery)
gr.Markdown("note, this was trained primarily on digital painting esk generated images, don't expect it to work outside of that training data for the moment")
gr.Markdown("This demo includes extra features to mitigate the implicit bias of the model and prevent explicit usage of it to generate content with faces of people, including third parties, that is not safe for all audiences, including naked or semi-naked people.")
gr.Markdown("based on: https://huggingface.co./spaces/multimodalart/Ip-Adapter-FaceID")
demo.launch() |