Skip to content

Commit

Permalink
nougat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegomez committed Nov 24, 2023
1 parent d88a31a commit ee1ac00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion playground/models/nougat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

nougat = Nougat()

out = nougat("path/to/image.png")
out = nougat("large.png")
18 changes: 11 additions & 7 deletions swarms/models/nougat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Nougat:
"""
Nougat
ArgsS:
Args:
model_name_or_path: str, default="facebook/nougat-base"
min_length: int, default=1
max_new_tokens: int, default=30
Expand All @@ -35,7 +35,7 @@ def __init__(
self,
model_name_or_path="facebook/nougat-base",
min_length: int = 1,
max_new_tokens: int = 30,
max_new_tokens: int = 5000,
):
self.model_name_or_path = model_name_or_path
self.min_length = min_length
Expand All @@ -50,14 +50,17 @@ def __init__(
self.device = "cuda" if torch.cuda.is_available() else "cpu"
self.model.to(self.device)

def get_image(self, img_path: str):
def get_image(self, img: str):
"""Get an image from a path"""
image = Image.open(img_path)
return image
img = Image.open(img)

def __call__(self, img_path: str):
if img.mode == "L":
img = img.convert("RGB")
return img

def __call__(self, img: str):
"""Call the model with an image_path str as an input"""
image = Image.open(img_path)
image = Image.open(img)
pixel_values = self.processor(image, return_tensors="pt").pixel_values

# Generate transcriptions, here we only generate 30 tokens
Expand All @@ -78,6 +81,7 @@ def __call__(self, img_path: str):
return out

def clean_nougat_output(raw_output):
"""Clean the output from nougat to be more readable"""
# Define the pattern to extract the relevant data
daily_balance_pattern = (
r"\*\*(\d{2}/\d{2}/\d{4})\*\*\n\n\*\*([\d,]+\.\d{2})\*\*"
Expand Down

0 comments on commit ee1ac00

Please sign in to comment.