afondiel commited on
Commit
0a07ad3
1 Parent(s): 302a640

add app files

Browse files
Files changed (4) hide show
  1. .gitignore +0 -0
  2. app.py +58 -0
  3. demo.jpg +0 -0
  4. requirements.txt +10 -0
.gitignore ADDED
File without changes
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_imageslider import ImageSlider
3
+ import numpy as np
4
+ import torch
5
+
6
+ import fastai
7
+ from deoldify import device
8
+ from deoldify.device_id import DeviceId
9
+ from deoldify.visualize import *
10
+
11
+ import warnings
12
+ from collections.abc import Sized # Import Sized from collections.abc
13
+ warnings.filterwarnings("ignore", category=UserWarning, message=".*?Your .*? set is empty.*?")
14
+
15
+ # Set the device to use for computation
16
+ # choices: CPU, GPU0...GPU7
17
+ if torch.cuda.is_available():
18
+ device.set(device=DeviceId.GPU0)
19
+ else:
20
+ device.set(device=DeviceId.CPU)
21
+
22
+ # Load the pre-trained model
23
+ colorizer = get_image_colorizer(artistic=True)
24
+
25
+
26
+ def colorizer_fn(input_img, render_factor):
27
+ """
28
+ Colorize grayscale images/photos
29
+ - @param input_img old (grayscale) image
30
+ - @param render_factor render_factor
31
+ """
32
+ if input_img is not None and input_img !='':
33
+ output_img = colorizer.get_transformed_image(
34
+ path=input_img,
35
+ render_factor=int(render_factor),
36
+ watermarked=watermarked,
37
+ post_process=True,
38
+ )
39
+ else:
40
+ print('Provide an image and try again.')
41
+
42
+ return (input_img, output_img) # Return a tuple of old and color Image to be plotted with ImageSlider()
43
+
44
+ title = "AI Image Colorizer"
45
+ description = "Colorize old images with AI"
46
+ examples = [["./demo.jpg"],]
47
+
48
+ demo = gr.Interface(
49
+ fn=colorizer_fn,
50
+ inputs=[gr.Image(type="filepath" , label="Old image"), gr.Slider(0, 40, label="Render Factor", value=10)],
51
+ outputs=ImageSlider(type="pil", label="Old vs Colored image"),
52
+ examples=examples,
53
+ title=title,
54
+ description=description,
55
+ )
56
+
57
+ # Launch the demo
58
+ demo.launch()
demo.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ numpy
3
+ torch
4
+ torchvision
5
+ fastai
6
+ pillow
7
+ scipy
8
+ opencv-python
9
+ deoldify
10
+