nakamura196 commited on
Commit
10c0e13
1 Parent(s): b97741c

feat: initial commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.faiss filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .DS_Store
2
+ __pycache__
3
+ .venv
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Jp Cos
3
  emoji: 🦀
4
  colorFrom: gray
5
  colorTo: red
 
1
  ---
2
+ title: 学習指導要領コード Predictor
3
  emoji: 🦀
4
  colorFrom: gray
5
  colorTo: red
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from langchain_community.vectorstores.faiss import FAISS
3
+ from langchain_community.embeddings.huggingface import HuggingFaceEmbeddings
4
+
5
+ # インデックスのパス
6
+ index_path = "./storage"
7
+
8
+ # 埋め込みモデルの読み込み
9
+ embedding_model = HuggingFaceEmbeddings(
10
+ model_name="intfloat/multilingual-e5-large"
11
+ )
12
+
13
+ # インデックスの読み込み
14
+ index = FAISS.load_local(
15
+ folder_path=index_path,
16
+ embeddings=embedding_model,
17
+ allow_dangerous_deserialization=True
18
+ )
19
+
20
+ def search_documents(input_text, grade):
21
+ output = []
22
+
23
+ metadata = {}
24
+
25
+ if grade:
26
+ metadata["学校種別"] = grade
27
+
28
+ docs_and_scores = index.similarity_search_with_score(
29
+ input_text,
30
+ filter=metadata
31
+ )
32
+
33
+
34
+ for idx, (doc, score) in enumerate(docs_and_scores):
35
+ row = [
36
+ f"<a href=\"https://w3id.org/jp-cos/{doc.metadata['id']}\" target=\"_blank\">{doc.metadata['id']}</a>",
37
+ doc.metadata["学校種別"],
38
+ doc.metadata["教科等"],
39
+ round(float(score), 3),
40
+ doc.page_content,
41
+ ]
42
+
43
+ output.append(row)
44
+
45
+ return output
46
+
47
+ # Components for input and output
48
+ text_input = gr.Textbox(lines=2, placeholder="テキストを入力してください。", label="テキスト")
49
+
50
+ schools = ['小学校', '特別支援学校小学部, 特別支援学校中学部', '幼稚園', '特別支援学校幼稚部', '中学校', '高等学校']
51
+
52
+ metadata_selector = gr.CheckboxGroup(schools, label="学校種別")
53
+ output_table = gr.Dataframe(
54
+ headers=["学習指導要領コード", "学校種別", "教科等", "スコア", "テキスト"],
55
+ datatype=["html", "str", "str", "str", "number"])
56
+
57
+ # Interface
58
+
59
+ examples=[
60
+ ["空気鉄砲や水鉄砲、ペットボトルロケットなどのしくみを調べ、空気はおし縮められ体積が小さくなるにつれて反発する力が大きくなるが、水はおし縮められないことに気づく。", "小学校"],
61
+ ["頼朝の妻・北条政子は、頼朝が築いた「ご恩と奉公」の絆で御家人たちを団結させ、復権をねらう朝廷に打ち勝った。鎌倉幕府の力をさらに強固なものにした政子の功績を知る。", "小学校"],
62
+ ["胞子をつくるキノコ。胞子が菌糸を伸ばし新しいキノコを作る", "中学校"],
63
+ ["今回のテーマは「鋭角の三角比の定義」。三角比は、高校で初めて扱う分野です。サイン、コサイン、タンジェント・・・これから何回かにわたり、この言葉を使って図形などの問題を解いていきますので、定義をばっちり覚えておきましょう。ミニコーナーでは、物語を書いたことで有名な、ある数学者を紹介します。\n出演:アイク ぬわら、酒井 蒼澄、藤本 ばんび、湯浅 弘一", "高等学校"]
64
+ ]
65
+
66
+ article = "<p style='text-align: center'><a href='https://jp-cos.github.io/' target='_blank'>学習指導要領LOD</a> | <a href='https://www.nhk.or.jp/school/' target='_blank'>NHK for School</a></p>"
67
+
68
+ demo = gr.Interface(
69
+ search_documents,
70
+ [text_input, metadata_selector],
71
+ output_table,
72
+ title="学習指導要領コード Predictor",
73
+ description="入力したテキストに類似するテキストを持つ学習指導要領コードを検索します。",
74
+ article=article,
75
+ examples=examples,
76
+ allow_flagging=False,
77
+ )
78
+
79
+ demo.launch()
jp-cos/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
jp-cos/README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Jp Cos
3
+ emoji: 🦀
4
+ colorFrom: gray
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 4.26.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: cc-by-4.0
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ langchain-community
2
+ gradio
3
+ sentence-transformers
4
+ faiss-cpu
storage/index.faiss ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6d162de6a9bc7dfcef406b659f0f3e47fca7282d9c407b0db8c77528a7f3eb0d
3
+ size 93859885
storage/index.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63d8bb58709dd698b762313ee98c4f3426973179721f5e1144d1f2a529d3c5a4
3
+ size 5814920