Upload text_detection/app.py with huggingface_hub
Browse files- text_detection/app.py +35 -0
text_detection/app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from imgutils.detect import detection_visualize
|
| 5 |
+
|
| 6 |
+
from detect import _ALL_MODELS, _DEFAULT_MODEL, detect_text
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _gr_detect_text(image, model: str, threshold: float):
|
| 10 |
+
return detection_visualize(image, detect_text(image, model, threshold))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
if __name__ == '__main__':
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
with gr.Row():
|
| 16 |
+
with gr.Column():
|
| 17 |
+
gr_face_input_image = gr.Image(type='pil', label='Original Image')
|
| 18 |
+
gr_face_model = gr.Dropdown(_ALL_MODELS, value=_DEFAULT_MODEL, label='Model')
|
| 19 |
+
with gr.Row():
|
| 20 |
+
gr_face_score_threshold = gr.Slider(0.0, 1.0, 0.05, label='Score Threshold')
|
| 21 |
+
|
| 22 |
+
gr_face_submit = gr.Button(value='Submit', variant='primary')
|
| 23 |
+
|
| 24 |
+
with gr.Column():
|
| 25 |
+
gr_face_output_image = gr.Image(type='pil', label="Labeled")
|
| 26 |
+
|
| 27 |
+
gr_face_submit.click(
|
| 28 |
+
_gr_detect_text,
|
| 29 |
+
inputs=[
|
| 30 |
+
gr_face_input_image, gr_face_model, gr_face_score_threshold,
|
| 31 |
+
],
|
| 32 |
+
outputs=[gr_face_output_image],
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
demo.queue(os.cpu_count()).launch()
|