hysts HF staff commited on
Commit
d4cc1fa
·
1 Parent(s): 27f260a
.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: green
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: green
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 5.9.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -1,8 +1,8 @@
1
  #!/usr/bin/env python
2
 
3
  import os
 
4
  from threading import Thread
5
- from typing import Iterator
6
 
7
  import gradio as gr
8
  import spaces
@@ -27,7 +27,7 @@ if torch.cuda.is_available():
27
  @spaces.GPU
28
  def generate(
29
  message: str,
30
- chat_history: list[tuple[str, str]],
31
  system_prompt: str = "",
32
  max_new_tokens: int = 1024,
33
  temperature: float = 0.7,
@@ -35,12 +35,8 @@ def generate(
35
  top_k: int = 50,
36
  repetition_penalty: float = 1.0,
37
  ) -> Iterator[str]:
38
- conversation = []
39
- if system_prompt:
40
- conversation.append({"role": "system", "content": system_prompt})
41
- for user, assistant in chat_history:
42
- conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
43
- conversation.append({"role": "user", "content": message})
44
 
45
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt", add_generation_prompt=True)
46
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
@@ -69,7 +65,7 @@ def generate(
69
  yield "".join(outputs)
70
 
71
 
72
- chat_interface = gr.ChatInterface(
73
  fn=generate,
74
  additional_inputs=[
75
  gr.Textbox(
@@ -121,16 +117,11 @@ chat_interface = gr.ChatInterface(
121
  ["How many hours does it take a man to eat a Helicopter?"],
122
  ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
123
  ],
 
 
 
124
  )
125
 
126
- with gr.Blocks(css="style.css") as demo:
127
- gr.Markdown(DESCRIPTION)
128
- gr.DuplicateButton(
129
- value="Duplicate Space for private use",
130
- elem_id="duplicate-button",
131
- visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
132
- )
133
- chat_interface.render()
134
 
135
  if __name__ == "__main__":
136
  demo.queue(max_size=20).launch()
 
1
  #!/usr/bin/env python
2
 
3
  import os
4
+ from collections.abc import Iterator
5
  from threading import Thread
 
6
 
7
  import gradio as gr
8
  import spaces
 
27
  @spaces.GPU
28
  def generate(
29
  message: str,
30
+ chat_history: list[dict],
31
  system_prompt: str = "",
32
  max_new_tokens: int = 1024,
33
  temperature: float = 0.7,
 
35
  top_k: int = 50,
36
  repetition_penalty: float = 1.0,
37
  ) -> Iterator[str]:
38
+ conversation = [{"role": "system", "content": system_prompt}] if system_prompt else []
39
+ conversation += [*chat_history, {"role": "user", "content": message}]
 
 
 
 
40
 
41
  input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt", add_generation_prompt=True)
42
  if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
 
65
  yield "".join(outputs)
66
 
67
 
68
+ demo = gr.ChatInterface(
69
  fn=generate,
70
  additional_inputs=[
71
  gr.Textbox(
 
117
  ["How many hours does it take a man to eat a Helicopter?"],
118
  ["Write a 100-word article on 'Benefits of Open-Source in AI research'"],
119
  ],
120
+ type="messages",
121
+ description=DESCRIPTION,
122
+ css_paths="style.css",
123
  )
124
 
 
 
 
 
 
 
 
 
125
 
126
  if __name__ == "__main__":
127
  demo.queue(max_size=20).launch()
pyproject.toml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "zephyr-7b"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "accelerate>=1.2.1",
9
+ "gradio>=5.9.1",
10
+ "hf-transfer>=0.1.8",
11
+ "spaces>=0.31.1",
12
+ "torch==2.4.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,8 +1,240 @@
1
- accelerate==0.31.0
2
- bitsandbytes==0.43.1
3
- gradio==4.36.1
4
- scipy==1.13.0
5
- sentencepiece==0.2.0
6
- spaces==0.28.3
7
- torch==2.0.1
8
- 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
+ accelerate==1.2.1
4
+ # via zephyr-7b (pyproject.toml)
5
+ aiofiles==23.2.1
6
+ # via gradio
7
+ annotated-types==0.7.0
8
+ # via pydantic
9
+ anyio==4.7.0
10
+ # via
11
+ # gradio
12
+ # httpx
13
+ # starlette
14
+ certifi==2024.12.14
15
+ # via
16
+ # httpcore
17
+ # httpx
18
+ # requests
19
+ charset-normalizer==3.4.1
20
+ # via requests
21
+ click==8.1.8
22
+ # via
23
+ # typer
24
+ # uvicorn
25
+ exceptiongroup==1.2.2
26
+ # via anyio
27
+ fastapi==0.115.6
28
+ # via gradio
29
+ ffmpy==0.5.0
30
+ # via gradio
31
+ filelock==3.16.1
32
+ # via
33
+ # huggingface-hub
34
+ # torch
35
+ # transformers
36
+ # triton
37
+ fsspec==2024.12.0
38
+ # via
39
+ # gradio-client
40
+ # huggingface-hub
41
+ # torch
42
+ gradio==5.9.1
43
+ # via
44
+ # zephyr-7b (pyproject.toml)
45
+ # spaces
46
+ gradio-client==1.5.2
47
+ # via gradio
48
+ h11==0.14.0
49
+ # via
50
+ # httpcore
51
+ # uvicorn
52
+ hf-transfer==0.1.8
53
+ # via zephyr-7b (pyproject.toml)
54
+ httpcore==1.0.7
55
+ # via httpx
56
+ httpx==0.28.1
57
+ # via
58
+ # gradio
59
+ # gradio-client
60
+ # safehttpx
61
+ # spaces
62
+ huggingface-hub==0.27.0
63
+ # via
64
+ # accelerate
65
+ # gradio
66
+ # gradio-client
67
+ # tokenizers
68
+ # transformers
69
+ idna==3.10
70
+ # via
71
+ # anyio
72
+ # httpx
73
+ # requests
74
+ jinja2==3.1.5
75
+ # via
76
+ # gradio
77
+ # torch
78
+ markdown-it-py==3.0.0
79
+ # via rich
80
+ markupsafe==2.1.5
81
+ # via
82
+ # gradio
83
+ # jinja2
84
+ mdurl==0.1.2
85
+ # via markdown-it-py
86
+ mpmath==1.3.0
87
+ # via sympy
88
+ networkx==3.4.2
89
+ # via torch
90
+ numpy==2.2.1
91
+ # via
92
+ # accelerate
93
+ # gradio
94
+ # pandas
95
+ # transformers
96
+ nvidia-cublas-cu12==12.1.3.1
97
+ # via
98
+ # nvidia-cudnn-cu12
99
+ # nvidia-cusolver-cu12
100
+ # torch
101
+ nvidia-cuda-cupti-cu12==12.1.105
102
+ # via torch
103
+ nvidia-cuda-nvrtc-cu12==12.1.105
104
+ # via torch
105
+ nvidia-cuda-runtime-cu12==12.1.105
106
+ # via torch
107
+ nvidia-cudnn-cu12==9.1.0.70
108
+ # via torch
109
+ nvidia-cufft-cu12==11.0.2.54
110
+ # via torch
111
+ nvidia-curand-cu12==10.3.2.106
112
+ # via torch
113
+ nvidia-cusolver-cu12==11.4.5.107
114
+ # via torch
115
+ nvidia-cusparse-cu12==12.1.0.106
116
+ # via
117
+ # nvidia-cusolver-cu12
118
+ # torch
119
+ nvidia-nccl-cu12==2.20.5
120
+ # via torch
121
+ nvidia-nvjitlink-cu12==12.6.85
122
+ # via
123
+ # nvidia-cusolver-cu12
124
+ # nvidia-cusparse-cu12
125
+ nvidia-nvtx-cu12==12.1.105
126
+ # via torch
127
+ orjson==3.10.13
128
+ # via gradio
129
+ packaging==24.2
130
+ # via
131
+ # accelerate
132
+ # gradio
133
+ # gradio-client
134
+ # huggingface-hub
135
+ # spaces
136
+ # transformers
137
+ pandas==2.2.3
138
+ # via gradio
139
+ pillow==11.0.0
140
+ # via gradio
141
+ psutil==5.9.8
142
+ # via
143
+ # accelerate
144
+ # spaces
145
+ pydantic==2.10.4
146
+ # via
147
+ # fastapi
148
+ # gradio
149
+ # spaces
150
+ pydantic-core==2.27.2
151
+ # via pydantic
152
+ pydub==0.25.1
153
+ # via gradio
154
+ pygments==2.18.0
155
+ # via rich
156
+ python-dateutil==2.9.0.post0
157
+ # via pandas
158
+ python-multipart==0.0.20
159
+ # via gradio
160
+ pytz==2024.2
161
+ # via pandas
162
+ pyyaml==6.0.2
163
+ # via
164
+ # accelerate
165
+ # gradio
166
+ # huggingface-hub
167
+ # transformers
168
+ regex==2024.11.6
169
+ # via transformers
170
+ requests==2.32.3
171
+ # via
172
+ # huggingface-hub
173
+ # spaces
174
+ # transformers
175
+ rich==13.9.4
176
+ # via typer
177
+ ruff==0.8.4
178
+ # via gradio
179
+ safehttpx==0.1.6
180
+ # via gradio
181
+ safetensors==0.4.5
182
+ # via
183
+ # accelerate
184
+ # transformers
185
+ semantic-version==2.10.0
186
+ # via gradio
187
+ shellingham==1.5.4
188
+ # via typer
189
+ six==1.17.0
190
+ # via python-dateutil
191
+ sniffio==1.3.1
192
+ # via anyio
193
+ spaces==0.31.1
194
+ # via zephyr-7b (pyproject.toml)
195
+ starlette==0.41.3
196
+ # via
197
+ # fastapi
198
+ # gradio
199
+ sympy==1.13.3
200
+ # via torch
201
+ tokenizers==0.21.0
202
+ # via transformers
203
+ tomlkit==0.13.2
204
+ # via gradio
205
+ torch==2.4.0
206
+ # via
207
+ # zephyr-7b (pyproject.toml)
208
+ # accelerate
209
+ tqdm==4.67.1
210
+ # via
211
+ # huggingface-hub
212
+ # transformers
213
+ transformers==4.47.1
214
+ # via zephyr-7b (pyproject.toml)
215
+ triton==3.0.0
216
+ # via torch
217
+ typer==0.15.1
218
+ # via gradio
219
+ typing-extensions==4.12.2
220
+ # via
221
+ # anyio
222
+ # fastapi
223
+ # gradio
224
+ # gradio-client
225
+ # huggingface-hub
226
+ # pydantic
227
+ # pydantic-core
228
+ # rich
229
+ # spaces
230
+ # torch
231
+ # typer
232
+ # uvicorn
233
+ tzdata==2024.2
234
+ # via pandas
235
+ urllib3==2.3.0
236
+ # via requests
237
+ uvicorn==0.34.0
238
+ # via gradio
239
+ websockets==14.1
240
+ # via gradio-client
style.css CHANGED
@@ -9,9 +9,3 @@ h1 {
9
  background: #1565c0;
10
  border-radius: 100vh;
11
  }
12
-
13
- .contain {
14
- max-width: 900px;
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