Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
@@ -27,9 +27,9 @@ def ocr_function(img, lang_name):
|
|
27 |
# Assuming predictions is a list of dictionaries, one per image
|
28 |
if predictions:
|
29 |
img_with_text = draw_polys_on_image(predictions[0]["polys"], img)
|
30 |
-
return img_with_text, predictions[0]
|
31 |
else:
|
32 |
-
return img,
|
33 |
|
34 |
def text_line_detection_function(img):
|
35 |
preds = batch_detection([img], det_model, det_processor)[0]
|
@@ -37,7 +37,7 @@ def text_line_detection_function(img):
|
|
37 |
return img_with_lines, preds
|
38 |
|
39 |
with gr.Blocks() as app:
|
40 |
-
gr.Markdown("# Surya OCR
|
41 |
with gr.Tab("OCR"):
|
42 |
with gr.Column():
|
43 |
ocr_input_image = gr.Image(label="Input Image for OCR", type="pil")
|
@@ -48,18 +48,18 @@ with gr.Blocks() as app:
|
|
48 |
ocr_text_output = gr.TextArea(label="Recognized Text")
|
49 |
|
50 |
# Pass the input image and the language name to the ocr_function
|
51 |
-
ocr_run_button.click(fn=ocr_function, inputs=[ocr_input_image, ocr_language_selector
|
52 |
|
53 |
-
|
54 |
-
with gr.Tab("Detecção de Linhas de Texto"):
|
55 |
with gr.Column():
|
56 |
-
detection_input_image = gr.Image(label="
|
57 |
-
detection_run_button = gr.Button("
|
58 |
with gr.Column():
|
59 |
-
detection_output_image = gr.Image(label="
|
60 |
-
detection_json_output = gr.JSON(label="
|
61 |
|
|
|
62 |
detection_run_button.click(fn=text_line_detection_function, inputs=detection_input_image, outputs=[detection_output_image, detection_json_output])
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
-
app.launch()
|
|
|
27 |
# Assuming predictions is a list of dictionaries, one per image
|
28 |
if predictions:
|
29 |
img_with_text = draw_polys_on_image(predictions[0]["polys"], img)
|
30 |
+
return img_with_text, predictions[0]["text"]
|
31 |
else:
|
32 |
+
return img, "No text detected"
|
33 |
|
34 |
def text_line_detection_function(img):
|
35 |
preds = batch_detection([img], det_model, det_processor)[0]
|
|
|
37 |
return img_with_lines, preds
|
38 |
|
39 |
with gr.Blocks() as app:
|
40 |
+
gr.Markdown("# Surya OCR and Text Line Detection")
|
41 |
with gr.Tab("OCR"):
|
42 |
with gr.Column():
|
43 |
ocr_input_image = gr.Image(label="Input Image for OCR", type="pil")
|
|
|
48 |
ocr_text_output = gr.TextArea(label="Recognized Text")
|
49 |
|
50 |
# Pass the input image and the language name to the ocr_function
|
51 |
+
ocr_run_button.click(fn=ocr_function, inputs=[ocr_input_image, ocr_language_selector], outputs=[ocr_output_image, ocr_text_output])
|
52 |
|
53 |
+
with gr.Tab("Text Line Detection"):
|
|
|
54 |
with gr.Column():
|
55 |
+
detection_input_image = gr.Image(label="Input Image for Detection", type="pil")
|
56 |
+
detection_run_button = gr.Button("Run Text Line Detection")
|
57 |
with gr.Column():
|
58 |
+
detection_output_image = gr.Image(label="Detection Output Image", type="pil", interactive=False)
|
59 |
+
detection_json_output = gr.JSON(label="Detection JSON Output")
|
60 |
|
61 |
+
# Pass the input image to the text_line_detection_function
|
62 |
detection_run_button.click(fn=text_line_detection_function, inputs=detection_input_image, outputs=[detection_output_image, detection_json_output])
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
+
app.launch()
|