Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,15 +40,6 @@ st.markdown("""
|
|
40 |
background-color: #0e1117;
|
41 |
color: #ffffff;
|
42 |
}
|
43 |
-
.chat-message {
|
44 |
-
padding: 1rem;
|
45 |
-
margin: 1rem 0;
|
46 |
-
border-radius: 0.5rem;
|
47 |
-
}
|
48 |
-
.assistant-message {
|
49 |
-
background-color: #1e2329;
|
50 |
-
color: #ffffff;
|
51 |
-
}
|
52 |
.directory-structure {
|
53 |
font-family: monospace;
|
54 |
white-space: pre;
|
@@ -57,13 +48,11 @@ st.markdown("""
|
|
57 |
border-radius: 0.5rem;
|
58 |
margin: 1rem 0;
|
59 |
}
|
60 |
-
.
|
61 |
background-color: #1e2329;
|
62 |
padding: 1rem;
|
63 |
border-radius: 0.5rem;
|
64 |
margin: 1rem 0;
|
65 |
-
max-height: 500px;
|
66 |
-
overflow-y: auto;
|
67 |
}
|
68 |
</style>
|
69 |
""", unsafe_allow_html=True)
|
@@ -71,12 +60,10 @@ st.markdown("""
|
|
71 |
# セッション状態の初期化
|
72 |
if 'repo_content' not in st.session_state:
|
73 |
st.session_state.repo_content = None
|
74 |
-
if 'directory_structure' not in st.session_state:
|
75 |
-
st.session_state.directory_structure = None
|
76 |
-
if 'content_md' not in st.session_state:
|
77 |
-
st.session_state.content_md = None
|
78 |
if 'structure_md' not in st.session_state:
|
79 |
st.session_state.structure_md = None
|
|
|
|
|
80 |
if 'temp_dir' not in st.session_state:
|
81 |
st.session_state.temp_dir = None
|
82 |
if 'llm_service' not in st.session_state:
|
@@ -91,7 +78,7 @@ if 'llm_service' not in st.session_state:
|
|
91 |
st.stop()
|
92 |
|
93 |
# メインのUIレイアウト
|
94 |
-
st.title("🔍
|
95 |
|
96 |
# サイドバーの設定
|
97 |
with st.sidebar:
|
@@ -100,9 +87,8 @@ with st.sidebar:
|
|
100 |
1. GitHubリポジトリのURLを入力
|
101 |
2. スキャン対象の拡張子を選択
|
102 |
3. スキャンを実行
|
103 |
-
4.
|
104 |
-
5.
|
105 |
-
6. コードについて質問
|
106 |
""")
|
107 |
|
108 |
# スキャン対象の拡張子選択
|
@@ -157,68 +143,35 @@ if st.button("スキャン開始", disabled=not repo_url):
|
|
157 |
|
158 |
st.success(f"スキャン完了: {len(files)}個のファイルを検出")
|
159 |
|
160 |
-
st.session_state.llm_service.clear_history()
|
161 |
-
|
162 |
except Exception as e:
|
163 |
st.error(f"エラーが発生しました: {str(e)}")
|
164 |
|
165 |
-
#
|
166 |
if st.session_state.structure_md and st.session_state.content_md:
|
167 |
-
|
|
|
|
|
|
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
|
|
|
|
173 |
st.download_button(
|
174 |
-
label="ディレクトリ構造をダウンロード",
|
175 |
data=st.session_state.structure_md,
|
176 |
file_name=f"directory_structure_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
|
177 |
mime="text/markdown"
|
178 |
)
|
179 |
|
180 |
-
with
|
181 |
-
st.markdown(f'<div class="markdown-preview">{st.session_state.content_md}</div>',
|
182 |
-
unsafe_allow_html=True)
|
183 |
-
|
184 |
st.download_button(
|
185 |
-
label="ファイル内容をダウンロード",
|
186 |
data=st.session_state.content_md,
|
187 |
file_name=f"repository_content_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
|
188 |
mime="text/markdown"
|
189 |
)
|
190 |
-
|
191 |
-
# 質問セクション
|
192 |
-
if st.session_state.repo_content:
|
193 |
-
st.divider()
|
194 |
-
st.subheader("💭 コードについて質問する")
|
195 |
|
196 |
-
|
197 |
-
for message in st.session_state.llm_service.conversation_history:
|
198 |
-
if message.role == "assistant":
|
199 |
-
st.markdown(f'<div class="chat-message assistant-message">{message.content}</div>',
|
200 |
-
unsafe_allow_html=True)
|
201 |
-
|
202 |
-
query = st.text_area(
|
203 |
-
"質問を入力してください",
|
204 |
-
placeholder="例: このコードの主な機能は何ですか?"
|
205 |
-
)
|
206 |
-
|
207 |
-
col1, col2 = st.columns([1, 5])
|
208 |
-
with col1:
|
209 |
-
if st.button("履歴クリア"):
|
210 |
-
st.session_state.llm_service.clear_history()
|
211 |
-
st.rerun()
|
212 |
-
|
213 |
-
with col2:
|
214 |
-
if st.button("質問する", disabled=not query):
|
215 |
-
with st.spinner('回答を生成中...'):
|
216 |
-
response, error = st.session_state.llm_service.get_response(
|
217 |
-
st.session_state.repo_content,
|
218 |
-
query
|
219 |
-
)
|
220 |
-
|
221 |
-
if error:
|
222 |
-
st.error(error)
|
223 |
-
else:
|
224 |
-
st.rerun()
|
|
|
40 |
background-color: #0e1117;
|
41 |
color: #ffffff;
|
42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
.directory-structure {
|
44 |
font-family: monospace;
|
45 |
white-space: pre;
|
|
|
48 |
border-radius: 0.5rem;
|
49 |
margin: 1rem 0;
|
50 |
}
|
51 |
+
.download-section {
|
52 |
background-color: #1e2329;
|
53 |
padding: 1rem;
|
54 |
border-radius: 0.5rem;
|
55 |
margin: 1rem 0;
|
|
|
|
|
56 |
}
|
57 |
</style>
|
58 |
""", unsafe_allow_html=True)
|
|
|
60 |
# セッション状態の初期化
|
61 |
if 'repo_content' not in st.session_state:
|
62 |
st.session_state.repo_content = None
|
|
|
|
|
|
|
|
|
63 |
if 'structure_md' not in st.session_state:
|
64 |
st.session_state.structure_md = None
|
65 |
+
if 'content_md' not in st.session_state:
|
66 |
+
st.session_state.content_md = None
|
67 |
if 'temp_dir' not in st.session_state:
|
68 |
st.session_state.temp_dir = None
|
69 |
if 'llm_service' not in st.session_state:
|
|
|
78 |
st.stop()
|
79 |
|
80 |
# メインのUIレイアウト
|
81 |
+
st.title("🔍 リポジトリ解析システム")
|
82 |
|
83 |
# サイドバーの設定
|
84 |
with st.sidebar:
|
|
|
87 |
1. GitHubリポジトリのURLを入力
|
88 |
2. スキャン対象の拡張子を選択
|
89 |
3. スキャンを実行
|
90 |
+
4. ディレクトリ構造を確認
|
91 |
+
5. 解析結果をダウンロード
|
|
|
92 |
""")
|
93 |
|
94 |
# スキャン対象の拡張子選択
|
|
|
143 |
|
144 |
st.success(f"スキャン完了: {len(files)}個のファイルを検出")
|
145 |
|
|
|
|
|
146 |
except Exception as e:
|
147 |
st.error(f"エラーが発生しました: {str(e)}")
|
148 |
|
149 |
+
# スキャン結果の表示とダウンロード
|
150 |
if st.session_state.structure_md and st.session_state.content_md:
|
151 |
+
# ディレクトリ構造の表示
|
152 |
+
st.subheader("📁 ディレクトリ構造")
|
153 |
+
st.markdown(f'<div class="directory-structure">{st.session_state.structure_md}</div>',
|
154 |
+
unsafe_allow_html=True)
|
155 |
|
156 |
+
# ダウンロードセクション
|
157 |
+
st.subheader("📥 解析結果のダウンロード")
|
158 |
+
st.markdown('<div class="download-section">', unsafe_allow_html=True)
|
159 |
+
|
160 |
+
col1, col2 = st.columns(2)
|
161 |
+
with col1:
|
162 |
st.download_button(
|
163 |
+
label="📁 ディレクトリ構造をダウンロード",
|
164 |
data=st.session_state.structure_md,
|
165 |
file_name=f"directory_structure_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
|
166 |
mime="text/markdown"
|
167 |
)
|
168 |
|
169 |
+
with col2:
|
|
|
|
|
|
|
170 |
st.download_button(
|
171 |
+
label="📄 ファイル内容をダウンロード",
|
172 |
data=st.session_state.content_md,
|
173 |
file_name=f"repository_content_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
|
174 |
mime="text/markdown"
|
175 |
)
|
|
|
|
|
|
|
|
|
|
|
176 |
|
177 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|