Shangkhonil commited on
Commit
b63b2e2
·
verified ·
1 Parent(s): 81b9df8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
+
5
+ # Load the model
6
+ pipe = DiffusionPipeline.from_pretrained("dreamlike-art/dreamlike-photoreal-2.0")
7
+
8
+ # Check if GPU is available and move model to GPU if possible
9
+ if torch.cuda.is_available():
10
+ pipe.to("cuda")
11
+ else:
12
+ pipe.to("cpu")
13
+
14
+ # Define the image generation function
15
+ def generate_image(prompt):
16
+ image = pipe(prompt).images[0]
17
+ return image
18
+
19
+ # Set up the Gradio interface
20
+ with gr.Blocks() as demo:
21
+ gr.Markdown("## Dreamlike Photoreal 2.0 Image Generator")
22
+
23
+ prompt = gr.Textbox(
24
+ label="Enter a creative prompt",
25
+ placeholder="A futuristic city with flying cars"
26
+ )
27
+
28
+ image_output = gr.Image(label="Generated Image")
29
+
30
+ generate_button = gr.Button("Generate Image")
31
+
32
+ # Connect the button click to the image generation function
33
+ generate_button.click(fn=generate_image, inputs=prompt, outputs=image_output)
34
+
35
+ # Launch the app
36
+ demo.launch()