hysts HF staff commited on
Commit
6490ee4
·
1 Parent(s): db8a78a
.pre-commit-config.yaml CHANGED
@@ -1,6 +1,6 @@
1
  repos:
2
  - repo: https://github.com/pre-commit/pre-commit-hooks
3
- rev: v4.6.0
4
  hooks:
5
  - id: check-executables-have-shebangs
6
  - id: check-json
@@ -18,13 +18,15 @@ repos:
18
  hooks:
19
  - id: docformatter
20
  args: ["--in-place"]
21
- - repo: https://github.com/pycqa/isort
22
- rev: 5.13.2
23
  hooks:
24
- - id: isort
25
- args: ["--profile", "black"]
 
 
26
  - repo: https://github.com/pre-commit/mirrors-mypy
27
- rev: v1.9.0
28
  hooks:
29
  - id: mypy
30
  args: ["--ignore-missing-imports"]
@@ -35,14 +37,8 @@ repos:
35
  "types-PyYAML",
36
  "types-pytz",
37
  ]
38
- - repo: https://github.com/psf/black
39
- rev: 24.4.0
40
- hooks:
41
- - id: black
42
- language_version: python3.10
43
- args: ["--line-length", "119"]
44
  - repo: https://github.com/kynan/nbstripout
45
- rev: 0.7.1
46
  hooks:
47
  - id: nbstripout
48
  args:
@@ -51,7 +47,7 @@ repos:
51
  "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
52
  ]
53
  - repo: https://github.com/nbQA-dev/nbQA
54
- rev: 1.8.5
55
  hooks:
56
  - id: nbqa-black
57
  - id: nbqa-pyupgrade
 
1
  repos:
2
  - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
  hooks:
5
  - id: check-executables-have-shebangs
6
  - id: check-json
 
18
  hooks:
19
  - id: docformatter
20
  args: ["--in-place"]
21
+ - repo: https://github.com/astral-sh/ruff-pre-commit
22
+ rev: v0.8.4
23
  hooks:
24
+ - id: ruff
25
+ args: ["--fix"]
26
+ - id: ruff-format
27
+ args: ["--line-length", "119"]
28
  - repo: https://github.com/pre-commit/mirrors-mypy
29
+ rev: v1.14.0
30
  hooks:
31
  - id: mypy
32
  args: ["--ignore-missing-imports"]
 
37
  "types-PyYAML",
38
  "types-pytz",
39
  ]
 
 
 
 
 
 
40
  - repo: https://github.com/kynan/nbstripout
41
+ rev: 0.8.1
42
  hooks:
43
  - id: nbstripout
44
  args:
 
47
  "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
48
  ]
49
  - repo: https://github.com/nbQA-dev/nbQA
50
+ rev: 1.9.1
51
  hooks:
52
  - id: nbqa-black
53
  - id: nbqa-pyupgrade
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.10
.vscode/extensions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "recommendations": [
3
+ "ms-python.python",
4
+ "charliermarsh.ruff",
5
+ "streetsidesoftware.code-spell-checker",
6
+ "tamasfe.even-better-toml"
7
+ ]
8
+ }
.vscode/settings.json CHANGED
@@ -2,29 +2,20 @@
2
  "editor.formatOnSave": true,
3
  "files.insertFinalNewline": false,
4
  "[python]": {
5
- "editor.defaultFormatter": "ms-python.black-formatter",
6
  "editor.formatOnType": true,
7
  "editor.codeActionsOnSave": {
 
8
  "source.organizeImports": "explicit"
9
  }
10
  },
11
  "[jupyter]": {
12
  "files.insertFinalNewline": false
13
  },
14
- "black-formatter.args": [
15
- "--line-length=119"
16
- ],
17
- "isort.args": ["--profile", "black"],
18
- "flake8.args": [
19
- "--max-line-length=119"
20
- ],
21
- "ruff.lint.args": [
22
- "--line-length=119"
23
- ],
24
  "notebook.output.scrolling": true,
25
  "notebook.formatOnCellExecution": true,
26
  "notebook.formatOnSave.enabled": true,
27
- "notebook.codeActionsOnSave": {
28
- "source.organizeImports": "explicit"
29
- }
30
  }
 
2
  "editor.formatOnSave": true,
3
  "files.insertFinalNewline": false,
4
  "[python]": {
5
+ "editor.defaultFormatter": "charliermarsh.ruff",
6
  "editor.formatOnType": true,
7
  "editor.codeActionsOnSave": {
8
+ "source.fixAll.ruff": "explicit",
9
  "source.organizeImports": "explicit"
10
  }
11
  },
12
  "[jupyter]": {
13
  "files.insertFinalNewline": false
14
  },
 
 
 
 
 
 
 
 
 
 
15
  "notebook.output.scrolling": true,
16
  "notebook.formatOnCellExecution": true,
17
  "notebook.formatOnSave.enabled": true,
18
+ "notebook.codeActionsOnSave": {
19
+ "source.organizeImports": "explicit"
20
+ }
21
  }
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: ⚡
4
  colorFrom: red
5
  colorTo: purple
6
  sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: red
5
  colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -1,7 +1,5 @@
1
  #!/usr/bin/env python
2
 
3
- from __future__ import annotations
4
-
5
  import gradio as gr
6
  import PIL.Image
7
  import spaces
@@ -21,11 +19,10 @@ model = BlipForConditionalGeneration.from_pretrained(model_id).to(device)
21
  def run(image: PIL.Image.Image, text: str = "A picture of") -> str:
22
  inputs = processor(images=image, text=text, return_tensors="pt").to(device)
23
  generated_ids = model.generate(pixel_values=inputs.pixel_values, num_beams=3, max_length=20, min_length=5)
24
- generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
25
- return generated_caption
26
 
27
 
28
- with gr.Blocks(css="style.css") as demo:
29
  gr.Markdown(DESCRIPTION)
30
  input_image = gr.Image(type="pil")
31
  text = gr.Textbox(label="Text", value="A picture of")
 
1
  #!/usr/bin/env python
2
 
 
 
3
  import gradio as gr
4
  import PIL.Image
5
  import spaces
 
19
  def run(image: PIL.Image.Image, text: str = "A picture of") -> str:
20
  inputs = processor(images=image, text=text, return_tensors="pt").to(device)
21
  generated_ids = model.generate(pixel_values=inputs.pixel_values, num_beams=3, max_length=20, min_length=5)
22
+ return processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
 
23
 
24
 
25
+ with gr.Blocks(css_paths="style.css") as demo:
26
  gr.Markdown(DESCRIPTION)
27
  input_image = gr.Image(type="pil")
28
  text = gr.Textbox(label="Text", value="A picture of")
pyproject.toml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "image-captioning-with-blip"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "gradio>=5.9.1",
9
+ "hf-transfer>=0.1.8",
10
+ "spaces>=0.31.1",
11
+ "torch==2.4.0",
12
+ "torchvision>=0.19.0",
13
+ "transformers>=4.47.1",
14
+ ]
15
+
16
+ [tool.ruff]
17
+ line-length = 119
18
+
19
+ [tool.ruff.lint]
20
+ select = ["ALL"]
21
+ ignore = [
22
+ "COM812", # missing-trailing-comma
23
+ "D203", # one-blank-line-before-class
24
+ "D213", # multi-line-summary-second-line
25
+ "E501", # line-too-long
26
+ "SIM117", # multiple-with-statements
27
+ ]
28
+ extend-ignore = [
29
+ "D100", # undocumented-public-module
30
+ "D101", # undocumented-public-class
31
+ "D102", # undocumented-public-method
32
+ "D103", # undocumented-public-function
33
+ "D104", # undocumented-public-package
34
+ "D105", # undocumented-magic-method
35
+ "D107", # undocumented-public-init
36
+ "EM101", # raw-string-in-exception
37
+ "FBT001", # boolean-type-hint-positional-argument
38
+ "FBT002", # boolean-default-value-positional-argument
39
+ "PD901", # pandas-df-variable-name
40
+ "PGH003", # blanket-type-ignore
41
+ "PLR0913", # too-many-arguments
42
+ "PLR0915", # too-many-statements
43
+ "TRY003", # raise-vanilla-args
44
+ ]
45
+ unfixable = [
46
+ "F401", # unused-import
47
+ ]
48
+
49
+ [tool.ruff.format]
50
+ docstring-code-format = true
requirements.txt CHANGED
@@ -1,6 +1,235 @@
1
- gradio==4.36.1
2
- Pillow==10.3.0
3
- spaces==0.28.3
4
- torch==2.0.1
5
- torchvision==0.15.2
6
- transformers==4.41.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ aiofiles==23.2.1
4
+ # via gradio
5
+ annotated-types==0.7.0
6
+ # via pydantic
7
+ anyio==4.7.0
8
+ # via
9
+ # gradio
10
+ # httpx
11
+ # starlette
12
+ certifi==2024.12.14
13
+ # via
14
+ # httpcore
15
+ # httpx
16
+ # requests
17
+ charset-normalizer==3.4.1
18
+ # via requests
19
+ click==8.1.8
20
+ # via
21
+ # typer
22
+ # uvicorn
23
+ exceptiongroup==1.2.2
24
+ # via anyio
25
+ fastapi==0.115.6
26
+ # via gradio
27
+ ffmpy==0.5.0
28
+ # via gradio
29
+ filelock==3.16.1
30
+ # via
31
+ # huggingface-hub
32
+ # torch
33
+ # transformers
34
+ # triton
35
+ fsspec==2024.12.0
36
+ # via
37
+ # gradio-client
38
+ # huggingface-hub
39
+ # torch
40
+ gradio==5.9.1
41
+ # via
42
+ # image-captioning-with-blip (pyproject.toml)
43
+ # spaces
44
+ gradio-client==1.5.2
45
+ # via gradio
46
+ h11==0.14.0
47
+ # via
48
+ # httpcore
49
+ # uvicorn
50
+ hf-transfer==0.1.8
51
+ # via image-captioning-with-blip (pyproject.toml)
52
+ httpcore==1.0.7
53
+ # via httpx
54
+ httpx==0.28.1
55
+ # via
56
+ # gradio
57
+ # gradio-client
58
+ # safehttpx
59
+ # spaces
60
+ huggingface-hub==0.27.0
61
+ # via
62
+ # gradio
63
+ # gradio-client
64
+ # tokenizers
65
+ # transformers
66
+ idna==3.10
67
+ # via
68
+ # anyio
69
+ # httpx
70
+ # requests
71
+ jinja2==3.1.5
72
+ # via
73
+ # gradio
74
+ # torch
75
+ markdown-it-py==3.0.0
76
+ # via rich
77
+ markupsafe==2.1.5
78
+ # via
79
+ # gradio
80
+ # jinja2
81
+ mdurl==0.1.2
82
+ # via markdown-it-py
83
+ mpmath==1.3.0
84
+ # via sympy
85
+ networkx==3.4.2
86
+ # via torch
87
+ numpy==2.2.1
88
+ # via
89
+ # gradio
90
+ # pandas
91
+ # torchvision
92
+ # transformers
93
+ nvidia-cublas-cu12==12.1.3.1
94
+ # via
95
+ # nvidia-cudnn-cu12
96
+ # nvidia-cusolver-cu12
97
+ # torch
98
+ nvidia-cuda-cupti-cu12==12.1.105
99
+ # via torch
100
+ nvidia-cuda-nvrtc-cu12==12.1.105
101
+ # via torch
102
+ nvidia-cuda-runtime-cu12==12.1.105
103
+ # via torch
104
+ nvidia-cudnn-cu12==9.1.0.70
105
+ # via torch
106
+ nvidia-cufft-cu12==11.0.2.54
107
+ # via torch
108
+ nvidia-curand-cu12==10.3.2.106
109
+ # via torch
110
+ nvidia-cusolver-cu12==11.4.5.107
111
+ # via torch
112
+ nvidia-cusparse-cu12==12.1.0.106
113
+ # via
114
+ # nvidia-cusolver-cu12
115
+ # torch
116
+ nvidia-nccl-cu12==2.20.5
117
+ # via torch
118
+ nvidia-nvjitlink-cu12==12.6.85
119
+ # via
120
+ # nvidia-cusolver-cu12
121
+ # nvidia-cusparse-cu12
122
+ nvidia-nvtx-cu12==12.1.105
123
+ # via torch
124
+ orjson==3.10.13
125
+ # via gradio
126
+ packaging==24.2
127
+ # via
128
+ # gradio
129
+ # gradio-client
130
+ # huggingface-hub
131
+ # spaces
132
+ # transformers
133
+ pandas==2.2.3
134
+ # via gradio
135
+ pillow==11.0.0
136
+ # via
137
+ # gradio
138
+ # torchvision
139
+ psutil==5.9.8
140
+ # via spaces
141
+ pydantic==2.10.4
142
+ # via
143
+ # fastapi
144
+ # gradio
145
+ # spaces
146
+ pydantic-core==2.27.2
147
+ # via pydantic
148
+ pydub==0.25.1
149
+ # via gradio
150
+ pygments==2.18.0
151
+ # via rich
152
+ python-dateutil==2.9.0.post0
153
+ # via pandas
154
+ python-multipart==0.0.20
155
+ # via gradio
156
+ pytz==2024.2
157
+ # via pandas
158
+ pyyaml==6.0.2
159
+ # via
160
+ # gradio
161
+ # huggingface-hub
162
+ # transformers
163
+ regex==2024.11.6
164
+ # via transformers
165
+ requests==2.32.3
166
+ # via
167
+ # huggingface-hub
168
+ # spaces
169
+ # transformers
170
+ rich==13.9.4
171
+ # via typer
172
+ ruff==0.8.4
173
+ # via gradio
174
+ safehttpx==0.1.6
175
+ # via gradio
176
+ safetensors==0.4.5
177
+ # via transformers
178
+ semantic-version==2.10.0
179
+ # via gradio
180
+ shellingham==1.5.4
181
+ # via typer
182
+ six==1.17.0
183
+ # via python-dateutil
184
+ sniffio==1.3.1
185
+ # via anyio
186
+ spaces==0.31.1
187
+ # via image-captioning-with-blip (pyproject.toml)
188
+ starlette==0.41.3
189
+ # via
190
+ # fastapi
191
+ # gradio
192
+ sympy==1.13.3
193
+ # via torch
194
+ tokenizers==0.21.0
195
+ # via transformers
196
+ tomlkit==0.13.2
197
+ # via gradio
198
+ torch==2.4.0
199
+ # via
200
+ # image-captioning-with-blip (pyproject.toml)
201
+ # torchvision
202
+ torchvision==0.19.0
203
+ # via image-captioning-with-blip (pyproject.toml)
204
+ tqdm==4.67.1
205
+ # via
206
+ # huggingface-hub
207
+ # transformers
208
+ transformers==4.47.1
209
+ # via image-captioning-with-blip (pyproject.toml)
210
+ triton==3.0.0
211
+ # via torch
212
+ typer==0.15.1
213
+ # via gradio
214
+ typing-extensions==4.12.2
215
+ # via
216
+ # anyio
217
+ # fastapi
218
+ # gradio
219
+ # gradio-client
220
+ # huggingface-hub
221
+ # pydantic
222
+ # pydantic-core
223
+ # rich
224
+ # spaces
225
+ # torch
226
+ # typer
227
+ # uvicorn
228
+ tzdata==2024.2
229
+ # via pandas
230
+ urllib3==2.3.0
231
+ # via requests
232
+ uvicorn==0.34.0
233
+ # via gradio
234
+ websockets==14.1
235
+ # via gradio-client
style.css CHANGED
@@ -9,9 +9,3 @@ h1 {
9
  background: #1565c0;
10
  border-radius: 100vh;
11
  }
12
-
13
- .contain {
14
- width: 730px;
15
- margin: auto;
16
- padding-top: 1.5rem;
17
- }
 
9
  background: #1565c0;
10
  border-radius: 100vh;
11
  }
 
 
 
 
 
 
uv.lock ADDED
The diff for this file is too large to render. See raw diff