File size: 2,137 Bytes
ad68f85
 
 
 
 
d1d6b7a
ad68f85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1d6b7a
ad68f85
 
 
 
 
21a7c2f
ad68f85
21a7c2f
ad68f85
 
 
46fc6aa
 
ad68f85
1275154
 
 
 
 
ad68f85
 
62c6ea1
46fc6aa
 
ad68f85
 
46fc6aa
 
 
ad68f85
21a7c2f
46fc6aa
 
 
 
 
ad68f85
 
 
46fc6aa
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
57
58
59
60
61
62
63
64
65
66
67
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]

import gradio as gr

# 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")
    gr.Markdown(description)

    # Prompt on its own row
    with gr.Row():
        prompt = gr.Textbox(label='Enter your image prompt')

    # Sliders for inference steps and guidance scale on another row
    with gr.Row():
        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=10, step=0.1, label='Guidance Scale', value=5)

    # Submit button
    submit = gr.Button('Generate Image')

    # Image output at the bottom
    img = gr.Image(label='Generated Image')

    submit.click(
        fn=generate_image,  # This function needs to be defined to generate the image based on the inputs
        inputs=[prompt, num_inference_steps, guidance_scale],
        outputs=img,
    )

demo.queue().launch()