sooooner commited on
Commit
5b80e47
Β·
1 Parent(s): 1a1cf19
Files changed (2) hide show
  1. app.py +1 -1
  2. utils.py +2 -5
app.py CHANGED
@@ -9,7 +9,7 @@ from utils import Image2Text
9
  @spaces.GPU(duration=15)
10
  def greet(input_img):
11
  global image_to_text
12
- contents = image_to_text.get_text([input_img], num_beams=4)
13
  return '\n'.join(contents)
14
 
15
  examples_path = os.path.dirname(__file__)
 
9
  @spaces.GPU(duration=15)
10
  def greet(input_img):
11
  global image_to_text
12
+ contents = image_to_text.get_text(input_img, num_beams=4)
13
  return '\n'.join(contents)
14
 
15
  examples_path = os.path.dirname(__file__)
utils.py CHANGED
@@ -51,11 +51,8 @@ class Image2Text:
51
  model.eval()
52
  return model, processor
53
 
54
- def load_img(self, img_path, width=480, height=480):
55
- if type(img_path) == np.ndarray:
56
- image = Image.fromarray(img_path)
57
- else:
58
- image = Image.open(img_path)
59
  image = aspect_ratio_preserving_resize_and_crop(image, target_width=width, target_height=height).convert("RGB")
60
  img = self.processor(image , return_tensors="pt", size=(width, height)).pixel_values
61
  pixel_values = img.to(self.device)
 
51
  model.eval()
52
  return model, processor
53
 
54
+ def load_img(self, inputs, width=480, height=480):
55
+ image = Image.fromarray(inputs)
 
 
 
56
  image = aspect_ratio_preserving_resize_and_crop(image, target_width=width, target_height=height).convert("RGB")
57
  img = self.processor(image , return_tensors="pt", size=(width, height)).pixel_values
58
  pixel_values = img.to(self.device)