Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(mes
|
|
20 |
FONT_PATH = os.path.join(os.path.dirname(__file__), "NanumGothicCoding.ttf")
|
21 |
MIN_FONT_SIZE = 8
|
22 |
|
23 |
-
|
24 |
def get_vision_client():
|
25 |
b64 = os.getenv("GCP_SERVICE_ACCOUNT_JSON")
|
26 |
if not b64:
|
@@ -37,7 +37,7 @@ def get_vision_client():
|
|
37 |
vision_client = get_vision_client()
|
38 |
checker = spell_init()
|
39 |
|
40 |
-
|
41 |
def normalize_text(text: str) -> str:
|
42 |
return unicodedata.normalize('NFC', text)
|
43 |
|
@@ -58,7 +58,7 @@ def preprocess_with_adaptive_threshold(img: Image.Image) -> Image.Image:
|
|
58 |
bgr = cv2.cvtColor(adap, cv2.COLOR_GRAY2BGR)
|
59 |
return Image.fromarray(cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB))
|
60 |
|
61 |
-
|
62 |
def ocr_overlay_and_correct_text(img: Image.Image):
|
63 |
corrected_text = ""
|
64 |
overlay = None
|
@@ -142,7 +142,7 @@ def ocr_overlay_and_correct_text(img: Image.Image):
|
|
142 |
|
143 |
return overlay, corrected_text
|
144 |
|
145 |
-
|
146 |
def text_correct_fn(text):
|
147 |
raw = normalize_text(text.strip())
|
148 |
corrected = checker(raw)
|
@@ -154,7 +154,7 @@ def img_correct_fn(blob):
|
|
154 |
img = Image.open(io.BytesIO(blob)).convert('RGB')
|
155 |
return ocr_overlay_and_correct_text(img)
|
156 |
|
157 |
-
|
158 |
with gr.Blocks(
|
159 |
css="""
|
160 |
.gradio-container {background-color: #fafaf5}
|
@@ -201,6 +201,6 @@ with gr.Blocks(
|
|
201 |
return None, gr.update(label="사진 촬영 및 업로드", interactive=True, value=None), '', gr.update(interactive=False), None, ''
|
202 |
clear_btn.click(on_clear, None, [state, upload, text_in, img_check_btn, img_out, txt_out])
|
203 |
|
204 |
-
|
205 |
if __name__ == '__main__':
|
206 |
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", 7860)))
|
|
|
20 |
FONT_PATH = os.path.join(os.path.dirname(__file__), "NanumGothicCoding.ttf")
|
21 |
MIN_FONT_SIZE = 8
|
22 |
|
23 |
+
|
24 |
def get_vision_client():
|
25 |
b64 = os.getenv("GCP_SERVICE_ACCOUNT_JSON")
|
26 |
if not b64:
|
|
|
37 |
vision_client = get_vision_client()
|
38 |
checker = spell_init()
|
39 |
|
40 |
+
|
41 |
def normalize_text(text: str) -> str:
|
42 |
return unicodedata.normalize('NFC', text)
|
43 |
|
|
|
58 |
bgr = cv2.cvtColor(adap, cv2.COLOR_GRAY2BGR)
|
59 |
return Image.fromarray(cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB))
|
60 |
|
61 |
+
|
62 |
def ocr_overlay_and_correct_text(img: Image.Image):
|
63 |
corrected_text = ""
|
64 |
overlay = None
|
|
|
142 |
|
143 |
return overlay, corrected_text
|
144 |
|
145 |
+
|
146 |
def text_correct_fn(text):
|
147 |
raw = normalize_text(text.strip())
|
148 |
corrected = checker(raw)
|
|
|
154 |
img = Image.open(io.BytesIO(blob)).convert('RGB')
|
155 |
return ocr_overlay_and_correct_text(img)
|
156 |
|
157 |
+
|
158 |
with gr.Blocks(
|
159 |
css="""
|
160 |
.gradio-container {background-color: #fafaf5}
|
|
|
201 |
return None, gr.update(label="사진 촬영 및 업로드", interactive=True, value=None), '', gr.update(interactive=False), None, ''
|
202 |
clear_btn.click(on_clear, None, [state, upload, text_in, img_check_btn, img_out, txt_out])
|
203 |
|
204 |
+
|
205 |
if __name__ == '__main__':
|
206 |
demo.launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", 7860)))
|