ItsJATAYU commited on
Commit
50039ab
·
verified ·
1 Parent(s): f28dfe2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -23
app.py CHANGED
@@ -1,30 +1,14 @@
1
  import gradio as gr
 
2
  import torch
3
- from torchvision import transforms
4
- from PIL import Image
5
- from model import Generator # Assuming you are using Hammad712's model structure
6
 
7
- # Load model
8
- device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
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
- input_tensor = preprocess(input_image).unsqueeze(0).to(device)
24
- with torch.no_grad():
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"