[feat] リポジトリのURLを入力してファイルツリーとコードを表示する機能を追加
Browse files- リポジトリのURLを入力するテキストボックスを追加
- 入力されたリポジトリをクローンし、ファイルツリーとコードを表示
- `.gitignore`のパターンを編集するサイドバーを追加
- マークダウンファイルのダウンロードリンクを作成
- フルテキストを表示するセクションを追加
[docs] ページの先頭にCodeLumiaのアイコンと説明を追加
- `docs/page_front.md`ファイルを作成
- CodeLumiaのアイコン、タイトル、説明を追加
- バッジを追加して、Hugging Face Spaces、GitHub Stars、Last Commit、Top Languageを表示
[style] マークダウンファイルのフォーマットを改善
- CodeLumiaファイルツリーのタイトルに`<<`と`>>`を追加
- CodeLumiaファイルツリーのタイトルにリポジトリ名を表示
- ファイルツリーのタイトルを`## File Tree`に変更
[chore] 開発環境の設定を変更
- `streamlit.yaml`ファイルの`sdk`を`docker`に変更
- `streamlit.yaml`ファイルの`sdk_version`を`1.33.0`に変更
- CodeLumia.md +2 -1
- README.md +2 -2
- app.py +97 -78
- docs/page_front.md +12 -0
CodeLumia.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
-
# CodeLumia
|
|
|
|
| 2 |
|
| 3 |
```
|
| 4 |
CodeLumia/
|
|
|
|
| 1 |
+
# << CodeLumia>>
|
| 2 |
+
## CodeLumia File Tree
|
| 3 |
|
| 4 |
```
|
| 5 |
CodeLumia/
|
README.md
CHANGED
|
@@ -3,7 +3,7 @@ title: CodeLumia
|
|
| 3 |
emoji: 📚
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
-
sdk:
|
| 7 |
sdk_version: 1.33.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
@@ -12,7 +12,7 @@ license: mit
|
|
| 12 |
|
| 13 |
|
| 14 |
<p align="center">
|
| 15 |
-
<img src="https://media.githubusercontent.com/media/Sunwood-ai-labs/CodeLumia/main/docs/CodeLumia_icon.png" width="
|
| 16 |
<br>
|
| 17 |
<h1 align="center">CodeLumia</h1>
|
| 18 |
<h3 align="center">
|
|
|
|
| 3 |
emoji: 📚
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: blue
|
| 6 |
+
sdk: docker
|
| 7 |
sdk_version: 1.33.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
<p align="center">
|
| 15 |
+
<img src="https://media.githubusercontent.com/media/Sunwood-ai-labs/CodeLumia/main/docs/CodeLumia_icon.png" width="50%">
|
| 16 |
<br>
|
| 17 |
<h1 align="center">CodeLumia</h1>
|
| 18 |
<h3 align="center">
|
app.py
CHANGED
|
@@ -8,86 +8,105 @@ import base64
|
|
| 8 |
|
| 9 |
# .gitignoreのパターンを読み込む
|
| 10 |
ignore_patterns = []
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
line
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
modified_lines.append("\t" + line)
|
| 78 |
else:
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
f.write(markdown_content)
|
| 87 |
|
| 88 |
-
#
|
| 89 |
-
st.
|
| 90 |
-
st.markdown(markdown_content, unsafe_allow_html=True)
|
| 91 |
|
| 92 |
-
|
| 93 |
-
st.markdown(
|
|
|
|
|
|
| 8 |
|
| 9 |
# .gitignoreのパターンを読み込む
|
| 10 |
ignore_patterns = []
|
| 11 |
+
if os.path.exists(".CodeLumiaignore"):
|
| 12 |
+
with open(".CodeLumiaignore", "r") as f:
|
| 13 |
+
for line in f:
|
| 14 |
+
line = line.strip()
|
| 15 |
+
if line and not line.startswith("#"):
|
| 16 |
+
ignore_patterns.append(line)
|
| 17 |
+
|
| 18 |
+
# docs\page_front.mdファイルの内容を読み込む
|
| 19 |
+
if os.path.exists("docs/page_front.md"):
|
| 20 |
+
with open("docs/page_front.md", "r", encoding="utf-8") as f:
|
| 21 |
+
page_front_content = f.read()
|
| 22 |
+
|
| 23 |
+
st.markdown(page_front_content, unsafe_allow_html=True)
|
| 24 |
+
|
| 25 |
+
# リポジトリのURLを入力するテキストボックス
|
| 26 |
+
repo_url = st.text_input("リポジトリのURL:")
|
| 27 |
+
|
| 28 |
+
# .gitignoreのパターンを編集するサイドバー
|
| 29 |
+
st.sidebar.title(".gitignore Patterns")
|
| 30 |
+
ignore_patterns = st.sidebar.text_area("Enter patterns (one per line):", value="\n".join(ignore_patterns), height=600).split("\n")
|
| 31 |
+
|
| 32 |
+
if repo_url:
|
| 33 |
+
# tmpフォルダを削除
|
| 34 |
+
if os.path.exists("tmp"):
|
| 35 |
+
shutil.rmtree("tmp")
|
| 36 |
+
|
| 37 |
+
# tmpフォルダを作成
|
| 38 |
+
os.makedirs("tmp")
|
| 39 |
+
|
| 40 |
+
# リポジトリのクローン
|
| 41 |
+
repo_name = repo_url.split("/")[-1].split(".")[0]
|
| 42 |
+
repo_path = f"tmp/{repo_name}"
|
| 43 |
+
if os.path.exists(repo_path):
|
| 44 |
+
shutil.rmtree(repo_path)
|
| 45 |
+
os.system(f"git clone {repo_url} {repo_path}")
|
| 46 |
+
|
| 47 |
+
# 一時的な遅延を追加
|
| 48 |
+
time.sleep(1)
|
| 49 |
+
|
| 50 |
+
# リポジトリのファイルツリーを取得
|
| 51 |
+
file_tree = ""
|
| 52 |
+
for root, dirs, files in os.walk(repo_path):
|
| 53 |
+
# .gitignoreに一致するディレクトリを無視
|
| 54 |
+
dirs[:] = [d for d in dirs if not any(fnmatch.fnmatch(d, pattern) for pattern in ignore_patterns)]
|
| 55 |
+
|
| 56 |
+
level = root.replace(repo_path, "").count(os.sep)
|
| 57 |
+
indent = " " * 4 * (level)
|
| 58 |
+
file_tree += f"{indent}{os.path.basename(root)}/\n"
|
| 59 |
+
subindent = " " * 4 * (level + 1)
|
| 60 |
+
for f in files:
|
| 61 |
+
# .gitignoreに一致するファイルを無視
|
| 62 |
+
if not any(fnmatch.fnmatch(f, pattern) for pattern in ignore_patterns):
|
| 63 |
+
file_tree += f"{subindent}{f}\n"
|
| 64 |
+
|
| 65 |
+
# マークダウンファイルを結合
|
| 66 |
+
markdown_content = f"# << {repo_name}>> \n## {repo_name} File Tree\n\n```\n{file_tree}\n```\n\n"
|
| 67 |
+
|
| 68 |
+
# 拡張子と言語のマッピングを読み込む
|
| 69 |
+
with open("docs/language_map.json", "r") as f:
|
| 70 |
+
language_map = json.load(f)
|
| 71 |
+
|
| 72 |
+
for root, dirs, files in os.walk(repo_path):
|
| 73 |
+
# .gitignoreに一致するディレクトリを無視
|
| 74 |
+
dirs[:] = [d for d in dirs if not any(fnmatch.fnmatch(d, pattern) for pattern in ignore_patterns)]
|
| 75 |
+
for file in files:
|
| 76 |
+
# .gitignoreに一致するファイルを無視
|
| 77 |
+
if not any(fnmatch.fnmatch(file, pattern) for pattern in ignore_patterns):
|
| 78 |
+
file_path = os.path.join(root, file)
|
| 79 |
+
_, file_extension = os.path.splitext(file)
|
| 80 |
+
language = language_map.get(file_extension, "")
|
| 81 |
+
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
|
| 82 |
+
content = f.read()
|
| 83 |
+
# コードブロック内のコードブロックの範囲の全行の先頭に2つのスペースを入れる
|
| 84 |
+
lines = content.split("\n")
|
| 85 |
+
modified_lines = []
|
| 86 |
+
inside_code_block = False
|
| 87 |
+
for line in lines:
|
| 88 |
+
if line.startswith("```"):
|
| 89 |
+
inside_code_block = not inside_code_block
|
| 90 |
modified_lines.append("\t" + line)
|
| 91 |
else:
|
| 92 |
+
if inside_code_block:
|
| 93 |
+
modified_lines.append("\t" + line)
|
| 94 |
+
else:
|
| 95 |
+
modified_lines.append(line)
|
| 96 |
+
content = "\n".join(modified_lines)
|
| 97 |
+
# コードブロックの中のバッククォートをエスケープ
|
| 98 |
+
markdown_content += f"## {file_path.replace(f'{repo_path}/', '')}\n\n```{language}\n{content}\n```\n\n"
|
| 99 |
+
|
| 100 |
+
# マークダウンファイルを保存
|
| 101 |
+
with open(f"{repo_name}.md", "w", encoding="utf-8") as f:
|
| 102 |
+
f.write(markdown_content)
|
| 103 |
|
| 104 |
+
# Streamlitアプリケーションの構築
|
| 105 |
+
st.markdown(markdown_content, unsafe_allow_html=True)
|
|
|
|
| 106 |
|
| 107 |
+
# ダウンロードリンクの作成
|
| 108 |
+
st.markdown(f'<a href="data:text/markdown;base64,{base64.b64encode(markdown_content.encode("utf-8")).decode("utf-8")}" download="{repo_name}.md">Download Markdown File</a>', unsafe_allow_html=True)
|
|
|
|
| 109 |
|
| 110 |
+
st.markdown("---")
|
| 111 |
+
st.markdown("# Full Text")
|
| 112 |
+
st.code(markdown_content)
|
docs/page_front.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<p align="center">
|
| 2 |
+
<img src="https://media.githubusercontent.com/media/Sunwood-ai-labs/CodeLumia/main/docs/CodeLumia_icon.png" width="40%">
|
| 3 |
+
<br>
|
| 4 |
+
<h1 align="center">CodeLumia</h1>
|
| 5 |
+
<h3 align="center">
|
| 6 |
+
~Learn to Code, Step by Step~
|
| 7 |
+
|
| 8 |
+
[](https://huggingface.co/spaces/OFA-Sys/OFA-Image_Caption)[](https://github.com/Sunwood-ai-labs/CodeLumia)[](https://github.com/Sunwood-ai-labs/CodeLumia)[](https://github.com/Sunwood-ai-labs/CodeLumia)
|
| 9 |
+
|
| 10 |
+
</h3>
|
| 11 |
+
|
| 12 |
+
</p>
|