Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,34 +5,19 @@ from PIL import Image
|
|
| 5 |
import random
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
|
| 8 |
-
# Initialize
|
| 9 |
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
|
| 10 |
pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora")
|
| 11 |
-
pipeline.to("cuda:0")
|
| 12 |
-
|
| 13 |
-
MAX_SEED = np.iinfo(np.int32).max
|
| 14 |
|
| 15 |
def text_to_image(prompt):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
output = pipeline(
|
| 20 |
-
prompt=prompt,
|
| 21 |
-
negative_prompt=negative_prompt,
|
| 22 |
-
width=1024,
|
| 23 |
-
height=1024,
|
| 24 |
-
guidance_scale=7.0,
|
| 25 |
-
num_inference_steps=25,
|
| 26 |
-
generator=torch.Generator().manual_seed(seed),
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
generated_img_tensor = output.images[0]
|
| 30 |
-
generated_img_array = generated_img_tensor.cpu().numpy().transpose((1, 2, 0))
|
| 31 |
-
return generated_img_array
|
| 32 |
|
| 33 |
def create_cereal_box(input_image):
|
| 34 |
-
cover_img = Image
|
| 35 |
template_img = Image.open('CerealBoxMaker/template.jpeg')
|
|
|
|
|
|
|
| 36 |
scaling_factor = 1.5
|
| 37 |
rect_height = int(template_img.height * 0.32)
|
| 38 |
new_width = int(rect_height * 0.70)
|
|
@@ -49,13 +34,15 @@ def create_cereal_box(input_image):
|
|
| 49 |
template_copy = template_img.copy()
|
| 50 |
template_copy.paste(cover_resized_scaled, left_position)
|
| 51 |
template_copy.paste(cover_resized_scaled, right_position)
|
|
|
|
|
|
|
| 52 |
template_copy_array = np.array(template_copy)
|
| 53 |
return template_copy_array
|
| 54 |
|
| 55 |
def combined_function(prompt):
|
| 56 |
-
|
| 57 |
-
final_img = create_cereal_box(
|
| 58 |
return final_img
|
| 59 |
|
| 60 |
-
# Create
|
| 61 |
-
gr.Interface(fn=combined_function, inputs="text", outputs="image").launch(
|
|
|
|
| 5 |
import random
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
|
| 8 |
+
# Initialize DiffusionPipeline with LoRA weights
|
| 9 |
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
|
| 10 |
pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora")
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def text_to_image(prompt):
|
| 13 |
+
generated_img = pipeline(prompt)
|
| 14 |
+
return generated_img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def create_cereal_box(input_image):
|
| 17 |
+
cover_img = input_image # This should already be a PIL Image
|
| 18 |
template_img = Image.open('CerealBoxMaker/template.jpeg')
|
| 19 |
+
|
| 20 |
+
# Cereal box creation logic
|
| 21 |
scaling_factor = 1.5
|
| 22 |
rect_height = int(template_img.height * 0.32)
|
| 23 |
new_width = int(rect_height * 0.70)
|
|
|
|
| 34 |
template_copy = template_img.copy()
|
| 35 |
template_copy.paste(cover_resized_scaled, left_position)
|
| 36 |
template_copy.paste(cover_resized_scaled, right_position)
|
| 37 |
+
|
| 38 |
+
# Convert to a numpy array for Gradio output
|
| 39 |
template_copy_array = np.array(template_copy)
|
| 40 |
return template_copy_array
|
| 41 |
|
| 42 |
def combined_function(prompt):
|
| 43 |
+
generated_img = text_to_image(prompt)
|
| 44 |
+
final_img = create_cereal_box(generated_img)
|
| 45 |
return final_img
|
| 46 |
|
| 47 |
+
# Create Gradio Interface
|
| 48 |
+
gr.Interface(fn=combined_function, inputs="text", outputs="image").launch()
|