about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/unstructured-api/default.nix
blob: 117af0ec816de5b10f7097fc9a88cae4710c017f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{
  lib,
  stdenvNoCC,
  fetchFromGitHub,
  python3,
  makeWrapper,
  nix-update-script,
  symlinkJoin,
  nltk-data,
}:
let
  pythonEnv = python3.withPackages (packages: with packages; [
    unstructured-api-tools
    unstructured
    pydantic
    click
    ratelimit
    requests
    pypdf
    pycryptodome
    safetensors
    uvicorn
  ] ++ packages.unstructured.optional-dependencies.local-inference);
  version = "0.0.42";
  unstructured_api_nltk_data = symlinkJoin {
    name = "unstructured_api_nltk_data";

    paths = [ nltk-data.punkt nltk-data.averaged_perceptron_tagger ];
  };
in stdenvNoCC.mkDerivation {
  pname = "unstructured-api";
  inherit version;

  src = fetchFromGitHub {
    owner = "Unstructured-IO";
    repo = "unstructured-api";
    rev = version;
    hash = "sha256-Tn4o7gAIlvWUTbAmbTCF9LgMk0up16iWuNPTy6pxOuk=";
  };

  nativeBuildInputs = [ makeWrapper ];

  installPhase = ''
    runHook preInstall

    mkdir -p $out $out/bin $out/lib
    cp -r . $out/lib

    makeWrapper ${pythonEnv}/bin/uvicorn $out/bin/unstructured-api \
      --set NLTK_DATA ${unstructured_api_nltk_data} \
      --prefix PYTHONPATH : $out/lib \
      --add-flags "prepline_general.api.app:app"

    runHook postInstall
  '';

  passthru = {
    updateScript = nix-update-script { };
  };

  meta = with lib; {
    description = "open-source toolkit designed to make it easy to prepare unstructured data like PDFs, HTML and Word Documents for downstream data science tasks";
    homepage = "https://github.com/Unstructured-IO/unstructured-api";
    changelog = "https://github.com/Unstructured-IO/unstructured-api/releases/tag/${version}";
    license = licenses.asl20;
    maintainers = with maintainers; [ happysalada ];
  };
}