Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	
		zhiweili
		
	commited on
		
		
					Commit 
							
							·
						
						13b9583
	
1
								Parent(s):
							
							e581b1e
								
fix canny image
Browse files- app_haircolor_pix2pix.py +9 -8
    	
        app_haircolor_pix2pix.py
    CHANGED
    
    | @@ -3,6 +3,7 @@ import gradio as gr | |
| 3 | 
             
            import time
         | 
| 4 | 
             
            import torch
         | 
| 5 | 
             
            import numpy as np
         | 
|  | |
| 6 |  | 
| 7 | 
             
            from PIL import Image
         | 
| 8 | 
             
            from segment_utils import(
         | 
| @@ -66,7 +67,7 @@ def image_to_image( | |
| 66 | 
             
                run_task_time = 0
         | 
| 67 | 
             
                time_cost_str = ''
         | 
| 68 | 
             
                run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
         | 
| 69 | 
            -
                canny_image =  | 
| 70 |  | 
| 71 | 
             
                cond_image = canny_image
         | 
| 72 | 
             
                cond_scale = cond_scale1
         | 
| @@ -88,14 +89,14 @@ def image_to_image( | |
| 88 |  | 
| 89 | 
             
                return generated_image, time_cost_str
         | 
| 90 |  | 
| 91 | 
            -
            def  | 
| 92 | 
            -
                image = np.array(image | 
| 93 | 
            -
                image_mask = np.array(image_mask.convert("L")).astype(np.float32) / 255.0
         | 
| 94 |  | 
| 95 | 
            -
                 | 
| 96 | 
            -
                 | 
| 97 | 
            -
             | 
| 98 | 
            -
                image =  | 
|  | |
| 99 | 
             
                return image
         | 
| 100 |  | 
| 101 | 
             
            def get_time_cost(run_task_time, time_cost_str):
         | 
|  | |
| 3 | 
             
            import time
         | 
| 4 | 
             
            import torch
         | 
| 5 | 
             
            import numpy as np
         | 
| 6 | 
            +
            import cv2
         | 
| 7 |  | 
| 8 | 
             
            from PIL import Image
         | 
| 9 | 
             
            from segment_utils import(
         | 
|  | |
| 67 | 
             
                run_task_time = 0
         | 
| 68 | 
             
                time_cost_str = ''
         | 
| 69 | 
             
                run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
         | 
| 70 | 
            +
                canny_image = custom_canny_detector(input_image)
         | 
| 71 |  | 
| 72 | 
             
                cond_image = canny_image
         | 
| 73 | 
             
                cond_scale = cond_scale1
         | 
|  | |
| 89 |  | 
| 90 | 
             
                return generated_image, time_cost_str
         | 
| 91 |  | 
| 92 | 
            +
            def custom_canny_detector(image):
         | 
| 93 | 
            +
                image = np.array(image)
         | 
|  | |
| 94 |  | 
| 95 | 
            +
                low_threshold = 100
         | 
| 96 | 
            +
                high_threshold = 200
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                image = cv2.Canny(image, low_threshold, high_threshold)
         | 
| 99 | 
            +
                image = Image.fromarray(image)
         | 
| 100 | 
             
                return image
         | 
| 101 |  | 
| 102 | 
             
            def get_time_cost(run_task_time, time_cost_str):
         |