Spaces:
Sleeping
Sleeping
Commit
·
8fdd4b0
1
Parent(s):
537e574
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from PIL import Image
|
2 |
+
import easyocr
|
3 |
+
import gradio as gr
|
4 |
+
import json
|
5 |
+
|
6 |
+
reader = easyocr.Reader(['ko'], gpu=False)
|
7 |
+
|
8 |
+
|
9 |
+
def image_captioning(img, threshold='0.6'):
|
10 |
+
text_bboxes = reader.readtext(img, paragraph=False)
|
11 |
+
confident_text_bboxes = []
|
12 |
+
for text_bbox in text_bboxes:
|
13 |
+
if text_bbox[2] > float(threshold):
|
14 |
+
confident_text_bboxes.append(text_bbox[1])
|
15 |
+
|
16 |
+
print(confident_text_bboxes)
|
17 |
+
return json.dumps(confident_text_bboxes, indent=4, ensure_ascii=False)
|
18 |
+
|
19 |
+
|
20 |
+
demo = gr.Interface(fn=image_captioning, inputs=["image", "text"], outputs="text")
|
21 |
+
demo.queue(concurrency_count=3, api_open=True)
|
22 |
+
demo.launch(share=True)
|