Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
from diffusers import DiffusionPipeline
|
4 |
from PIL import Image
|
|
|
|
|
5 |
|
6 |
# Set up device
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
@@ -17,9 +19,12 @@ def process_image(prompt, image, style, upscale_factor, inpaint):
|
|
17 |
try:
|
18 |
# Ensure the image is in the correct format
|
19 |
if image is not None:
|
20 |
-
image
|
21 |
-
|
22 |
-
image
|
|
|
|
|
|
|
23 |
|
24 |
# Log the input parameters
|
25 |
print(f"Prompt: {prompt}")
|
@@ -49,7 +54,7 @@ with gr.Blocks() as demo:
|
|
49 |
with gr.Row():
|
50 |
with gr.Column():
|
51 |
prompt_input = gr.Textbox(label="Enter your prompt")
|
52 |
-
image_input = gr.Image(label="Image (for inpainting)", type="pil")
|
53 |
style_input = gr.Dropdown(choices=["Fooocus Style", "SAI Anime"], label="Select Style")
|
54 |
upscale_input = gr.Slider(minimum=1, maximum=4, step=1, label="Upscale Factor")
|
55 |
inpaint_input = gr.Checkbox(label="Enable Inpainting")
|
|
|
2 |
import torch
|
3 |
from diffusers import DiffusionPipeline
|
4 |
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
from torchvision import transforms
|
7 |
|
8 |
# Set up device
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
19 |
try:
|
20 |
# Ensure the image is in the correct format
|
21 |
if image is not None:
|
22 |
+
if isinstance(image, np.ndarray):
|
23 |
+
image = Image.fromarray(image)
|
24 |
+
elif isinstance(image, torch.Tensor):
|
25 |
+
image = transforms.ToPILImage()(image)
|
26 |
+
elif not isinstance(image, Image.Image):
|
27 |
+
return None, "Error: Unsupported image format."
|
28 |
|
29 |
# Log the input parameters
|
30 |
print(f"Prompt: {prompt}")
|
|
|
54 |
with gr.Row():
|
55 |
with gr.Column():
|
56 |
prompt_input = gr.Textbox(label="Enter your prompt")
|
57 |
+
image_input = gr.Image(label="Image (for inpainting)", type="pil")
|
58 |
style_input = gr.Dropdown(choices=["Fooocus Style", "SAI Anime"], label="Select Style")
|
59 |
upscale_input = gr.Slider(minimum=1, maximum=4, step=1, label="Upscale Factor")
|
60 |
inpaint_input = gr.Checkbox(label="Enable Inpainting")
|