1{ lib
2, buildPythonPackage
3, fetchPypi
4, pythonOlder
5, pythonRelaxDepsHook
6
7# pyproject
8, hatchling
9, hatch-requirements-txt
10, hatch-fancy-pypi-readme
11
12# runtime
13, setuptools
14, aiofiles
15, altair
16, fastapi
17, ffmpy
18, gradio-client
19, httpx
20, huggingface-hub
21, importlib-resources
22, jinja2
23, markupsafe
24, matplotlib
25, numpy
26, orjson
27, packaging
28, pandas
29, pillow
30, pydantic
31, python-multipart
32, pydub
33, pyyaml
34, requests
35, semantic-version
36, typing-extensions
37, uvicorn
38, websockets
39
40# check
41, pytestCheckHook
42, boto3
43, ffmpeg
44, ipython
45, pytest-asyncio
46, respx
47, scikit-image
48, torch
49, tqdm
50, transformers
51, vega-datasets
52}:
53
54buildPythonPackage rec {
55 pname = "gradio";
56 version = "3.44.3";
57 format = "pyproject";
58
59 disabled = pythonOlder "3.7";
60
61 # We use the Pypi release, as it provides prebuilt webui assets,
62 # and has more frequent releases compared to github tags
63 src = fetchPypi {
64 inherit pname version;
65 hash = "sha256-3mXs9PwlzUo89VosBWtnsOzDQf/T22Yv7s5j6OLLp3M=";
66 };
67
68 # fix packaging.ParserSyntaxError, which can't handle comments
69 postPatch = ''
70 sed -ie "s/ #.*$//g" requirements*.txt
71 '';
72
73 nativeBuildInputs = [
74 pythonRelaxDepsHook
75 hatchling
76 hatch-requirements-txt
77 hatch-fancy-pypi-readme
78 ];
79
80 propagatedBuildInputs = [
81 setuptools # needed for 'pkg_resources'
82 aiofiles
83 altair
84 fastapi
85 ffmpy
86 gradio-client
87 httpx
88 huggingface-hub
89 importlib-resources
90 jinja2
91 markupsafe
92 matplotlib
93 numpy
94 orjson
95 packaging
96 pandas
97 pillow
98 pydantic
99 python-multipart
100 pydub
101 pyyaml
102 requests
103 semantic-version
104 typing-extensions
105 uvicorn
106 websockets
107 ];
108
109 nativeCheckInputs = [
110 pytestCheckHook
111 boto3
112 ffmpeg
113 ipython
114 pytest-asyncio
115 respx
116 scikit-image
117 # shap is needed as well, but breaks too often
118 torch
119 tqdm
120 transformers
121 vega-datasets
122 ];
123
124 # Add a pytest hook skipping tests that access network, marking them as "Expected fail" (xfail).
125 # We additionally xfail FileNotFoundError, since the gradio devs often fail to upload test assets to pypi.
126 preCheck = ''
127 export HOME=$TMPDIR
128 cat ${./conftest-skip-network-errors.py} >> test/conftest.py
129 '';
130
131 disabledTests = [
132 # Actually broken
133 "test_mount_gradio_app"
134
135 # requires network, it caught our xfail exception
136 "test_error_analytics_successful"
137
138 # Flaky, tries to pin dependency behaviour. Sensitive to dep versions
139 # These error only affect downstream use of the check dependencies.
140 "test_no_color"
141 "test_in_interface_as_output"
142 "test_should_warn_url_not_having_version"
143
144 # Flaky, unknown reason
145 "test_in_interface"
146
147 # shap is too often broken in nixpkgs
148 "test_shapley_text"
149 ];
150 disabledTestPaths = [
151 # makes pytest freeze 50% of the time
152 "test/test_interfaces.py"
153 ];
154 pytestFlagsArray = [
155 "-x" # abort on first failure
156 #"-m" "not flaky" # doesn't work, even when advertised
157 #"-W" "ignore" # uncomment for debugging help
158 ];
159
160 # check the binary works outside the build env
161 doInstallCheck = true;
162 postInstallCheck = ''
163 env --ignore-environment $out/bin/gradio environment >/dev/null
164 '';
165
166 pythonImportsCheck = [ "gradio" ];
167
168 meta = with lib; {
169 homepage = "https://www.gradio.app/";
170 description = "Python library for easily interacting with trained machine learning models";
171 license = licenses.asl20;
172 maintainers = with maintainers; [ pbsds ];
173 };
174}