Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import torch
|
|
| 3 |
from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
|
|
|
|
|
|
| 6 |
import time
|
| 7 |
|
| 8 |
# Force CPU usage
|
|
@@ -60,11 +62,11 @@ def generate_image(prompt):
|
|
| 60 |
# Generate the image with better settings
|
| 61 |
image = pipe(
|
| 62 |
prompt=enhanced_prompt,
|
| 63 |
-
negative_prompt=negative_prompt,
|
| 64 |
width=512,
|
| 65 |
height=512,
|
| 66 |
-
guidance_scale=9.0,
|
| 67 |
-
num_inference_steps=25,
|
| 68 |
generator=torch.Generator(device=device)
|
| 69 |
).images[0]
|
| 70 |
|
|
@@ -73,9 +75,15 @@ def generate_image(prompt):
|
|
| 73 |
image = image.convert('RGB')
|
| 74 |
|
| 75 |
print("Image generated successfully!")
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
# Create the Gradio Interface
|
| 79 |
demo = gr.Interface(
|
| 80 |
fn=generate_image,
|
| 81 |
inputs=gr.Textbox(
|
|
@@ -83,7 +91,7 @@ demo = gr.Interface(
|
|
| 83 |
lines=2,
|
| 84 |
placeholder="A dragon reading a book under a magical tree"
|
| 85 |
),
|
| 86 |
-
outputs=gr.
|
| 87 |
title="Premium Children's Book Illustrator 🤖🎨",
|
| 88 |
description="Generating high-quality, sharp, detailed images for your stories. Enter a scene description."
|
| 89 |
)
|
|
|
|
| 3 |
from diffusers import StableDiffusionPipeline, EulerAncestralDiscreteScheduler
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
| 6 |
+
import io
|
| 7 |
+
import base64
|
| 8 |
import time
|
| 9 |
|
| 10 |
# Force CPU usage
|
|
|
|
| 62 |
# Generate the image with better settings
|
| 63 |
image = pipe(
|
| 64 |
prompt=enhanced_prompt,
|
| 65 |
+
negative_prompt=negative_prompt,
|
| 66 |
width=512,
|
| 67 |
height=512,
|
| 68 |
+
guidance_scale=9.0,
|
| 69 |
+
num_inference_steps=25,
|
| 70 |
generator=torch.Generator(device=device)
|
| 71 |
).images[0]
|
| 72 |
|
|
|
|
| 75 |
image = image.convert('RGB')
|
| 76 |
|
| 77 |
print("Image generated successfully!")
|
| 78 |
+
|
| 79 |
+
# SOLUTION: Convert image to bytes and return as file
|
| 80 |
+
img_bytes = io.BytesIO()
|
| 81 |
+
image.save(img_bytes, format='PNG')
|
| 82 |
+
img_bytes.seek(0)
|
| 83 |
+
|
| 84 |
+
return img_bytes
|
| 85 |
|
| 86 |
+
# Create the Gradio Interface - CHANGE OUTPUT TO "file"
|
| 87 |
demo = gr.Interface(
|
| 88 |
fn=generate_image,
|
| 89 |
inputs=gr.Textbox(
|
|
|
|
| 91 |
lines=2,
|
| 92 |
placeholder="A dragon reading a book under a magical tree"
|
| 93 |
),
|
| 94 |
+
outputs=gr.File(label="Download Generated Illustration"), # Changed to File output
|
| 95 |
title="Premium Children's Book Illustrator 🤖🎨",
|
| 96 |
description="Generating high-quality, sharp, detailed images for your stories. Enter a scene description."
|
| 97 |
)
|