Fix Gradio compatibility: use v4.44.1 with type='pil'
Browse files- app.py +7 -5
- requirements.txt +1 -2
app.py
CHANGED
|
@@ -85,10 +85,11 @@ def decode_predictions(outputs, itos, blank_idx=0):
|
|
| 85 |
# ============================================================================
|
| 86 |
def preprocess_image(image, img_height=32, max_width=200):
|
| 87 |
"""๋ฒํธํ ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ"""
|
| 88 |
-
#
|
| 89 |
-
if isinstance(image,
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 92 |
image = image.convert('L')
|
| 93 |
|
| 94 |
# ๋ฆฌ์ฌ์ด์ฆ (aspect ratio ์ ์ง)
|
|
@@ -157,7 +158,7 @@ def predict_license_plate(image):
|
|
| 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="""
|
|
@@ -173,6 +174,7 @@ demo = gr.Interface(
|
|
| 173 |
1. ๋ฒํธํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์
|
| 174 |
2. ์๋์ผ๋ก ๋ฒํธํ ๋ฒํธ๊ฐ ์ธ์๋ฉ๋๋ค
|
| 175 |
""",
|
|
|
|
| 176 |
)
|
| 177 |
|
| 178 |
if __name__ == "__main__":
|
|
|
|
| 85 |
# ============================================================================
|
| 86 |
def preprocess_image(image, img_height=32, max_width=200):
|
| 87 |
"""๋ฒํธํ ์ด๋ฏธ์ง ์ ์ฒ๋ฆฌ"""
|
| 88 |
+
# PIL Image๋ก ๋ณํ (Gradio 4.x์์ type="pil"๋ก ์ด๋ฏธ PIL Image)
|
| 89 |
+
if not isinstance(image, Image.Image):
|
| 90 |
+
if isinstance(image, np.ndarray):
|
| 91 |
+
image = Image.fromarray(image.astype('uint8'))
|
| 92 |
+
|
| 93 |
image = image.convert('L')
|
| 94 |
|
| 95 |
# ๋ฆฌ์ฌ์ด์ฆ (aspect ratio ์ ์ง)
|
|
|
|
| 158 |
# ============================================================================
|
| 159 |
demo = gr.Interface(
|
| 160 |
fn=predict_license_plate,
|
| 161 |
+
inputs=gr.Image(type="pil", label="๋ฒํธํ ์ด๋ฏธ์ง"),
|
| 162 |
outputs=gr.Textbox(label="์ธ์ ๊ฒฐ๊ณผ"),
|
| 163 |
title="๐ ํ๊ตญ ๋ฒํธํ OCR - KLPR v2",
|
| 164 |
description="""
|
|
|
|
| 174 |
1. ๋ฒํธํ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ธ์
|
| 175 |
2. ์๋์ผ๋ก ๋ฒํธํ ๋ฒํธ๊ฐ ์ธ์๋ฉ๋๋ค
|
| 176 |
""",
|
| 177 |
+
api_name="predict"
|
| 178 |
)
|
| 179 |
|
| 180 |
if __name__ == "__main__":
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
gradio==
|
| 2 |
-
gradio-client==0.6.1
|
| 3 |
torch
|
| 4 |
torchvision
|
| 5 |
Pillow
|
|
|
|
| 1 |
+
gradio==4.44.1
|
|
|
|
| 2 |
torch
|
| 3 |
torchvision
|
| 4 |
Pillow
|