hayas commited on
Commit
b3d9f11
·
1 Parent(s): 31790f0
.pre-commit-config.yaml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
7
+ - id: check-merge-conflict
8
+ - id: check-shebang-scripts-are-executable
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: end-of-file-fixer
12
+ - id: mixed-line-ending
13
+ args: ["--fix=lf"]
14
+ - id: requirements-txt-fixer
15
+ - id: trailing-whitespace
16
+ - repo: https://github.com/astral-sh/ruff-pre-commit
17
+ rev: v0.9.9
18
+ hooks:
19
+ - id: ruff
20
+ args: ["--fix"]
21
+ - id: ruff-format
22
+ - repo: https://github.com/pre-commit/mirrors-mypy
23
+ rev: v1.15.0
24
+ hooks:
25
+ - id: mypy
26
+ args: ["--ignore-missing-imports"]
27
+ additional_dependencies:
28
+ [
29
+ "types-python-slugify",
30
+ "types-pytz",
31
+ "types-PyYAML",
32
+ "types-requests",
33
+ ]
.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 ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
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.formatOnSave.enabled": true
17
+ }
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: Asagi 14B
3
- emoji: 🐢
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.20.0
8
  app_file: app.py
 
1
  ---
2
+ title: Asagi-14B
3
+ emoji:
4
+ colorFrom: red
5
+ colorTo: purple
6
  sdk: gradio
7
  sdk_version: 5.20.0
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import gradio as gr
4
+ import PIL.Image
5
+ import spaces
6
+ import torch
7
+ from transformers import AutoModel, AutoProcessor, GenerationConfig
8
+
9
+ DESCRIPTION = "# MIL-UT/Asagi-14B"
10
+
11
+ model_id = "MIL-UT/Asagi-14B"
12
+ processor = AutoProcessor.from_pretrained(model_id)
13
+ model = AutoModel.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
14
+
15
+
16
+ TEMPLATE = (
17
+ "以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。\n\n"
18
+ "### 指示:\n<image>\n{prompt}\n\n### 応答:\n"
19
+ )
20
+
21
+
22
+ @spaces.GPU
23
+ def run(
24
+ image: PIL.Image.Image,
25
+ prompt: str,
26
+ max_new_tokens: int = 256,
27
+ temperature: float = 0.7,
28
+ ) -> str:
29
+ prompt = TEMPLATE.format(prompt=prompt)
30
+
31
+ inputs = processor(text=prompt, images=image, return_tensors="pt")
32
+ inputs_text = processor.tokenizer(prompt, return_tensors="pt")
33
+ inputs["input_ids"] = inputs_text["input_ids"]
34
+ inputs["attention_mask"] = inputs_text["attention_mask"]
35
+ for k, v in inputs.items():
36
+ if v.dtype == torch.float32:
37
+ inputs[k] = v.to(model.dtype)
38
+ inputs = {k: inputs[k].to(model.device) for k in inputs if k != "token_type_ids"}
39
+
40
+ generation_config = GenerationConfig(
41
+ max_new_tokens=max_new_tokens,
42
+ temperature=temperature,
43
+ do_sample=temperature > 0,
44
+ num_beams=5,
45
+ )
46
+
47
+ output = model.generate(**inputs, generation_config=generation_config)
48
+ generated_text = processor.batch_decode(output, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
49
+
50
+ # do not print the prompt
51
+ if "<image>" in prompt:
52
+ prompt = prompt.replace("<image>", " ")
53
+ return generated_text.replace(prompt, "")
54
+
55
+
56
+ examples = [
57
+ [
58
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/shibuya.jpg",
59
+ "この画像を見て、次の質問に詳細かつ具体的に答えてください。この写真はどこで撮影されたものか教えてください。また、画像の内容についても詳しく説明してください。",
60
+ ],
61
+ [
62
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/bridge.jpg",
63
+ "この画像を見て、次の指示に詳細かつ具体的に答えてください。この写真の内容について詳しく教えてください。",
64
+ ],
65
+ [
66
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/tower.jpg",
67
+ "この画像を見て、次の質問に詳細かつ具体的に答えてください。この写真について評価してください。",
68
+ ],
69
+ [
70
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/shrine.jpg",
71
+ "この画像を見て、次の質問に詳細かつ具体的に答えてください。この写真の神社について、細かいところまで詳しく説明してください。",
72
+ ],
73
+ [
74
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/garden.jpg",
75
+ "この画像を見て、次の指示に詳細かつ具体的に答えてください。これは日本庭園の中でも、どのような形式に分類される庭園ですか?また、その理由は何ですか?", # noqa: RUF001
76
+ ],
77
+ [
78
+ "https://raw.githubusercontent.com/uehara-mech/uehara-mech.github.io/refs/heads/master/images/slope.jpg",
79
+ "この画像を見て、次の質問に詳細に答えてください。この画像の場所を舞台とした小説のあらすじを書いてください。",
80
+ ],
81
+ ]
82
+
83
+ with gr.Blocks(css_paths="style.css") as demo:
84
+ gr.Markdown(DESCRIPTION)
85
+ with gr.Row():
86
+ with gr.Column():
87
+ image = gr.Image(label="Input Image")
88
+ prompt = gr.Textbox(label="Prompt")
89
+ run_button = gr.Button()
90
+ with gr.Accordion("Advanced options", open=False):
91
+ max_new_tokens = gr.Slider(
92
+ label="Max new tokens",
93
+ minimum=1,
94
+ maximum=1024,
95
+ step=1,
96
+ value=256,
97
+ )
98
+ temperature = gr.Slider(
99
+ label="Temperature",
100
+ minimum=0.1,
101
+ maximum=2.0,
102
+ step=0.1,
103
+ value=0.7,
104
+ )
105
+ with gr.Column():
106
+ output = gr.Textbox(label="Output")
107
+
108
+ gr.Examples(examples=examples, inputs=[image, prompt])
109
+
110
+ run_button.click(
111
+ fn=run,
112
+ inputs=[image, prompt, max_new_tokens, temperature],
113
+ outputs=output,
114
+ )
115
+
116
+ if __name__ == "__main__":
117
+ demo.launch()
pyproject.toml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "asagi-14b"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "accelerate>=1.4.0",
9
+ "gradio>=5.9.1",
10
+ "hf-transfer>=0.1.9",
11
+ "spaces>=0.32.0",
12
+ "torch==2.4.0",
13
+ "transformers==4.45.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.lint.pydocstyle]
50
+ convention = "google"
51
+
52
+ [tool.ruff.lint.per-file-ignores]
53
+ "*.ipynb" = ["T201", "T203"]
54
+
55
+ [tool.ruff.format]
56
+ docstring-code-format = true
requirements.txt ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ accelerate==1.4.0
4
+ # via asagi-14b (pyproject.toml)
5
+ aiofiles==23.2.1
6
+ # via gradio
7
+ annotated-types==0.7.0
8
+ # via pydantic
9
+ anyio==4.8.0
10
+ # via
11
+ # gradio
12
+ # httpx
13
+ # starlette
14
+ certifi==2025.1.31
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.11
28
+ # via gradio
29
+ ffmpy==0.5.0
30
+ # via gradio
31
+ filelock==3.17.0
32
+ # via
33
+ # huggingface-hub
34
+ # torch
35
+ # transformers
36
+ # triton
37
+ fsspec==2025.2.0
38
+ # via
39
+ # gradio-client
40
+ # huggingface-hub
41
+ # torch
42
+ gradio==5.20.0
43
+ # via
44
+ # asagi-14b (pyproject.toml)
45
+ # spaces
46
+ gradio-client==1.7.2
47
+ # via gradio
48
+ groovy==0.1.2
49
+ # via gradio
50
+ h11==0.14.0
51
+ # via
52
+ # httpcore
53
+ # uvicorn
54
+ hf-transfer==0.1.9
55
+ # via asagi-14b (pyproject.toml)
56
+ httpcore==1.0.7
57
+ # via httpx
58
+ httpx==0.28.1
59
+ # via
60
+ # gradio
61
+ # gradio-client
62
+ # safehttpx
63
+ # spaces
64
+ huggingface-hub==0.29.1
65
+ # via
66
+ # accelerate
67
+ # gradio
68
+ # gradio-client
69
+ # tokenizers
70
+ # transformers
71
+ idna==3.10
72
+ # via
73
+ # anyio
74
+ # httpx
75
+ # requests
76
+ jinja2==3.1.5
77
+ # via
78
+ # gradio
79
+ # torch
80
+ markdown-it-py==3.0.0
81
+ # via rich
82
+ markupsafe==2.1.5
83
+ # via
84
+ # gradio
85
+ # jinja2
86
+ mdurl==0.1.2
87
+ # via markdown-it-py
88
+ mpmath==1.3.0
89
+ # via sympy
90
+ networkx==3.4.2
91
+ # via torch
92
+ numpy==2.2.3
93
+ # via
94
+ # accelerate
95
+ # gradio
96
+ # pandas
97
+ # transformers
98
+ nvidia-cublas-cu12==12.1.3.1
99
+ # via
100
+ # nvidia-cudnn-cu12
101
+ # nvidia-cusolver-cu12
102
+ # torch
103
+ nvidia-cuda-cupti-cu12==12.1.105
104
+ # via torch
105
+ nvidia-cuda-nvrtc-cu12==12.1.105
106
+ # via torch
107
+ nvidia-cuda-runtime-cu12==12.1.105
108
+ # via torch
109
+ nvidia-cudnn-cu12==9.1.0.70
110
+ # via torch
111
+ nvidia-cufft-cu12==11.0.2.54
112
+ # via torch
113
+ nvidia-curand-cu12==10.3.2.106
114
+ # via torch
115
+ nvidia-cusolver-cu12==11.4.5.107
116
+ # via torch
117
+ nvidia-cusparse-cu12==12.1.0.106
118
+ # via
119
+ # nvidia-cusolver-cu12
120
+ # torch
121
+ nvidia-nccl-cu12==2.20.5
122
+ # via torch
123
+ nvidia-nvjitlink-cu12==12.8.61
124
+ # via
125
+ # nvidia-cusolver-cu12
126
+ # nvidia-cusparse-cu12
127
+ nvidia-nvtx-cu12==12.1.105
128
+ # via torch
129
+ orjson==3.10.15
130
+ # via gradio
131
+ packaging==24.2
132
+ # via
133
+ # accelerate
134
+ # gradio
135
+ # gradio-client
136
+ # huggingface-hub
137
+ # spaces
138
+ # transformers
139
+ pandas==2.2.3
140
+ # via gradio
141
+ pillow==11.1.0
142
+ # via gradio
143
+ psutil==5.9.8
144
+ # via
145
+ # accelerate
146
+ # spaces
147
+ pydantic==2.10.6
148
+ # via
149
+ # fastapi
150
+ # gradio
151
+ # spaces
152
+ pydantic-core==2.27.2
153
+ # via pydantic
154
+ pydub==0.25.1
155
+ # via gradio
156
+ pygments==2.19.1
157
+ # via rich
158
+ python-dateutil==2.9.0.post0
159
+ # via pandas
160
+ python-multipart==0.0.20
161
+ # via gradio
162
+ pytz==2025.1
163
+ # via pandas
164
+ pyyaml==6.0.2
165
+ # via
166
+ # accelerate
167
+ # gradio
168
+ # huggingface-hub
169
+ # transformers
170
+ regex==2024.11.6
171
+ # via transformers
172
+ requests==2.32.3
173
+ # via
174
+ # huggingface-hub
175
+ # spaces
176
+ # transformers
177
+ rich==13.9.4
178
+ # via typer
179
+ ruff==0.9.9
180
+ # via gradio
181
+ safehttpx==0.1.6
182
+ # via gradio
183
+ safetensors==0.5.3
184
+ # via
185
+ # accelerate
186
+ # transformers
187
+ semantic-version==2.10.0
188
+ # via gradio
189
+ shellingham==1.5.4
190
+ # via typer
191
+ six==1.17.0
192
+ # via python-dateutil
193
+ sniffio==1.3.1
194
+ # via anyio
195
+ spaces==0.32.0
196
+ # via asagi-14b (pyproject.toml)
197
+ starlette==0.46.0
198
+ # via
199
+ # fastapi
200
+ # gradio
201
+ sympy==1.13.3
202
+ # via torch
203
+ tokenizers==0.20.3
204
+ # via transformers
205
+ tomlkit==0.13.2
206
+ # via gradio
207
+ torch==2.4.0
208
+ # via
209
+ # asagi-14b (pyproject.toml)
210
+ # accelerate
211
+ tqdm==4.67.1
212
+ # via
213
+ # huggingface-hub
214
+ # transformers
215
+ transformers==4.45.1
216
+ # via asagi-14b (pyproject.toml)
217
+ triton==3.0.0
218
+ # via torch
219
+ typer==0.15.2
220
+ # via gradio
221
+ typing-extensions==4.12.2
222
+ # via
223
+ # anyio
224
+ # fastapi
225
+ # gradio
226
+ # gradio-client
227
+ # huggingface-hub
228
+ # pydantic
229
+ # pydantic-core
230
+ # rich
231
+ # spaces
232
+ # torch
233
+ # typer
234
+ # uvicorn
235
+ tzdata==2025.1
236
+ # via pandas
237
+ urllib3==2.3.0
238
+ # via requests
239
+ uvicorn==0.34.0
240
+ # via gradio
241
+ websockets==15.0
242
+ # via gradio-client
style.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ #duplicate-button {
7
+ margin: auto;
8
+ color: #fff;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
+ }
uv.lock ADDED
The diff for this file is too large to render. See raw diff