Spaces:
Runtime error
Runtime error
File size: 2,560 Bytes
414eb06 faace9e 121192a 414eb06 224639d 414eb06 6145d60 5da113a 6bbf751 5da113a 121192a 5da113a 121192a 414eb06 db4aed5 a177ad1 db4aed5 414eb06 6145d60 414eb06 db4aed5 414eb06 |
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 |
import os
import gradio as gr
import PIL.Image
import numpy as np
import random
import torch
import subprocess
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import time
model_id = "dicoo_model"
dpm = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder="scheduler")
pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=dpm, torch_dtype=torch.float)
def predict(prompt, steps=25, seed=42, guidance_scale=7.5):
# cpu info
# print(subprocess.check_output(["cat /proc/cpuinfo | grep 'model name' |uniq"], stderr=subprocess.STDOUT).decode("utf8"))
print("prompt: ", prompt)
print("steps: ", steps)
generator = torch.manual_seed(seed)
start_time = time.time()
image = pipe(prompt, generator=generator, num_inference_steps=steps, guidance_scale=7.5).images[0]
print("cost: ", time.time() - start_time)
return image
md = """
This Spaces app is same as <a href=\"https://huggingface.co/spaces/Intel/dicoo_diffusion\">Intel/dicoo_diffusion</a>, created by Intel AIA/AIPC team with the model fine-tuned with one shot (one image) for a newly introduced object \"dicoo\". To replicate the model fine-tuning, please refer to the code sample in <a href=\"https://github.com/intel/neural-compressor/tree/master/examples/pytorch/diffusion_model/diffusers/textual_inversion\">Intel Neural Compressor</a>. You may also refer to our <a href=\"https://medium.com/intel-analytics-software/personalized-stable-diffusion-with-few-shot-fine-tuning-on-a-single-cpu-f01a3316b13\">blog</a> for more details.
**Tips:**
1) When inputting prompts, you need to contain the word **<dicoo>** which represents the pretrained object \"dicoo\".
2) For better generation, you maybe increase the inference steps.
"""
random_seed = random.randint(0, 2147483647)
gr.Interface(
predict,
inputs=[
gr.inputs.Textbox(label='Prompt', default='a lovely <dicoo> in red dress and hat, in the snowy and brightly night, with many brightly buildings'),
gr.inputs.Slider(1, 100, label='Inference Steps', default=25, step=1),
gr.inputs.Slider(0, 2147483647, label='Seed', default=random_seed, step=1),
gr.inputs.Slider(1.0, 20.0, label='Guidance Scale - how much the prompt will influence the results', default=6.0, step=0.1),
],
outputs=gr.Image(shape=[512, 512], type="pil", elem_id="output_image"),
css="#output_image{width: 256px}",
title="Demo of dicoo-finetuned-diffusion-model using Intel Neural Compressor 🧨",
description=md,
).launch()
|