Fix Gradio compatibility issues
Browse files- app.py +7 -12
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
"""
|
| 2 |
-
ํ๊ตญ ๋ฒํธํ OCR -
|
| 3 |
Hugging Face Gradio App
|
| 4 |
"""
|
| 5 |
|
|
@@ -8,6 +8,7 @@ import torch
|
|
| 8 |
import torch.nn as nn
|
| 9 |
from PIL import Image
|
| 10 |
import torchvision.transforms as transforms
|
|
|
|
| 11 |
|
| 12 |
# ============================================================================
|
| 13 |
# ๋ชจ๋ธ ์ ์
|
|
@@ -84,10 +85,10 @@ def decode_predictions(outputs, itos, blank_idx=0):
|
|
| 84 |
# ============================================================================
|
| 85 |
def preprocess_image(image, img_height=32, max_width=200):
|
| 86 |
"""๋ฒํธํ ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ"""
|
| 87 |
-
# PIL Image๋ก ๋ณํ
|
| 88 |
-
if
|
| 89 |
-
image = Image.fromarray(image)
|
| 90 |
-
|
| 91 |
image = image.convert('L')
|
| 92 |
|
| 93 |
# ๋ฆฌ์ฌ์ด์ฆ (aspect ratio ์ ์ง)
|
|
@@ -156,7 +157,7 @@ def predict_license_plate(image):
|
|
| 156 |
# ============================================================================
|
| 157 |
demo = gr.Interface(
|
| 158 |
fn=predict_license_plate,
|
| 159 |
-
inputs=gr.Image(
|
| 160 |
outputs=gr.Textbox(label="์ธ์ ๊ฒฐ๊ณผ"),
|
| 161 |
title="๐ ํ๊ตญ ๋ฒํธํ OCR - KLPR v2",
|
| 162 |
description="""
|
|
@@ -171,13 +172,7 @@ demo = gr.Interface(
|
|
| 171 |
**์ฌ์ฉ ๋ฐฉ๋ฒ:**
|
| 172 |
1. ๋ฒํธํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์
|
| 173 |
2. ์๋์ผ๋ก ๋ฒํธํ ๋ฒํธ๊ฐ ์ธ์๋ฉ๋๋ค
|
| 174 |
-
|
| 175 |
-
**v2์ ํน์ง:**
|
| 176 |
-
- ๋ ๋ง์ ์ง์ญ๋ช
์ง์ (์ฐ, ์ , ์ธ, ์ข
, ํ)
|
| 177 |
-
- 18 epoch ํ๋ จ์ผ๋ก ๋ ์์ ์ ์ธ ํ์ต
|
| 178 |
""",
|
| 179 |
-
examples=None,
|
| 180 |
-
cache_examples=False,
|
| 181 |
)
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
|
|
|
| 1 |
"""
|
| 2 |
+
ํ๊ตญ ๋ฒํธํ OCR - KLPR_v1 (Model v5)
|
| 3 |
Hugging Face Gradio App
|
| 4 |
"""
|
| 5 |
|
|
|
|
| 8 |
import torch.nn as nn
|
| 9 |
from PIL import Image
|
| 10 |
import torchvision.transforms as transforms
|
| 11 |
+
import numpy as np
|
| 12 |
|
| 13 |
# ============================================================================
|
| 14 |
# ๋ชจ๋ธ ์ ์
|
|
|
|
| 85 |
# ============================================================================
|
| 86 |
def preprocess_image(image, img_height=32, max_width=200):
|
| 87 |
"""๋ฒํธํ ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ"""
|
| 88 |
+
# numpy array๋ฅผ PIL Image๋ก ๋ณํ
|
| 89 |
+
if isinstance(image, np.ndarray):
|
| 90 |
+
image = Image.fromarray(image.astype('uint8'))
|
| 91 |
+
|
| 92 |
image = image.convert('L')
|
| 93 |
|
| 94 |
# ๋ฆฌ์ฌ์ด์ฆ (aspect ratio ์ ์ง)
|
|
|
|
| 157 |
# ============================================================================
|
| 158 |
demo = gr.Interface(
|
| 159 |
fn=predict_license_plate,
|
| 160 |
+
inputs=gr.Image(),
|
| 161 |
outputs=gr.Textbox(label="์ธ์ ๊ฒฐ๊ณผ"),
|
| 162 |
title="๐ ํ๊ตญ ๋ฒํธํ OCR - KLPR v2",
|
| 163 |
description="""
|
|
|
|
| 172 |
**์ฌ์ฉ ๋ฐฉ๋ฒ:**
|
| 173 |
1. ๋ฒํธํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์
|
| 174 |
2. ์๋์ผ๋ก ๋ฒํธํ ๋ฒํธ๊ฐ ์ธ์๋ฉ๋๋ค
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
""",
|
|
|
|
|
|
|
| 176 |
)
|
| 177 |
|
| 178 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
|
|
| 1 |
torch
|
| 2 |
torchvision
|
| 3 |
-
gradio
|
| 4 |
Pillow
|
|
|
|
| 1 |
+
gradio==4.44.0
|
| 2 |
torch
|
| 3 |
torchvision
|
|
|
|
| 4 |
Pillow
|