sh install-docker.sh
- log out
- log back in
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 os | |
def listdirs(path='./', filetype='.*'): | |
""" List all files in directory. """ | |
output = [] | |
for root, dirs, files in os.walk(path): | |
for file in files: | |
if filetype in ['.*', '*']: |
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_path | |
from PyPDF2 import PdfFileReader | |
def pdf_to_image(file: str, page_num=0, output_file=None) -> Image: | |
""" Convert a PDF to a PIL Image. """ | |
pdf_page = PdfFileReader(open(file, 'rb')).getPage(page_num) | |
pdf_shape = pdf_page.mediaBox | |
pdf_height = pdf_shape[3] - pdf_shape[1] | |
pdf_width = pdf_shape[2] - pdf_shape[0] |
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
# Uses python3 | |
import sys | |
from typing import List | |
def calc_fib(n): | |
if n == 1 or n == 2: | |
return 1 | |
elif n == 0: | |
return 0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 os | |
from typing import List, Union | |
def listdirs(path, extensions: Union[List[str], str] = None): | |
""" List all files in directory (including walking all subdirectories). | |
Can filter by file extension by providing either, for example: | |
extensions='png' | |
extensions=['png', 'jpeg'] |
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
# TODO: Add this to PR for Langchain so that it will be easy to use across all our different LLM projects | |
import re | |
import time | |
import warnings | |
from pathlib import Path | |
from typing import List, Union, Optional | |
import requests | |
from tqdm import tqdm | |
from pydantic import BaseModel, Field, field_validator, computed_field |
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
""" | |
# See https://huggingface.co/intfloat/e5-mistral-7b-instruct for model inference code | |
## Quickstart | |
Install requirements | |
```bash | |
pip install fastapi uvicorn torch transformers | |
``` |
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 typing as t | |
import jsonlines | |
from langchain.schema import Document | |
def save_docs_to_jsonl(documents: t.Iterable[Document], file_path: str) -> None: | |
with jsonlines.open(file_path, mode="w") as writer: | |
for doc in documents: | |
writer.write(doc.dict()) |
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
# For directory | |
du -h ./ | sort -hr | head -n 10 | |
# For the largest files within a given directory and its subdirectories | |
find ./ -type f -exec du -h {} + | sort -hr | head -n 10 | |
# Find venv/.venv folders (limit recursive lookup to 4) | |
find ~/ -maxdepth 4 -type d \( -name ".venv" -o -name "venv" \) 2>/dev/null |