File size: 1,352 Bytes
68f7549
4c7447e
9d5045e
 
4c7447e
 
 
 
b372ff9
 
 
2bc874f
20dacf0
4c7447e
 
 
f2ef10f
4c7447e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b372ff9
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
import torch
import spaces
import gradio as gr

from diffusers import StableDiffusionPipeline


repo = "Tramac/style-portrait-v1-5"
pipeline = StableDiffusionPipeline.from_pretrained(
    repo,
    torch_dtype=torch.float16,
)
# pipeline.enable_model_cpu_offload()

@spaces.GPU(enable_queue=True)
def generate_image(prompt, neg_prompt):
    results = pipeline(
        prompt=prompt,
        negative_prompt=neg_prompt,
        height=832,
        width=512,
        num_inference_steps=20,
    )
    return results.images[0]



with gr.Blocks() as demo:
    gr.HTML("<h1><center>Style Portrait</center></h1>")
    gr.HTML("<p><center>text-to-image generation</center></p><p><center><a href='https://huggingface.co/Tramac/style-portrait-v1-5'></a></center></p>")
    with gr.Row():
        with gr.Column():
            prompt = gr.Textbox(label='Enter your prompt', scale=8)
            neg_prompt = gr.Textbox(label='Enter your negative prompt', scale=8)
            submit = gr.Button(scale=1, variant='primary')

        with gr.Column():
            img = gr.Image(label='Style-Portrait Generated Image')

    prompt.submit(
        fn=generate_image,
        inputs=[prompt, neg_prompt],
        outputs=img,
    )
    submit.click(
        fn=generate_image,
        inputs=[prompt, neg_prompt],
        outputs=img,
    )

demo.queue().launch()