Spaces:
				
			
			
	
			
			
		Configuration error
		
	
	
	
			
			
	
	
	
	
		
		
		Configuration error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -10,12 +10,9 @@ model = model.eval().cuda() | |
| 10 |  | 
| 11 | 
             
            @spaces.GPU
         | 
| 12 | 
             
            def run_GOT(image_array, got_mode, ocr_box="", ocr_color=""):
         | 
| 13 | 
            -
                print("image_array: ", image_array)
         | 
| 14 | 
            -
                print(got_mode, ' ', ocr_box, ' ', ocr_color)
         | 
| 15 | 
            -
                # image = Image.fromarray(np.uint8(image_array))
         | 
| 16 | 
             
                image = image_array
         | 
| 17 | 
             
                if got_mode == "plain texts OCR":
         | 
| 18 | 
            -
                    res = model.chat(tokenizer, image, ocr_type='ocr' | 
| 19 | 
             
                elif got_mode == "format texts OCR":
         | 
| 20 | 
             
                    res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
         | 
| 21 | 
             
                elif got_mode == "plain multi-crop OCR":
         | 
| @@ -31,8 +28,8 @@ def run_GOT(image_array, got_mode, ocr_box="", ocr_color=""): | |
| 31 | 
             
                if "format" in got_mode:
         | 
| 32 | 
             
                    with open('./demo.html', 'r') as f:
         | 
| 33 | 
             
                        demo_html = f.read()
         | 
| 34 | 
            -
                     | 
| 35 | 
            -
                 | 
| 36 |  | 
| 37 | 
             
            def task_update(task):
         | 
| 38 | 
             
                if "fine-grained" in task:
         | 
| @@ -106,8 +103,7 @@ with gr.Blocks() as demo: | |
| 106 | 
             
                        submit_button = gr.Button("Submit")
         | 
| 107 |  | 
| 108 | 
             
                    with gr.Column():
         | 
| 109 | 
            -
                         | 
| 110 | 
            -
                        # ocr_result = gr.Textbox(label="GOT output")
         | 
| 111 | 
             
                        html_result = gr.HTML(label="rendered html")
         | 
| 112 |  | 
| 113 | 
             
                gr.Examples(
         | 
| @@ -121,7 +117,8 @@ with gr.Blocks() as demo: | |
| 121 | 
             
                        ["assets/color.png", "plain fine-grained OCR", "color", "red", ""],
         | 
| 122 | 
             
                    ],
         | 
| 123 | 
             
                    inputs=[image_input, task_dropdown, fine_grained_dropdown, color_dropdown, box_input],
         | 
| 124 | 
            -
                    outputs=[ | 
|  | |
| 125 | 
             
                    label="examples",
         | 
| 126 | 
             
                )
         | 
| 127 |  | 
| @@ -139,7 +136,7 @@ with gr.Blocks() as demo: | |
| 139 | 
             
                submit_button.click(
         | 
| 140 | 
             
                    run_GOT,
         | 
| 141 | 
             
                    inputs=[image_input, task_dropdown, box_input, color_dropdown],
         | 
| 142 | 
            -
                    outputs=[ | 
| 143 | 
             
                )
         | 
| 144 |  | 
| 145 | 
             
            demo.launch(share=True)
         | 
|  | |
| 10 |  | 
| 11 | 
             
            @spaces.GPU
         | 
| 12 | 
             
            def run_GOT(image_array, got_mode, ocr_box="", ocr_color=""):
         | 
|  | |
|  | |
|  | |
| 13 | 
             
                image = image_array
         | 
| 14 | 
             
                if got_mode == "plain texts OCR":
         | 
| 15 | 
            +
                    res = model.chat(tokenizer, image, ocr_type='ocr')
         | 
| 16 | 
             
                elif got_mode == "format texts OCR":
         | 
| 17 | 
             
                    res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
         | 
| 18 | 
             
                elif got_mode == "plain multi-crop OCR":
         | 
|  | |
| 28 | 
             
                if "format" in got_mode:
         | 
| 29 | 
             
                    with open('./demo.html', 'r') as f:
         | 
| 30 | 
             
                        demo_html = f.read()
         | 
| 31 | 
            +
                    return res, demo_html
         | 
| 32 | 
            +
                return res, None
         | 
| 33 |  | 
| 34 | 
             
            def task_update(task):
         | 
| 35 | 
             
                if "fine-grained" in task:
         | 
|  | |
| 103 | 
             
                        submit_button = gr.Button("Submit")
         | 
| 104 |  | 
| 105 | 
             
                    with gr.Column():
         | 
| 106 | 
            +
                        ocr_result = gr.Textbox(label="GOT output")
         | 
|  | |
| 107 | 
             
                        html_result = gr.HTML(label="rendered html")
         | 
| 108 |  | 
| 109 | 
             
                gr.Examples(
         | 
|  | |
| 117 | 
             
                        ["assets/color.png", "plain fine-grained OCR", "color", "red", ""],
         | 
| 118 | 
             
                    ],
         | 
| 119 | 
             
                    inputs=[image_input, task_dropdown, fine_grained_dropdown, color_dropdown, box_input],
         | 
| 120 | 
            +
                    outputs=[ocr_result, html_result],
         | 
| 121 | 
            +
                    fn = run_GOT,
         | 
| 122 | 
             
                    label="examples",
         | 
| 123 | 
             
                )
         | 
| 124 |  | 
|  | |
| 136 | 
             
                submit_button.click(
         | 
| 137 | 
             
                    run_GOT,
         | 
| 138 | 
             
                    inputs=[image_input, task_dropdown, box_input, color_dropdown],
         | 
| 139 | 
            +
                    outputs=[ocr_result, html_result]
         | 
| 140 | 
             
                )
         | 
| 141 |  | 
| 142 | 
             
            demo.launch(share=True)
         | 
