File size: 968 Bytes
b63b2e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from diffusers import DiffusionPipeline
import torch

# Load the model
pipe = DiffusionPipeline.from_pretrained("dreamlike-art/dreamlike-photoreal-2.0")

# Check if GPU is available and move model to GPU if possible
if torch.cuda.is_available():
    pipe.to("cuda")
else:
    pipe.to("cpu")

# Define the image generation function
def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Set up the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("## Dreamlike Photoreal 2.0 Image Generator")

    prompt = gr.Textbox(
        label="Enter a creative prompt",
        placeholder="A futuristic city with flying cars"
    )
    
    image_output = gr.Image(label="Generated Image")

    generate_button = gr.Button("Generate Image")

    # Connect the button click to the image generation function
    generate_button.click(fn=generate_image, inputs=prompt, outputs=image_output)

# Launch the app
demo.launch()