Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,33 +4,36 @@ import torch
|
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
-
# Load the model
|
| 8 |
model_id = "nitrosocke/Ghibli-Diffusion"
|
| 9 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 10 |
|
| 11 |
# Define the inference function
|
| 12 |
def ghibli_transform(input_image, prompt="ghibli style", strength=0.75, guidance_scale=7.5):
|
| 13 |
-
# Check
|
|
|
|
| 14 |
if input_image is None:
|
| 15 |
raise gr.Error("Please upload an image before clicking Transform!")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
if not isinstance(input_image, np.ndarray):
|
| 19 |
-
raise gr.Error("Input image format is invalid. Expected a NumPy array.")
|
| 20 |
-
|
| 21 |
try:
|
| 22 |
-
init_image =
|
|
|
|
| 23 |
except Exception as e:
|
| 24 |
raise gr.Error(f"Failed to process image: {str(e)}")
|
| 25 |
|
| 26 |
# Generate the Ghibli-style image
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
return output
|
| 36 |
|
|
@@ -41,7 +44,7 @@ with gr.Blocks(title="Ghibli Diffusion Image Transformer") as demo:
|
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column():
|
| 44 |
-
input_img = gr.Image(label="Upload Image", type="
|
| 45 |
prompt = gr.Textbox(label="Prompt", value="ghibli style")
|
| 46 |
strength = gr.Slider(0, 1, value=0.75, step=0.05, label="Strength (How much to transform)")
|
| 47 |
guidance = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
+
# Load the model
|
| 8 |
model_id = "nitrosocke/Ghibli-Diffusion"
|
| 9 |
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
|
| 10 |
|
| 11 |
# Define the inference function
|
| 12 |
def ghibli_transform(input_image, prompt="ghibli style", strength=0.75, guidance_scale=7.5):
|
| 13 |
+
# Debug: Check input type and value
|
| 14 |
+
print(f"Input type: {type(input_image)}")
|
| 15 |
if input_image is None:
|
| 16 |
raise gr.Error("Please upload an image before clicking Transform!")
|
| 17 |
|
| 18 |
+
# Since input is now PIL, just resize and ensure RGB
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
+
init_image = input_image.resize((768, 768)).convert("RGB")
|
| 21 |
+
print(f"Converted to PIL Image: {type(init_image)}")
|
| 22 |
except Exception as e:
|
| 23 |
raise gr.Error(f"Failed to process image: {str(e)}")
|
| 24 |
|
| 25 |
# Generate the Ghibli-style image
|
| 26 |
+
try:
|
| 27 |
+
output = pipe(
|
| 28 |
+
prompt=prompt,
|
| 29 |
+
init_image=init_image,
|
| 30 |
+
strength=strength,
|
| 31 |
+
guidance_scale=guidance_scale,
|
| 32 |
+
num_inference_steps=50
|
| 33 |
+
).images[0]
|
| 34 |
+
print("Pipeline executed successfully")
|
| 35 |
+
except Exception as e:
|
| 36 |
+
raise gr.Error(f"Pipeline error: {str(e)}")
|
| 37 |
|
| 38 |
return output
|
| 39 |
|
|
|
|
| 44 |
|
| 45 |
with gr.Row():
|
| 46 |
with gr.Column():
|
| 47 |
+
input_img = gr.Image(label="Upload Image", type="pil") # Changed to "pil"
|
| 48 |
prompt = gr.Textbox(label="Prompt", value="ghibli style")
|
| 49 |
strength = gr.Slider(0, 1, value=0.75, step=0.05, label="Strength (How much to transform)")
|
| 50 |
guidance = gr.Slider(1, 20, value=7.5, step=0.5, label="Guidance Scale")
|