Files changed (1) hide show
  1. app.py +39 -16
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import os
3
  import cv2
4
- from modelscope.outputs import OutputKeys
5
  from modelscope.pipelines import pipeline
6
  from modelscope.utils.constant import Tasks
7
  import PIL
@@ -9,26 +9,49 @@ import numpy as np
9
  import uuid
10
  from gradio_imageslider import ImageSlider
11
 
 
12
  img_colorization = pipeline(Tasks.image_colorization, model='iic/cv_ddcolor_image-colorization')
13
- img_path = 'input.png'
14
- ##result = img_colorization(img_path)
15
- ##cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
16
- def color(image):
17
- output = img_colorization(image[...,::-1])
18
- result = output[OutputKeys.OUTPUT_IMG].astype(np.uint8)
19
- # result = result[...,::-1]
20
- # Generate a unique filename using UUID
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  unique_imgfilename = str(uuid.uuid4()) + '.png'
22
- cv2.imwrite(unique_imgfilename, result)
23
- print('infer finished!')
24
- return (image, unique_imgfilename)
25
 
 
 
26
 
27
- title = "old_photo_restoration"
28
- description = "upload old photo, ddcolor image colorization"
29
  examples = [['./input.jpg'],]
30
 
31
- demo = gr.Interface(fn=color,inputs="image",outputs=ImageSlider(position=0.5,label='Colored image with slider-view'),examples=examples,title=title,description=description)
 
 
 
 
 
 
 
 
32
 
33
  if __name__ == "__main__":
34
- demo.launch(share=False)
 
1
  import gradio as gr
2
  import os
3
  import cv2
4
+ # Assuming img_colorization as before
5
  from modelscope.pipelines import pipeline
6
  from modelscope.utils.constant import Tasks
7
  import PIL
 
9
  import uuid
10
  from gradio_imageslider import ImageSlider
11
 
12
+ # Your existing colorization pipeline
13
  img_colorization = pipeline(Tasks.image_colorization, model='iic/cv_ddcolor_image-colorization')
14
+
15
+ # Additional pipelines for image enhancement and repair
16
+ img_enhancement = pipeline(Tasks.image_super_resolution, model='your_super_resolution_model')
17
+ img_repair = pipeline(Tasks.image_inpainting, model='your_image_repair_model')
18
+
19
+ def process_image(image, enhance_quality, repair_damage):
20
+ # Convert image to proper format for processing
21
+ image = image[..., ::-1]
22
+
23
+ # Repair the image if requested
24
+ if repair_damage:
25
+ image = img_repair(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
26
+
27
+ # Enhance image quality if requested
28
+ if enhance_quality:
29
+ image = img_enhancement(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
30
+
31
+ # Colorize the image
32
+ colored_image = img_colorization(image)[OutputKeys.OUTPUT_IMG].astype(np.uint8)
33
+
34
+ # Save the processed image with a unique filename
35
  unique_imgfilename = str(uuid.uuid4()) + '.png'
36
+ cv2.imwrite(unique_imgfilename, colored_image)
37
+ print('Infer finished!')
 
38
 
39
+ # Return both original and processed image paths for the slider
40
+ return image[..., ::-1], unique_imgfilename
41
 
42
+ title = "Old Photo Restoration"
43
+ description = "Upload old photos for colorization, quality enhancement, and damage repair."
44
  examples = [['./input.jpg'],]
45
 
46
+ inputs = [
47
+ gr.inputs.Image(shape=(512, 512)),
48
+ gr.inputs.Checkbox(label="Enhance Quality"),
49
+ gr.inputs.Checkbox(label="Repair Damage")
50
+ ]
51
+
52
+ outputs = gr.outputs.ImageSlider(position=0.5, label='Processed image with slider-view')
53
+
54
+ demo = gr.Interface(fn=process_image, inputs=inputs, outputs=outputs, examples=examples, title=title, description=description)
55
 
56
  if __name__ == "__main__":
57
+ demo.launch()