Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Added gray-scale and negative preprocessing for input images
Browse files- app.py +16 -3
- requirements.txt +3 -1
    	
        app.py
    CHANGED
    
    | @@ -8,19 +8,32 @@ import openai | |
| 8 | 
             
            import ast
         | 
| 9 | 
             
            import os
         | 
| 10 | 
             
            from deta import Deta
         | 
|  | |
| 11 |  | 
| 12 |  | 
| 13 | 
             
            openai.api_key = os.getenv('API_KEY')
         | 
| 14 | 
             
            reader = Reader(["tr"])
         | 
| 15 |  | 
|  | |
| 16 | 
             
            def get_parsed_address(input_img):
         | 
| 17 |  | 
| 18 | 
             
                address_full_text = get_text(input_img)
         | 
| 19 | 
             
                return openai_response(address_full_text)
         | 
| 20 | 
            -
                
         | 
| 21 |  | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 24 | 
             
                return " ".join(result)
         | 
| 25 |  | 
| 26 |  | 
|  | |
| 8 | 
             
            import ast
         | 
| 9 | 
             
            import os
         | 
| 10 | 
             
            from deta import Deta
         | 
| 11 | 
            +
            import cv2
         | 
| 12 |  | 
| 13 |  | 
| 14 | 
             
            openai.api_key = os.getenv('API_KEY')
         | 
| 15 | 
             
            reader = Reader(["tr"])
         | 
| 16 |  | 
| 17 | 
            +
             | 
| 18 | 
             
            def get_parsed_address(input_img):
         | 
| 19 |  | 
| 20 | 
             
                address_full_text = get_text(input_img)
         | 
| 21 | 
             
                return openai_response(address_full_text)
         | 
|  | |
| 22 |  | 
| 23 | 
            +
             | 
| 24 | 
            +
            def preprocess_img(inp_image):
         | 
| 25 | 
            +
                gray = cv2.cvtColor(inp_image, cv2.COLOR_BGR2GRAY)
         | 
| 26 | 
            +
                gray_img = cv2.bitwise_not(gray)
         | 
| 27 | 
            +
                return gray_img
         | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
| 30 | 
            +
            def get_text(image):
         | 
| 31 | 
            +
                processed_image = preprocess_img(inp_image=image)
         | 
| 32 | 
            +
                result = reader.readtext(processed_image,
         | 
| 33 | 
            +
                                         detail=0,
         | 
| 34 | 
            +
                                         paragraph=True
         | 
| 35 | 
            +
                                         )
         | 
| 36 | 
            +
             | 
| 37 | 
             
                return " ".join(result)
         | 
| 38 |  | 
| 39 |  | 
    	
        requirements.txt
    CHANGED
    
    | @@ -2,4 +2,6 @@ openai | |
| 2 | 
             
            Pillow
         | 
| 3 | 
             
            easyocr
         | 
| 4 | 
             
            gradio
         | 
| 5 | 
            -
            deta
         | 
|  | |
|  | 
|  | |
| 2 | 
             
            Pillow
         | 
| 3 | 
             
            easyocr
         | 
| 4 | 
             
            gradio
         | 
| 5 | 
            +
            deta
         | 
| 6 | 
            +
            opencv-python
         | 
| 7 | 
            +
            opencv-contrib-python
         | 

