Skip to content

Instantly share code, notes, and snippets.

View JoshuaPurtell's full-sized avatar
💭
Working

Josh Purtell JoshuaPurtell

💭
Working
View GitHub Profile
from pydantic import BaseModel
from typing import List
import anthropic
import instructor
import asyncio
# Patching the Anthropics client with the instructor for enhanced capabilities
anthropic_client = instructor.patch(
create=anthropic.AsyncAnthropic().messages.create,
mode=instructor.Mode.ANTHROPIC_TOOLS
import asyncio
import copy
import hashlib
import json
import os
import random
from dataclasses import dataclass
from typing import Any, Dict, List, Optional
import numpy as np
from pdf2image import convert_from_bytes
from transformers import NougatImageProcessor, NougatTokenizerFast
from transformers.models.vision_encoder_decoder import VisionEncoderDecoderModel
MODEL_ID = "facebook/nougat-small"
def first_page_to_title_and_authors(file):
tokenizer = NougatTokenizerFast.from_pretrained(MODEL_ID)
processor = NougatImageProcessor.from_pretrained(MODEL_ID)
model = VisionEncoderDecoderModel.from_pretrained(MODEL_ID)
file_bytes = file.read()
first_page = convert_from_bytes(file_bytes)[0]