File size: 2,715 Bytes
b60f459
 
1fa3748
 
b60f459
 
 
c35fda2
 
a5bdce9
1fa3748
 
9f1a2ce
2f81857
c35fda2
2f81857
 
 
899ef55
c35fda2
5c61552
b43fcf5
 
 
 
 
 
 
 
 
 
 
 
 
c35fda2
 
 
 
 
 
 
 
 
bbf5928
74b8b05
fcf6180
 
833a8d9
74b8b05
c35fda2
 
448cbb4
 
c35fda2
 
 
 
4da129c
 
c35fda2
 
 
 
 
 
 
 
 
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
import os

# os.system('pip install paddlepaddle') # for cpu enviroment
os.system('pip install paddlepaddle-gpu==2.4.2.post117 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html')
os.system('pip install paddlenlp>=2.5.2')
os.system('pip install ppdiffusers>=0.14.0')

import gradio as gr
from ppdiffusers import StableDiffusionPipeline

# 通过git获取仓库模型,并读取
# import git
# 获取模型参数
# repo = git.Repo.clone_from(url='https://huggingface.co/Liyulingyue/Neolle_Face_Generator', to_path="./dream_outputs")
# 加载模型
# model_path = "dream_outputs"
# pipe = StableDiffusionPipeline.from_pretrained(model_path)

pipe = StableDiffusionPipeline.from_pretrained("Liyulingyue/Neolle_Face_Generator", from_hf_hub=True)

def generate_images(prompt, num_inference_steps, guidance_scale):
    # num_inference_steps to number
    try:
        infer_steps = int(num_inference_steps)
    except:
        infer_steps = 50

    # guidance_scale to number
    try:
        gui_scale = float(guidance_scale)
    except:
        gui_scale = 7.5
    
    image = pipe(prompt, num_inference_steps=infer_steps,guidance_scale=gui_scale).images[0]
    # image = os.getcwd()
    return image

with gr.Blocks() as demo:
    gr.Markdown(
    """
    # 诺艾尔生成器
    基于 Linaqruf/anything-v3.0 训练,采用DreamBooth的技术并使用a photo of Neolle文本进行了训练。用于微调的图片共10张,均为原神角色诺艾尔,batch_size取1,学习率是5e-6,共训练1000步。

    Hugging face的CPU环境num_inference_steps=50时,大约需要运行1200s。在T4 small环境下,一张图大约需要30s到60s。

    如果推理结果包含色情内容,会返回一张纯黑图片~ 如果出现纯黑图片请重新运行

    欢迎大家从 https://huggingface.co/Liyulingyue/Neolle_Face_Generator 下载模型到本地运行, 20s即可出图, 该链接包含运行示例代码~

    ## 输入参数如下:
    - prompt:提示语
    - num_inference_steps: 推理轮次,越高越耗时,能够提高画作结果的精细程度,建议取值50,更高会需要消耗更多的时间,但效果会更好。
    - guidance_scale:训练图片的影响度,如果无法满足提示词描述的场景,可以降低该值,建议取值50。

    ## 推荐的提示词示例:
    - Noelle with dark hair, beautiful eyes
    - Noelle, 20 years old
    - Noelle with glasses
    - Noelle with sunglasses
    - Noelle playing basketball
    - Noelle with cat ears, blue hair
    """)
    gr.Interface(fn=generate_images, 
                 inputs=["text","text","text"], 
                 outputs="image")

if __name__ == "__main__":
    demo.launch()