Spaces:
Runtime error
Runtime error
Commit
·
3432643
1
Parent(s):
e55ec3c
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from diffusers import DiffusionPipeline
|
|
|
|
| 4 |
|
| 5 |
# Load model and scheduler
|
| 6 |
ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
|
| 7 |
|
| 8 |
def generate_image(prompt, negative_prompt="Low quality", width=512, height=512):
|
| 9 |
# Run pipeline in inference (sample random noise and denoise)
|
|
|
|
| 10 |
images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images
|
| 11 |
# Resize image to desired width and height
|
| 12 |
resized_images = [image.resize((int(width), int(height))) for image in images]
|
| 13 |
# Save images
|
| 14 |
for idx, image in enumerate(resized_images):
|
| 15 |
image.save(f"squirrel-{idx}.png")
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Define the interface
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=generate_image,
|
| 21 |
inputs=["text", "text", "number", "number"],
|
| 22 |
-
outputs="
|
| 23 |
layout="vertical",
|
| 24 |
title="Image Generation",
|
| 25 |
description="Generate images based on prompts.",
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from PIL import Image
|
| 3 |
from diffusers import DiffusionPipeline
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
# Load model and scheduler
|
| 7 |
ldm = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")
|
| 8 |
|
| 9 |
def generate_image(prompt, negative_prompt="Low quality", width=512, height=512):
|
| 10 |
# Run pipeline in inference (sample random noise and denoise)
|
| 11 |
+
start_time = time.time()
|
| 12 |
images = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6, negative_prompts=[negative_prompt]).images
|
| 13 |
# Resize image to desired width and height
|
| 14 |
resized_images = [image.resize((int(width), int(height))) for image in images]
|
| 15 |
# Save images
|
| 16 |
for idx, image in enumerate(resized_images):
|
| 17 |
image.save(f"squirrel-{idx}.png")
|
| 18 |
+
end_time = time.time()
|
| 19 |
+
elapsed_time = round(end_time - start_time, 2)
|
| 20 |
+
return f"Images generated successfully! (Elapsed Time: {elapsed_time} seconds)"
|
| 21 |
|
| 22 |
# Define the interface
|
| 23 |
iface = gr.Interface(
|
| 24 |
fn=generate_image,
|
| 25 |
inputs=["text", "text", "number", "number"],
|
| 26 |
+
outputs=gr.outputs.Image(label="Generated Image"),
|
| 27 |
layout="vertical",
|
| 28 |
title="Image Generation",
|
| 29 |
description="Generate images based on prompts.",
|