hysts HF Staff commited on
Commit
8e0b801
·
1 Parent(s): e6b28a2
Files changed (5) hide show
  1. .pre-commit-config.yaml +1 -1
  2. README.md +1 -1
  3. app.py +6 -3
  4. requirements.txt +24 -21
  5. uv.lock +0 -0
.pre-commit-config.yaml CHANGED
@@ -14,7 +14,7 @@ repos:
14
  - id: requirements-txt-fixer
15
  - id: trailing-whitespace
16
  - repo: https://github.com/astral-sh/ruff-pre-commit
17
- rev: v0.15.4
18
  hooks:
19
  - id: ruff-check
20
  args: ["--fix"]
 
14
  - id: requirements-txt-fixer
15
  - id: trailing-whitespace
16
  - repo: https://github.com/astral-sh/ruff-pre-commit
17
+ rev: v0.15.8
18
  hooks:
19
  - id: ruff-check
20
  args: ["--fix"]
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 😻
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 6.9.0
8
  python_version: "3.12"
9
  app_file: app.py
10
  pinned: false
 
4
  colorFrom: indigo
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 6.10.0
8
  python_version: "3.12"
9
  app_file: app.py
10
  pinned: false
app.py CHANGED
@@ -26,7 +26,7 @@ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
26
  model = AutoModelForCausalLM.from_pretrained(
27
  MODEL_ID,
28
  device_map="auto",
29
- torch_dtype=torch.bfloat16,
30
  )
31
  model.config.sliding_window = 4096
32
  model.eval()
@@ -79,6 +79,10 @@ def _generate_on_gpu(
79
  raise gr.Error(msg)
80
 
81
 
 
 
 
 
82
  def generate(
83
  message: str,
84
  chat_history: list[dict],
@@ -88,8 +92,6 @@ def generate(
88
  top_k: int = 50,
89
  repetition_penalty: float = 1.2,
90
  ) -> Iterator[str]:
91
- if not message or not message.strip():
92
- raise gr.Error("Please enter a message.")
93
 
94
  conversation = []
95
  for msg in chat_history:
@@ -125,6 +127,7 @@ def generate(
125
 
126
  demo = gr.ChatInterface(
127
  fn=generate,
 
128
  additional_inputs=[
129
  gr.Slider(
130
  label="Max new tokens",
 
26
  model = AutoModelForCausalLM.from_pretrained(
27
  MODEL_ID,
28
  device_map="auto",
29
+ dtype=torch.bfloat16,
30
  )
31
  model.config.sliding_window = 4096
32
  model.eval()
 
79
  raise gr.Error(msg)
80
 
81
 
82
+ def validate_input(message: str) -> dict:
83
+ return gr.validate(bool(message and message.strip()), "Please enter a message.")
84
+
85
+
86
  def generate(
87
  message: str,
88
  chat_history: list[dict],
 
92
  top_k: int = 50,
93
  repetition_penalty: float = 1.2,
94
  ) -> Iterator[str]:
 
 
95
 
96
  conversation = []
97
  for msg in chat_history:
 
127
 
128
  demo = gr.ChatInterface(
129
  fn=generate,
130
+ validator=validate_input,
131
  additional_inputs=[
132
  gr.Slider(
133
  label="Max new tokens",
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
  # This file was autogenerated by uv via the following command:
2
- # uv export --no-hashes --no-dev --group hf-spaces --no-emit-package typer-slim -o requirements.txt
3
  accelerate==1.13.0
4
  # via gemma-2-9b-it
5
  aiofiles==24.1.0
@@ -16,12 +16,12 @@ annotated-doc==0.0.4
16
  # typer
17
  annotated-types==0.7.0
18
  # via pydantic
19
- anyio==4.12.1
20
  # via
21
  # gradio
22
  # httpx
23
  # starlette
24
- attrs==25.4.0
25
  # via aiohttp
26
  audioop-lts==0.2.2 ; python_full_version >= '3.13'
27
  # via gradio
@@ -32,7 +32,7 @@ certifi==2026.2.25
32
  # httpcore
33
  # httpx
34
  # requests
35
- charset-normalizer==3.4.5
36
  # via requests
37
  click==8.3.1
38
  # via
@@ -42,16 +42,16 @@ colorama==0.4.6 ; sys_platform == 'win32'
42
  # via
43
  # click
44
  # tqdm
45
- datasets==4.6.1
46
- dill==0.4.0
47
  # via
48
  # datasets
49
  # multiprocess
50
- fastapi==0.135.1
51
  # via gradio
52
  ffmpy==1.0.0
53
  # via gradio
54
- filelock==3.25.0
55
  # via
56
  # datasets
57
  # huggingface-hub
@@ -66,19 +66,23 @@ fsspec==2026.2.0
66
  # gradio-client
67
  # huggingface-hub
68
  # torch
69
- gradio==6.9.0
70
  # via
71
  # gemma-2-9b-it
72
  # spaces
73
- gradio-client==2.3.0
74
- # via gradio
 
 
75
  groovy==0.1.2
76
  # via gradio
77
  h11==0.16.0
78
  # via
79
  # httpcore
80
  # uvicorn
81
- hf-xet==1.3.2 ; platform_machine == 'AMD64' or platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
 
 
82
  # via huggingface-hub
83
  httpcore==1.0.9
84
  # via httpx
@@ -90,7 +94,7 @@ httpx==0.28.1
90
  # huggingface-hub
91
  # safehttpx
92
  # spaces
93
- huggingface-hub==1.6.0
94
  # via
95
  # accelerate
96
  # datasets
@@ -122,11 +126,11 @@ multidict==6.7.1
122
  # via
123
  # aiohttp
124
  # yarl
125
- multiprocess==0.70.18
126
  # via datasets
127
  networkx==3.6.1
128
  # via torch
129
- numpy==2.4.2
130
  # via
131
  # accelerate
132
  # datasets
@@ -225,7 +229,7 @@ pyyaml==6.0.3
225
  # transformers
226
  regex==2026.2.28
227
  # via transformers
228
- requests==2.32.5
229
  # via
230
  # datasets
231
  # spaces
@@ -239,14 +243,12 @@ safetensors==0.7.0
239
  # transformers
240
  semantic-version==2.10.0
241
  # via gradio
242
- setuptools==82.0.0
243
  # via torch
244
  shellingham==1.5.4
245
  # via typer
246
  six==1.17.0
247
  # via python-dateutil
248
- spaces==0.47.0
249
- # via gemma-2-9b-it
250
  starlette==0.52.1
251
  # via
252
  # fastapi
@@ -266,13 +268,14 @@ tqdm==4.67.3
266
  # datasets
267
  # huggingface-hub
268
  # transformers
269
- transformers==5.3.0
270
  # via gemma-2-9b-it
271
  triton==3.5.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
272
  # via torch
273
  typer==0.24.1
274
  # via
275
  # gradio
 
276
  # huggingface-hub
277
  # transformers
278
  typing-extensions==4.15.0
@@ -297,7 +300,7 @@ tzdata==2025.3 ; sys_platform == 'emscripten' or sys_platform == 'win32'
297
  # via pandas
298
  urllib3==2.6.3
299
  # via requests
300
- uvicorn==0.41.0
301
  # via gradio
302
  xxhash==3.6.0
303
  # via datasets
 
1
  # This file was autogenerated by uv via the following command:
2
+ # uv export --no-hashes --no-dev --group hf-spaces --no-emit-package typer-slim --no-emit-package spaces -o requirements.txt
3
  accelerate==1.13.0
4
  # via gemma-2-9b-it
5
  aiofiles==24.1.0
 
16
  # typer
17
  annotated-types==0.7.0
18
  # via pydantic
19
+ anyio==4.13.0
20
  # via
21
  # gradio
22
  # httpx
23
  # starlette
24
+ attrs==26.1.0
25
  # via aiohttp
26
  audioop-lts==0.2.2 ; python_full_version >= '3.13'
27
  # via gradio
 
32
  # httpcore
33
  # httpx
34
  # requests
35
+ charset-normalizer==3.4.6
36
  # via requests
37
  click==8.3.1
38
  # via
 
42
  # via
43
  # click
44
  # tqdm
45
+ datasets==4.8.4
46
+ dill==0.4.1
47
  # via
48
  # datasets
49
  # multiprocess
50
+ fastapi==0.135.2
51
  # via gradio
52
  ffmpy==1.0.0
53
  # via gradio
54
+ filelock==3.25.2
55
  # via
56
  # datasets
57
  # huggingface-hub
 
66
  # gradio-client
67
  # huggingface-hub
68
  # torch
69
+ gradio==6.10.0
70
  # via
71
  # gemma-2-9b-it
72
  # spaces
73
+ gradio-client==2.4.0
74
+ # via
75
+ # gradio
76
+ # hf-gradio
77
  groovy==0.1.2
78
  # via gradio
79
  h11==0.16.0
80
  # via
81
  # httpcore
82
  # uvicorn
83
+ hf-gradio==0.3.0
84
+ # via gradio
85
+ hf-xet==1.4.2 ; platform_machine == 'AMD64' or platform_machine == 'aarch64' or platform_machine == 'amd64' or platform_machine == 'arm64' or platform_machine == 'x86_64'
86
  # via huggingface-hub
87
  httpcore==1.0.9
88
  # via httpx
 
94
  # huggingface-hub
95
  # safehttpx
96
  # spaces
97
+ huggingface-hub==1.8.0
98
  # via
99
  # accelerate
100
  # datasets
 
126
  # via
127
  # aiohttp
128
  # yarl
129
+ multiprocess==0.70.19
130
  # via datasets
131
  networkx==3.6.1
132
  # via torch
133
+ numpy==2.4.3
134
  # via
135
  # accelerate
136
  # datasets
 
229
  # transformers
230
  regex==2026.2.28
231
  # via transformers
232
+ requests==2.33.0
233
  # via
234
  # datasets
235
  # spaces
 
243
  # transformers
244
  semantic-version==2.10.0
245
  # via gradio
246
+ setuptools==82.0.1
247
  # via torch
248
  shellingham==1.5.4
249
  # via typer
250
  six==1.17.0
251
  # via python-dateutil
 
 
252
  starlette==0.52.1
253
  # via
254
  # fastapi
 
268
  # datasets
269
  # huggingface-hub
270
  # transformers
271
+ transformers==5.4.0
272
  # via gemma-2-9b-it
273
  triton==3.5.1 ; platform_machine == 'x86_64' and sys_platform == 'linux'
274
  # via torch
275
  typer==0.24.1
276
  # via
277
  # gradio
278
+ # hf-gradio
279
  # huggingface-hub
280
  # transformers
281
  typing-extensions==4.15.0
 
300
  # via pandas
301
  urllib3==2.6.3
302
  # via requests
303
+ uvicorn==0.42.0
304
  # via gradio
305
  xxhash==3.6.0
306
  # via datasets
uv.lock CHANGED
The diff for this file is too large to render. See raw diff