Hijiki-HF commited on
Commit
b22544c
·
1 Parent(s): b5ea8b6

feat: gguf for spaces

Browse files
Files changed (4) hide show
  1. .gitignore +3 -0
  2. README.md +20 -1
  3. requirements.txt +3 -66
  4. src/app.py +11 -32
.gitignore CHANGED
@@ -1,5 +1,8 @@
 
1
  models/
 
2
  src/data/
 
3
  tmp/
4
 
5
  # Byte-compiled / optimized / DLL files
 
1
+ fig_memo/
2
  models/
3
+ practice/
4
  src/data/
5
+ src/model/
6
  tmp/
7
 
8
  # Byte-compiled / optimized / DLL files
README.md CHANGED
@@ -46,4 +46,23 @@ LLMやBERTなどの自然言語処理技術を使ったプロジェクトの練
46
  ├── collect # データセットを作成する
47
  ├── data
48
  └── app.py
49
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  ├── collect # データセットを作成する
47
  ├── data
48
  └── app.py
49
+ ```
50
+
51
+ ## 実行方法
52
+
53
+ - ローカル
54
+
55
+
56
+ ## メモ
57
+ ### モデルについて
58
+ - (2025/5/10)LLMをCPUで使用するのはかなり厳しい。gguf形式のものを適切に使用すれば可能かもしれないが、まずはt5などを使用する?
59
+ - LLMについて比較を行った結果
60
+ - SakanaAI/TinySwallow-1.5B-Instruct(1.5Bということを考慮に入れるとgemma3以上?)
61
+ - gguf形式ならCPUでも推論可能なはず。だけどcolabで6分かかる、、、
62
+ - google/gemma-3-4b-it(圧倒的。1bは英語のみ対応)
63
+ - Rakuten/RakutenAI-2.0-mini-instruct(かなり良い)
64
+ - rinna/gemma-2-baku-2b-it(そこそこ。実行方法が悪い?)
65
+ - google/gemma-2-2b-jpn-it(同)
66
+ - meta-llama/Llama-3.2-3B-Instruct(日本語対応してない)
67
+ - microsoft/Phi-4-mini-instruct
68
+ - lightblue/DeepSeek-R1-Distill-Qwen-1.5B-Multilingual
requirements.txt CHANGED
@@ -1,66 +1,3 @@
1
- altair==5.5.0
2
- appnope==0.1.4
3
- asttokens==3.0.0
4
- attrs==25.1.0
5
- blinker==1.9.0
6
- cachetools==5.5.1
7
- certifi==2025.1.31
8
- charset-normalizer==3.4.1
9
- click==8.1.8
10
- comm==0.2.2
11
- debugpy==1.8.9
12
- decorator==5.1.1
13
- diskcache==5.6.3
14
- executing==2.1.0
15
- gitdb==4.0.12
16
- GitPython==3.1.44
17
- idna==3.10
18
- ipykernel==6.29.5
19
- ipython==8.30.0
20
- jedi==0.19.2
21
- Jinja2==3.1.4
22
- jsonschema==4.23.0
23
- jsonschema-specifications==2024.10.1
24
- jupyter_client==8.6.3
25
- jupyter_core==5.7.2
26
- llama_cpp_python==0.3.2
27
- markdown-it-py==3.0.0
28
- MarkupSafe==3.0.2
29
- matplotlib-inline==0.1.7
30
- mdurl==0.1.2
31
- narwhals==1.27.1
32
- nest-asyncio==1.6.0
33
- numpy==2.1.3
34
- packaging==24.2
35
- pandas==2.2.3
36
- parso==0.8.4
37
- pexpect==4.9.0
38
- pillow==11.1.0
39
- platformdirs==4.3.6
40
- prompt_toolkit==3.0.48
41
- protobuf==5.29.3
42
- psutil==6.1.0
43
- ptyprocess==0.7.0
44
- pure_eval==0.2.3
45
- pyarrow==19.0.0
46
- pydeck==0.9.1
47
- Pygments==2.18.0
48
- python-dateutil==2.9.0.post0
49
- pytz==2024.2
50
- pyzmq==26.2.0
51
- referencing==0.36.2
52
- requests==2.32.3
53
- rich==13.9.4
54
- rpds-py==0.22.3
55
- six==1.17.0
56
- smmap==5.0.2
57
- stack-data==0.6.3
58
- streamlit==1.42.1
59
- tenacity==9.0.0
60
- toml==0.10.2
61
- tornado==6.4.2
62
- traitlets==5.14.3
63
- typing_extensions==4.12.2
64
- tzdata==2024.2
65
- urllib3==2.3.0
66
- wcwidth==0.2.13
 
1
+ huggingface-hub
2
+ llama-cpp-python
3
+ streamlit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/app.py CHANGED
@@ -1,32 +1,19 @@
1
- from optimum.onnxruntime import ORTModelForSeq2SeqLM
 
2
  import streamlit as st
3
- import torch
4
- from transformers import AutoTokenizer, pipeline
5
 
6
- torch.classes.__path__ = []
7
 
8
  def summarize_article(input_text):
9
- MODEL_PATH = "model/mt5_onnx"
10
-
11
- # ONNXモデルの読み込み
12
- tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, local_files_only=True)
13
- model = ORTModelForSeq2SeqLM.from_pretrained(MODEL_PATH, local_files_only=True)
14
-
15
- summarizer = pipeline(
16
- "summarization",
17
- model=model,
18
- tokenizer=tokenizer
19
- )
20
- return summarizer(
21
- input_text,
22
- max_length=600,
23
- min_length=200,
24
- do_sample=True,
25
- temperature=0.5,
26
- num_beams=4,
27
- early_stopping=True
28
- )
29
 
 
 
 
 
 
30
 
31
  # ページ設定
32
  st.set_page_config(
@@ -41,19 +28,11 @@ st.subheader("入力を元に要約を生成します")
41
 
42
  # 入力フォーム
43
  with st.form("input_form"):
44
- # novel_title = st.text_input("小説のタイトル", placeholder="例:人間失格")
45
  input_text = st.text_area("記事内容", height=200, placeholder="例:主人公の葉蔵は自分を「人間失格」だと考えている...")
46
  submit_button = st.form_submit_button("生成")
47
 
48
  # 送信ボタンが押されたら結果を表示
49
  if submit_button:
50
- # st.markdown("## 入力内容")
51
- # # st.write(f"**タイトル:** {novel_title}")
52
- # st.write("**あらすじや感想メモ:**")
53
- # st.write(summary)
54
-
55
- # st.markdown("---")
56
-
57
  summary = summarize_article(input_text)
58
 
59
  st.markdown("## 生成された感想記事(デモ)")
 
1
+ from huggingface_hub import hf_hub_download
2
+ from llama_cpp import Llama
3
  import streamlit as st
 
 
4
 
5
+ MAX_OUTPUT_TOKENS = 512
6
 
7
  def summarize_article(input_text):
8
+ repo_id = "SakanaAI/TinySwallow-1.5B-Instruct-GGUF"
9
+ filename = "tinyswallow-1.5b-instruct-q5_k_m.gguf"
10
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ # モデルの読み込み
13
+ llm = Llama(model_path=model_path, n_ctx=4096, n_gpu_layers=-1)
14
+ prompt = f"以下のテキストを日本語で約400字程度に要約してください。特に固有名詞や専門用語は正確に含めてください。テキスト: {input_text} 要約: "
15
+ response = llm(prompt, max_tokens=MAX_OUTPUT_TOKENS)
16
+ return response["choices"][0]["text"]
17
 
18
  # ページ設定
19
  st.set_page_config(
 
28
 
29
  # 入力フォーム
30
  with st.form("input_form"):
 
31
  input_text = st.text_area("記事内容", height=200, placeholder="例:主人公の葉蔵は自分を「人間失格」だと考えている...")
32
  submit_button = st.form_submit_button("生成")
33
 
34
  # 送信ボタンが押されたら結果を表示
35
  if submit_button:
 
 
 
 
 
 
 
36
  summary = summarize_article(input_text)
37
 
38
  st.markdown("## 生成された感想記事(デモ)")