File size: 4,525 Bytes
985dde8
 
 
 
 
 
 
 
 
 
 
 
812872a
985dde8
 
 
 
 
 
 
812872a
985dde8
 
 
 
 
 
 
 
 
812872a
985dde8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
812872a
e3eb7bd
812872a
985dde8
 
 
 
812872a
985dde8
 
812872a
985dde8
 
812872a
985dde8
 
812872a
985dde8
 
 
812872a
 
985dde8
 
812872a
 
985dde8
812872a
985dde8
812872a
985dde8
 
812872a
 
985dde8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import gradio as gr
import spaces
import torch
from diffusers import NewbiePipeline
from transformers import AutoModel
import random
import warnings

warnings.filterwarnings("ignore")

model_path = "Disty0/NewBie-image-Exp0.1-Diffusers"  # NewBie-AI/NewBie-image-Exp0.1

print("Text Encoder...")
text_encoder_2 = AutoModel.from_pretrained(
    model_path, 
    subfolder="text_encoder_2", 
    trust_remote_code=True, 
    torch_dtype=torch.bfloat16
)

print("Pipeline...")
pipe_newbie = NewbiePipeline.from_pretrained(
    model_path, 
    text_encoder_2=text_encoder_2, 
    torch_dtype=torch.bfloat16
)
pipe_newbie.to("cuda")

del text_encoder_2
torch.cuda.empty_cache()
print("Completed")

@spaces.GPU()
def generate_image_newbie(prompt, negative_prompt, height, width, num_inference_steps, guidance_scale, seed, progress=gr.Progress(track_tqdm=True)):
    if seed < 0:
        seed = random.randint(0, 2**32 - 1)

    generator = torch.Generator("cuda").manual_seed(int(seed))

    image = pipe_newbie(
        prompt=prompt,
        negative_prompt=negative_prompt,
        height=int(height),
        width=int(width),
        num_inference_steps=int(num_inference_steps),
        guidance_scale=guidance_scale,
        generator=generator,
    ).images[0]

    return image, seed

# 默认提示词
newbie_prompt = """<character_1>
<n>$character_1$</n>
<gender>1girl, solo</gender>
<appearance>blonde_hair, long_hair</appearance>
<clothing>large_hat, white_hat, white_blouse, puffy_sleeves, shoulder_cutout, black_skirt, shirt_tucked_in, socks, shoes</clothing>
<expression>looking_up</expression>
<action>sitting, reclining, arm_support, from_side, cowboy_shot, wide_shot</action>
<position>center</position>
</character_1>

<general_tags>
<count>1girl</count>
<artists> (kazutake hazano:1.2), (kazutake hazano:0.5), (onineko:0.8), (r17329 illu:0.2), (ma1ma1helmes b illu:0.2)</artists>
<style>masterpiece, best_quality, high_resolution, detailed</style>
<background>detailed_background, scenery, detailed_background</background>
<atmosphere>cheerful</atmosphere>
<lighting>dynamic_angle, depth_of_field, high_contrast, colorful, detailed_light, light_leaks, beautiful_detailed_glow, best_shadow, shiny_skin, cinematic_lighting, ray_tracing, from_above, female_focus, close-up, dutch_angle, blue_archive</lighting>
<quality>very_aesthetic, masterpiece, no_text</quality>
<objects>bag</objects>
<other>2024_year</other>
</general_tags>"""

with gr.Blocks(title="NewBie") as demo:
    gr.Markdown("# NewBie Image Generator")
    gr.Markdown("Generate high-quality anime-style images using the NewBie model.")
    
    with gr.Row(variant="panel"):
        with gr.Column(scale=2):
            prompt_newbie = gr.Textbox(
                label="Prompt",
                value=newbie_prompt,
                lines=10,
                placeholder="Enter the prompt here..."
            )
            negative_prompt_newbie = gr.Textbox(
                label="Negative Prompt",
                value="low quality, bad quality, blurry, low resolution, deformed, ugly, bad anatomy",
                lines=3,
                placeholder="Enter the elements that should not appear here..."
            )
            
            with gr.Row():
                height_newbie = gr.Slider(label="Height", minimum=512, maximum=2048, step=64, value=1024)
                width_newbie = gr.Slider(label="Width", minimum=512, maximum=2048, step=64, value=1024)
            
            with gr.Row():
                steps_newbie = gr.Slider(label="Inference Steps", minimum=1, maximum=100, step=1, value=28)
                guidance_scale_newbie = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=20.0, step=0.1, value=3.5)
            
            seed_newbie = gr.Number(label="Seed, -1 is random", value=-1, precision=0)
            
            generate_btn_newbie = gr.Button("Generate", variant="primary")

        with gr.Column(scale=1):
            image_output_newbie = gr.Image(label="Output", format="png", interactive=False)
            used_seed_newbie = gr.Number(label="Used Seed", interactive=False)

    generate_btn_newbie.click(
        fn=generate_image_newbie,
        inputs=[
            prompt_newbie, 
            negative_prompt_newbie, 
            height_newbie, 
            width_newbie, 
            steps_newbie, 
            guidance_scale_newbie, 
            seed_newbie
        ],
        outputs=[image_output_newbie, used_seed_newbie]
    )

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