File size: 1,839 Bytes
ad68f85
 
 
 
 
d1d6b7a
ad68f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1d6b7a
ad68f85
 
 
 
 
 
 
 
 
 
 
 
1275154
 
 
 
 
ad68f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from PIL import Image
from diffusers import DiffusionPipeline
import os
import spaces

# Constants
#SAFETY_CHECKER = os.environ.get("SAFETY_CHECKER", "0") == "1"

# Initialize the model
pipe = DiffusionPipeline.from_pretrained(
    "playgroundai/playground-v2.5-1024px-aesthetic",
    torch_dtype=torch.float16,
    variant="fp16",
).to("cuda")

# Safety Checker (if necessary)
#if SAFETY_CHECKER:
    # Implement or import the safety checker code here

@spaces.GPU(enable_queue=True)
def generate_image(prompt, num_inference_steps=50, guidance_scale=7):
    # Generate image
    results = pipe(prompt=prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale)

    # Safety check (if necessary)
    if SAFETY_CHECKER:
        # Implement the safety check logic here
        pass

    return results.images[0]

# Gradio Interface
description = """
This demo utilizes the playgroundai/playground-v2.5-1024px-aesthetic by Playground, which is a text-to-image generative model capable of producing high-quality images.
As a community effort, this demo was put together by AngryPenguin. Link to model: https://huggingface.co/playgroundai/playground-v2.5-1024px-aesthetic
"""

with gr.Blocks() as demo:
    gr.Markdown("## Playground-V2.5 Demo")
    with gr.Row():
        prompt = gr.Textbox(label='Enter your image prompt')
        num_inference_steps = gr.Slider(minimum=1, maximum=75, step=1, label='Number of Inference Steps', value=50)
        guidance_scale = gr.Slider(minimum=1, maximum=20, step=0.1, label='Guidance Scale', value=7)
        submit = gr.Button('Generate Image')
    img = gr.Image(label='Generated Image')

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


demo.queue().launch()