nice22090 commited on
Commit
642943a
ยท
1 Parent(s): 8d3aba0

Fix Gradio compatibility issues

Browse files
Files changed (2) hide show
  1. app.py +7 -12
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,5 +1,5 @@
1
  """
2
- ํ•œ๊ตญ ๋ฒˆํ˜ธํŒ OCR - KLPR_v2 (Model v5)
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๋กœ ๋ณ€ํ™˜ (Gradio๊ฐ€ numpy array๋ฅผ ์ „๋‹ฌ)
88
- if not isinstance(image, Image.Image):
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(type="numpy", label="๋ฒˆํ˜ธํŒ ์ด๋ฏธ์ง€"),
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