Hijiki commited on
Commit
28c88f6
·
unverified ·
2 Parent(s): c2806e9 b22544c

Merge pull request #7 from hijiki-my-dev/develop

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 +22 -18
.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,41 +1,45 @@
 
 
1
  import streamlit as st
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  # ページ設定
4
  st.set_page_config(
5
- page_title="小説感想生成アプリ(デモ)",
6
  page_icon="📚",
7
  layout="centered",
8
  )
9
 
10
  # アプリのタイトル
11
- st.title("小説感想生成アプリ(デモ版)")
12
- st.subheader("あなたの入力をそのまま返します")
13
 
14
  # 入力フォーム
15
  with st.form("input_form"):
16
- novel_title = st.text_input("小説のタイトル", placeholder="例:人間失格")
17
- summary = st.text_area("あらすじや感想メモ", height=200, placeholder="例:主人公の葉蔵は自分を「人間失格」だと考えている...")
18
  submit_button = st.form_submit_button("生成")
19
 
20
  # 送信ボタンが押されたら結果を表示
21
  if submit_button:
22
- st.markdown("## 入力内容")
23
- st.write(f"**タイトル:** {novel_title}")
24
- st.write("**あらすじや感想メモ:**")
25
- st.write(summary)
26
-
27
- st.markdown("---")
28
 
29
  st.markdown("## 生成された感想記事(デモ)")
30
  st.info(f"""
31
- {novel_title}】についての感想
32
-
33
- {summary}
34
-
35
- ※このデモ版では入力内容をそのまま返しています。
36
- 実際のアプリではここにLLMによって生成された内容が表示されます。
37
  """)
38
 
39
  # フッター
40
  st.markdown("---")
41
- st.caption("Powered by Streamlit & Hugging Face")
 
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(
20
+ page_title="記事要約(デモ)",
21
  page_icon="📚",
22
  layout="centered",
23
  )
24
 
25
  # アプリのタイトル
26
+ st.title("記事要約(デモ)")
27
+ st.subheader("入力を元に要約を生成します")
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("## 生成された感想記事(デモ)")
39
  st.info(f"""
40
+ {summary["summary_text"][0]}
 
 
 
 
 
41
  """)
42
 
43
  # フッター
44
  st.markdown("---")
45
+ st.caption("Powered by Streamlit & Hugging Face")