nightfury commited on
Commit
7ce533e
·
1 Parent(s): dcf3c94

Create new file

Browse files
Files changed (1) hide show
  1. colorization_module.app +40 -0
colorization_module.app ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("hub install deoldify==1.0.1")
3
+ import gradio as gr
4
+ import paddlehub as hub
5
+ from pathlib import Path
6
+ from datetime import datetime
7
+ from typing import Optional
8
+
9
+
10
+ model = hub.Module(name='deoldify')
11
+ # NOTE: Max is 45 with 11GB video cards. 35 is a good default
12
+ render_factor=35
13
+
14
+
15
+ def colorize_image(image):
16
+ # now = datetime.now().strftime("%Y%m%d-%H%M%S-%f")
17
+ if not os.path.exists("./output"):
18
+ os.makedirs("./output")
19
+ # if image is not None:
20
+ # image.save(f"./output/{now}-input.jpg")
21
+ model.predict(image.name)
22
+ return './output/DeOldify/'+Path(image.name).stem+".png"
23
+
24
+
25
+ def create_interface():
26
+ with gr.Blocks() as enhancer:
27
+ gr.Markdown("Colorize old black & white photos")
28
+ with gr.Column(scale=1, label = "Colorize photo", visible=True) as colorize_column:
29
+ colorize_input = gr.Image(type="file")
30
+ colorize_button = gr.Button("Colorize!")
31
+ colorize_output = gr.Image(type="file")
32
+ download_colorize_button = gr.outputs.File(label="Download colorized image!")
33
+ colorize_button.click(colorize_image, inputs=colorize_input, outputs=colorize_output)
34
+ enhancer.launch()
35
+
36
+ def run_code():
37
+ create_interface()
38
+
39
+ # The main function
40
+ run_code()