File size: 2,035 Bytes
b116026
50ed895
 
2d95c60
50ed895
 
 
 
b6ec670
 
50ed895
2d95c60
50ed895
2d95c60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6ec670
2d95c60
 
b6ec670
2d95c60
 
50ed895
2d95c60
 
d8bf5cd
50ed895
2d95c60
 
 
 
 
 
 
 
 
50ed895
 
2d95c60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import os
import cv2
# Assuming img_colorization as before
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
import PIL
import numpy as np
import uuid
from gradio_imageslider import ImageSlider

# Your existing colorization pipeline
img_colorization = pipeline(Tasks.image_colorization, model='iic/cv_ddcolor_image-colorization')

# Additional pipelines for image enhancement and repair
img_enhancement = pipeline(Tasks.image_super_resolution, model='your_super_resolution_model')
img_repair = pipeline(Tasks.image_inpainting, model='your_image_repair_model')

def process_image(image, enhance_quality, repair_damage):
    # Convert image to proper format for processing
    image = image[..., ::-1]
    
    # Repair the image if requested
    if repair_damage:
        image = img_repair(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
    
    # Enhance image quality if requested
    if enhance_quality:
        image = img_enhancement(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
    
    # Colorize the image
    colored_image = img_colorization(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
    
    # Save the processed image with a unique filename
    unique_imgfilename = str(uuid.uuid4()) + '.png'
    cv2.imwrite(unique_imgfilename, colored_image)
    print('Infer finished!')
    
    # Return both original and processed image paths for the slider
    return image[..., ::-1], unique_imgfilename

title = "Old Photo Restoration"
description = "Upload old photos for colorization, quality enhancement, and damage repair."
examples = [['./input.jpg'],]

inputs = [
    gr.inputs.Image(shape=(512, 512)),
    gr.inputs.Checkbox(label="Enhance Quality"),
    gr.inputs.Checkbox(label="Repair Damage")
]

outputs = gr.outputs.ImageSlider(position=0.5, label='Processed image with slider-view')

demo = gr.Interface(fn=process_image, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description)

if __name__ == "__main__":
    demo.launch()