CoolFace
Apppublic

SuCicada/waifu-diffusion

sourceHugging Faceupdated 4y agoView on Hugging Face
0likes
app2.py82 linesDownload Raw Back to root
1# pip install transformers gradio scipy ftfy "ipywidgets>=7,<8" datasets diffusers2 3import gradio as gr4import torch5from torch import autocast6from diffusers import StableDiffusionPipeline7 8model_id = "hakurei/waifu-diffusion"9device = "cpu"10 11# pipe = StableDiffusionPipeline.from_pretrained(model_id,12#                                                resume_download=True,  # 模型文件断点续传13#                                                torch_dtype=torch.float16,14#                                                revision='fp16')15# pipe = pipe.to(device)16 17block = gr.Blocks(css=".container { max-width: 800px; margin: auto; }")18 19num_samples = 220 21 22def infer(prompt):23    print(prompt)24    return prompt25    # with autocast("cuda"):26    #     images = pipe([prompt] * num_samples,27    #                   hight=111,28    #                   width=100,29    #30    #                   guidance_scale=7.5)["sample"]31 32    # return images33 34 35with block as demo:36    gr.Markdown("<h1><center>Waifu Diffusion</center></h1>")37    gr.Markdown(38        "waifu-diffusion is a latent text-to-image diffusion model that has been conditioned on high-quality anime images through fine-tuning."39    )40    with gr.Group():41        with gr.Box():42            with gr.Column().style(mobile_collapse=False, equal_height=True):43                text = gr.Textbox(44                    label="Enter your prompt",45                    show_label=False,46                    max_lines=147                ).style(48                    border=(True, False, True, True),49                    rounded=(True, False, False, True),50                    container=False,51                )52                slider = gr.Slider(0, 1000, 10)53 54                btn = gr.Button("Run").style(55                    margin=False,56                    rounded=(False, True, True, False),57                )58 59        gallery = gr.Gallery(60            label="Generated images",61            show_label=False62        ).style(63            grid=[2],64            height="auto"65        )66        gr.Interface67        text.submit(infer,68                    inputs=[text,slider] ,69                    outputs=gallery)70        btn.click(infer, inputs=[text], outputs=gallery)71 72    gr.Markdown(73        """___74      <p style='text-align: center75      '>76      Created by https://huggingface.co/hakurei77      <br/>78      </p>"""79    )80 81demo.launch(debug=True)82