Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,14 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import torch
|
3 |
-
from
|
4 |
-
from PIL import Image
|
5 |
-
from model import Generator # Assuming you are using Hammad712's model structure
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
model = Generator().to(device)
|
10 |
-
model.load_state_dict(torch.load('generator.pth', map_location=device))
|
11 |
-
model.eval()
|
12 |
-
|
13 |
-
# Define preprocessing and postprocessing
|
14 |
-
preprocess = transforms.Compose([
|
15 |
-
transforms.Resize((256, 256)),
|
16 |
-
transforms.Grayscale(num_output_channels=1),
|
17 |
-
transforms.ToTensor()
|
18 |
-
])
|
19 |
-
|
20 |
-
postprocess = transforms.ToPILImage()
|
21 |
|
22 |
def colorize_image(input_image):
|
23 |
-
|
24 |
-
|
25 |
-
output_tensor = model(input_tensor)
|
26 |
-
output_image = postprocess(output_tensor.squeeze(0).cpu().clamp(0, 1))
|
27 |
-
return output_image
|
28 |
|
29 |
def reset():
|
30 |
return None, None
|
@@ -54,7 +38,6 @@ with gr.Blocks() as demo:
|
|
54 |
outputs=[input_image, output_image]
|
55 |
)
|
56 |
|
57 |
-
# Allow download after processing
|
58 |
def prepare_download(image):
|
59 |
if image:
|
60 |
path = "colorized_output.png"
|
|
|
1 |
import gradio as gr
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
import torch
|
4 |
+
from transformers import pipeline
|
|
|
|
|
5 |
|
6 |
+
# Use an available colorization pipeline from Hugging Face
|
7 |
+
colorizer = pipeline("image-to-image", model="HuggingFaceM4/DeOldify", device_map="auto")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def colorize_image(input_image):
|
10 |
+
output = colorizer(input_image)
|
11 |
+
return output[0]['image']
|
|
|
|
|
|
|
12 |
|
13 |
def reset():
|
14 |
return None, None
|
|
|
38 |
outputs=[input_image, output_image]
|
39 |
)
|
40 |
|
|
|
41 |
def prepare_download(image):
|
42 |
if image:
|
43 |
path = "colorized_output.png"
|