HALU-HAL commited on
Commit
26ec914
1 Parent(s): 96f62a9

[feat] CodeLumiaのリポジトリのファイルツリーとコードを表示するStreamlitアプリケーションを追加

Browse files

## 概要

- `.CodeLumiaignore`と`.SourceSageignore`ファイルを追加し、無視するファイルとディレクトリのパターンを指定
- `CodeLumia.md`ファイルを追加し、リポジトリのファイルツリーとコードを表示するマークダウンファイルを生成
- `Dockerfile`と`docker-compose.yml`を追加し、アプリケーションのDockerイメージとコンテナを定義
- `app.py`ファイルを追加し、以下の機能を実装:
- リポジトリのクローン
- ファイルツリーの取得
- マークダウンファイルの生成
- Streamlitアプリケーションの構築
- `docs/language_map.json`ファイルを追加し、ファイル拡張子と言語のマッピングを定義
- `requirements.txt`ファイルを追加し、必要なPythonパッケージを指定

## 詳細

- `.CodeLumiaignore`と`.SourceSageignore`ファイルを使用して、リポジトリ内の特定のファイルとディレクトリを無視
- `CodeLumia.md`ファイルにリポジトリのファイルツリーとコードを表示
- `Dockerfile`と`docker-compose.yml`を使用して、アプリケーションのDockerイメージとコンテナを定義し、デプロイを容易にする
- `app.py`ファイルでは以下の処理を行う:
- リポジトリをクローンし、ファイルツリーを取得
- マークダウンファイルを生成し、ファイルツリーとコードを表示
- Streamlitアプリケーションを構築し、マークダウンファイルを表示
- マークダウンファイルのダウンロードリンクを提供
- `docs/language_map.json`ファイルを使用して、コードブロックの言語を適切に設定
- `requirements.txt`ファイルにStreamlitパッケージを指定

Files changed (8) hide show
  1. .CodeLumiaignore +170 -0
  2. .SourceSageignore +29 -0
  3. CodeLumia.md +65 -0
  4. Dockerfile +16 -0
  5. app.py +93 -0
  6. docker-compose.yml +9 -0
  7. docs/language_map.json +27 -0
  8. requirements.txt +1 -0
.CodeLumiaignore ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+ SourceSageAssets
163
+
164
+ .git
165
+ .CodeLumiaignore
166
+ .gitattributes
167
+ .gitignore
168
+ LICENSE
169
+ .github
170
+ *.png
.SourceSageignore ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .git
2
+ __pycache__
3
+ LICENSE
4
+ output.md
5
+ assets
6
+ Style-Bert-VITS2
7
+ output
8
+ streamlit
9
+ SourceSage.md
10
+ data
11
+ .gitignore
12
+ .SourceSageignore
13
+ *.png
14
+ Changelog
15
+ SourceSageAssets
16
+ SourceSageAssetsDemo
17
+ __pycache__
18
+ .pyc
19
+ **/__pycache__/**
20
+ modules\__pycache__
21
+ .svg
22
+ sourcesage.egg-info
23
+ .pytest_cache
24
+ dist
25
+ build
26
+
27
+ .gitattributes
28
+ .CodeLumiaignore
29
+ tmp
CodeLumia.md ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CodeLumia File Tree
2
+
3
+ ```
4
+ CodeLumia/
5
+ app.py
6
+ README.md
7
+ docs/
8
+ SourceSageDocs.md
9
+
10
+ ```
11
+
12
+ ## app.py
13
+
14
+ ```python
15
+ # sample code
16
+
17
+ import streamlit as st
18
+
19
+ x = st.slider('Select a value')
20
+ st.write(x, 'squared is', x * x)
21
+ ```
22
+
23
+ ## README.md
24
+
25
+ ```markdown
26
+ ---
27
+ title: CodeLumia
28
+ emoji: 📚
29
+ colorFrom: purple
30
+ colorTo: blue
31
+ sdk: streamlit
32
+ sdk_version: 1.33.0
33
+ app_file: app.py
34
+ pinned: false
35
+ license: mit
36
+ ---
37
+
38
+
39
+ <p align="center">
40
+ <img src="https://media.githubusercontent.com/media/Sunwood-ai-labs/CodeLumia/main/docs/CodeLumia_icon.png" width="50%">
41
+ <br>
42
+ <h1 align="center">CodeLumia</h1>
43
+ <h3 align="center">
44
+ ~Learn to Code, Step by Step~
45
+
46
+ [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/MakiAi/CodeLumia)[![](https://img.shields.io/github/stars/Sunwood-ai-labs/CodeLumia)](https://github.com/Sunwood-ai-labs/CodeLumia)[![](https://img.shields.io/github/last-commit/Sunwood-ai-labs/CodeLumia)](https://github.com/Sunwood-ai-labs/CodeLumia)[![](https://img.shields.io/github/languages/top/Sunwood-ai-labs/CodeLumia)](https://github.com/Sunwood-ai-labs/CodeLumia)
47
+
48
+ </h3>
49
+
50
+ </p>
51
+
52
+
53
+ ```
54
+
55
+ ## docs/SourceSageDocs.md
56
+
57
+ ```markdown
58
+ # SourceSageDocs
59
+
60
+ ```bash
61
+
62
+ sourcesage --repository CodeLumia --owner Sunwood-ai-labs
63
+ ```
64
+ ```
65
+
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && \
6
+ apt-get install -y git && \
7
+ rm -rf /var/lib/apt/lists/*
8
+
9
+ COPY requirements.txt .
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ COPY . .
13
+
14
+ EXPOSE 8501
15
+
16
+ CMD ["streamlit", "run", "app.py"]
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import fnmatch
4
+ import shutil
5
+ import time
6
+ import json
7
+ import base64
8
+
9
+ # .gitignoreのパターンを読み込む
10
+ ignore_patterns = []
11
+ with open(".CodeLumiaignore", "r") as f:
12
+ for line in f:
13
+ line = line.strip()
14
+ if line and not line.startswith("#"):
15
+ ignore_patterns.append(line)
16
+
17
+ # tmpフォルダを削除
18
+ if os.path.exists("tmp"):
19
+ shutil.rmtree("tmp")
20
+
21
+ # tmpフォルダを作成
22
+ os.makedirs("tmp")
23
+
24
+ # リポジトリのクローン
25
+ repo_path = "tmp/CodeLumia"
26
+ if os.path.exists(repo_path):
27
+ shutil.rmtree(repo_path)
28
+ os.system(f"git clone https://github.com/Sunwood-ai-labs/CodeLumia.git {repo_path}")
29
+
30
+ # 一時的な遅延を追加
31
+ time.sleep(1)
32
+
33
+ # リポジトリのファイルツリーを取得
34
+ file_tree = ""
35
+ for root, dirs, files in os.walk("tmp/CodeLumia"):
36
+ # .gitignoreに一致するディレクトリを無視
37
+ dirs[:] = [d for d in dirs if not any(fnmatch.fnmatch(d, pattern) for pattern in ignore_patterns)]
38
+
39
+ level = root.replace("tmp/CodeLumia", "").count(os.sep)
40
+ indent = " " * 4 * (level)
41
+ file_tree += f"{indent}{os.path.basename(root)}/\n"
42
+ subindent = " " * 4 * (level + 1)
43
+ for f in files:
44
+ # .gitignoreに一致するファイルを無視
45
+ if not any(fnmatch.fnmatch(f, pattern) for pattern in ignore_patterns):
46
+ file_tree += f"{subindent}{f}\n"
47
+
48
+ # マークダウンファイルを結合
49
+ markdown_content = f"# CodeLumia File Tree\n\n```\n{file_tree}\n```\n\n"
50
+
51
+ # 拡張子と言語のマッピングを読み込む
52
+ with open("docs/language_map.json", "r") as f:
53
+ language_map = json.load(f)
54
+
55
+ for root, dirs, files in os.walk("tmp/CodeLumia"):
56
+ print(root)
57
+ # .gitignoreに一致するディレクトリを無視
58
+ dirs[:] = [d for d in dirs if not any(fnmatch.fnmatch(d, pattern) for pattern in ignore_patterns)]
59
+ for file in files:
60
+ # .gitignoreに一致するファイルを無視
61
+ if not any(fnmatch.fnmatch(file, pattern) for pattern in ignore_patterns):
62
+ file_path = os.path.join(root, file)
63
+ _, file_extension = os.path.splitext(file)
64
+ language = language_map.get(file_extension, "")
65
+ with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
66
+ content = f.read()
67
+ # コードブロック内のコードブロックの範囲の全行の先頭に2つのスペースを入れる
68
+ lines = content.split("\n")
69
+ modified_lines = []
70
+ inside_code_block = False
71
+ for line in lines:
72
+ if line.startswith("```"):
73
+ inside_code_block = not inside_code_block
74
+ modified_lines.append("\t" + line)
75
+ else:
76
+ if inside_code_block:
77
+ modified_lines.append("\t" + line)
78
+ else:
79
+ modified_lines.append(line)
80
+ content = "\n".join(modified_lines)
81
+ # コードブロックの中のバッククォートをエスケープ
82
+ markdown_content += f"## {file_path.replace("tmp/CodeLumia/", "")}\n\n```{language}\n{content}\n```\n\n"
83
+
84
+ # マークダウンファイルを保存
85
+ with open("CodeLumia.md", "w", encoding="utf-8") as f:
86
+ f.write(markdown_content)
87
+
88
+ # Streamlitアプリケーションの構築
89
+ st.title("CodeLumia")
90
+ st.markdown(markdown_content, unsafe_allow_html=True)
91
+
92
+ # ダウンロードリンクの作成
93
+ st.markdown(f'<a href="data:text/markdown;base64,{base64.b64encode(markdown_content.encode("utf-8")).decode("utf-8")}" download="CodeLumia.md">Download Markdown File</a>', unsafe_allow_html=True)
docker-compose.yml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ build: .
6
+ ports:
7
+ - "8501:8501"
8
+ volumes:
9
+ - .:/app
docs/language_map.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ ".py": "python",
3
+ ".js": "javascript",
4
+ ".java": "java",
5
+ ".c": "c",
6
+ ".cpp": "cpp",
7
+ ".cs": "csharp",
8
+ ".go": "go",
9
+ ".php": "php",
10
+ ".rb": "ruby",
11
+ ".rs": "rust",
12
+ ".ts": "typescript",
13
+ ".html": "html",
14
+ ".css": "css",
15
+ ".json": "json",
16
+ ".xml": "xml",
17
+ ".yml": "yaml",
18
+ ".yaml": "yaml",
19
+ ".md": "markdown",
20
+ ".txt": "plaintext",
21
+ ".sh": "bash",
22
+ ".sql": "sql",
23
+ "Dockerfile": "dockerfile",
24
+ ".dockerfile": "dockerfile",
25
+ "docker-compose.yml": "yaml",
26
+ "docker-compose.yaml": "yaml"
27
+ }
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit