This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import os | |
import random | |
import hashlib | |
from datetime import datetime | |
from typing import Dict, List, Type | |
from dotenv import load_dotenv | |
from loguru import logger | |
from pydantic import BaseModel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |