Spaces:
Runtime error
Runtime error
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(
|
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,
|
55 |
-
|
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)
|