This file contains 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 { BedrockChat } from "@langchain/community/chat_models/bedrock"; | |
import { StateGraph, END, START } from "@langchain/langgraph"; | |
import { | |
ChatPromptTemplate, | |
MessagesPlaceholder, | |
} from "@langchain/core/prompts"; | |
import { HumanMessage, AIMessage, ToolMessage } from "@langchain/core/messages"; | |
import { z } from "zod"; | |
import { MessagesAnnotation, Annotation } from "@langchain/langgraph"; | |
import { tool } from "@langchain/core/tools"; |
This file contains 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 enum import auto | |
from typing import List, Optional | |
from collections import Counter | |
from fastapi_utils.enums import StrEnum | |
from fastapi_utils.inferring_router import InferringRouter | |
from pydantic import BaseModel | |
from fastapi import HTTPException, Query, Depends | |
router = InferringRouter() |
This file contains 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
find . -regex '.*.py' -type f | sed "s/\.py$//" | xargs -I% mv -iv %.py %.txt |
This file contains 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
"""This module requires: | |
- poppler-utils [apt-get upde && apt-get install poppler-utils] | |
- pdf2image [pip install pdf2image] | |
- pillow [pip install pillow] | |
- boto3 [pip install boto3] | |
""" | |
import boto3 | |
from pdf2image import convert_from_bytes |
This file contains 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 boto3 | |
from PIL import Image | |
from io import BytesIO | |
import os | |
class S3ImagesInvalidExtension(Exception): | |
pass | |
class S3ImagesUploadFailed(Exception): | |
pass |
This file contains 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 PIL import Image | |
import numpy as np | |
import cv2 | |
import time | |
# Helper function for jupyter notebooks | |
def showarray(a): | |
return Image.fromarray(a) | |
def detect_boxes(img, min_percent_of_area=0.02, max_percent_of_area=2): |
This file contains 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 boto3 | |
import pandas as pd | |
from io import StringIO | |
class S3DataFrame(pd.DataFrame): | |
""" | |
# Make a dataframe and upload it as csv | |
s3df = S3DataFrame({'h1':[1], 'h2':[2]}) | |
s3df.to_s3(Bucket='bucket-name', |
This file contains 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
## Tesseract4 | |
# 2 images into tiff: 843 msec 796 | |
# 10 images into tiff: 1003 msec | |
# 53 images (same as page 1) into tiff: 1740 msec | |
## Tesseract3 | |
# 2 images into tiff: 727 msec | |
# 10 images into tiff: 816 msec | |
# 53 images (same as page 1) into tiff: 1620 msec |
This file contains 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 PIL import Image | |
from PIL.PngImagePlugin import PngInfo | |
im = Image.open('example.png') | |
im_info = PngInfo() | |
im_info.add_text('Key Information', 'Value Information') | |
im.save('example.png', pnginfo=im_info) |
This file contains 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 imageio | |
from typing import NamedTuple | |
import cv2 | |
import numpy as np | |
LabeledGIFState = NamedTuple('LabeledGIFState', [('image', np.ndarray), ('label', str)]) | |
class GifSettings(object): | |
red = [255, 0, 0] |
NewerOlder