nice22090 commited on
Commit
f89b961
ยท
1 Parent(s): 53d6f75

Fix Gradio compatibility: use v4.44.1 with type='pil'

Browse files
Files changed (2) hide show
  1. app.py +7 -5
  2. 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
- # 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,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==3.50.2
2
- gradio-client==0.6.1
3
  torch
4
  torchvision
5
  Pillow
 
1
+ gradio==4.44.1
 
2
  torch
3
  torchvision
4
  Pillow