Spaces:
Sleeping
Sleeping
hi
Browse files- app.py +12 -12
- repo_explorer.py +16 -18
app.py
CHANGED
@@ -382,13 +382,13 @@ def create_ui() -> gr.Blocks:
|
|
382 |
status_box_analysis = gr.Textbox(label="π Analysis Status", interactive=False, lines=2)
|
383 |
|
384 |
with gr.Row(equal_height=True):
|
385 |
-
with gr.Column():
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
with gr.Column():
|
393 |
summary_output = gr.Textbox(
|
394 |
label="π― AI Analysis Summary",
|
@@ -510,12 +510,12 @@ def create_ui() -> gr.Blocks:
|
|
510 |
requirements = "\n".join([f"- {msg}" for msg in user_messages if msg.strip()])
|
511 |
return requirements
|
512 |
|
513 |
-
def handle_analyze_next(repo_ids: List[str], current_idx: int, user_requirements: str) -> Tuple[str,
|
514 |
"""Analyzes the next repository in the list."""
|
515 |
if not repo_ids:
|
516 |
-
return "",
|
517 |
if current_idx >= len(repo_ids):
|
518 |
-
return "",
|
519 |
|
520 |
repo_id_to_analyze = repo_ids[current_idx]
|
521 |
status = f"Status: Analyzing repository {current_idx + 1}/{len(repo_ids)}: {repo_id_to_analyze}"
|
@@ -528,7 +528,7 @@ def create_ui() -> gr.Blocks:
|
|
528 |
if next_idx >= len(repo_ids):
|
529 |
status += "\n\nFinished all analyses."
|
530 |
|
531 |
-
return
|
532 |
|
533 |
def handle_user_message(user_message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
534 |
"""Appends the user's message to the history, preparing for the bot's response."""
|
@@ -645,7 +645,7 @@ def create_ui() -> gr.Blocks:
|
|
645 |
analyze_next_btn.click(
|
646 |
fn=handle_analyze_next,
|
647 |
inputs=[repo_ids_state, current_repo_idx_state, user_requirements_state],
|
648 |
-
outputs=[
|
649 |
)
|
650 |
|
651 |
# Chatbot Tab
|
|
|
382 |
status_box_analysis = gr.Textbox(label="π Analysis Status", interactive=False, lines=2)
|
383 |
|
384 |
with gr.Row(equal_height=True):
|
385 |
+
# with gr.Column():
|
386 |
+
# content_output = gr.Textbox(
|
387 |
+
# label="π Repository Content",
|
388 |
+
# lines=20,
|
389 |
+
# show_copy_button=True,
|
390 |
+
# info="Raw content extracted from the repository"
|
391 |
+
# )
|
392 |
with gr.Column():
|
393 |
summary_output = gr.Textbox(
|
394 |
label="π― AI Analysis Summary",
|
|
|
510 |
requirements = "\n".join([f"- {msg}" for msg in user_messages if msg.strip()])
|
511 |
return requirements
|
512 |
|
513 |
+
def handle_analyze_next(repo_ids: List[str], current_idx: int, user_requirements: str) -> Tuple[str, pd.DataFrame, int, str]:
|
514 |
"""Analyzes the next repository in the list."""
|
515 |
if not repo_ids:
|
516 |
+
return "", pd.DataFrame(), 0, "Status: No repositories to analyze. Please submit repo IDs first."
|
517 |
if current_idx >= len(repo_ids):
|
518 |
+
return "", read_csv_to_dataframe(), current_idx, "Status: All repositories have been analyzed."
|
519 |
|
520 |
repo_id_to_analyze = repo_ids[current_idx]
|
521 |
status = f"Status: Analyzing repository {current_idx + 1}/{len(repo_ids)}: {repo_id_to_analyze}"
|
|
|
528 |
if next_idx >= len(repo_ids):
|
529 |
status += "\n\nFinished all analyses."
|
530 |
|
531 |
+
return summary, df, next_idx, status
|
532 |
|
533 |
def handle_user_message(user_message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
534 |
"""Appends the user's message to the history, preparing for the bot's response."""
|
|
|
645 |
analyze_next_btn.click(
|
646 |
fn=handle_analyze_next,
|
647 |
inputs=[repo_ids_state, current_repo_idx_state, user_requirements_state],
|
648 |
+
outputs=[summary_output, df_output, current_repo_idx_state, status_box_analysis]
|
649 |
)
|
650 |
|
651 |
# Chatbot Tab
|
repo_explorer.py
CHANGED
@@ -155,7 +155,7 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
155 |
with gr.Column(scale=2):
|
156 |
repo_chatbot = gr.Chatbot(
|
157 |
label="π€ Repository Assistant",
|
158 |
-
height=
|
159 |
type="messages",
|
160 |
avatar_images=(
|
161 |
"https://cdn-icons-png.flaticon.com/512/149/149071.png",
|
@@ -175,14 +175,15 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
175 |
)
|
176 |
repo_send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
177 |
|
178 |
-
with gr.Column(scale=1):
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
186 |
|
187 |
# Component references
|
188 |
components = {
|
@@ -192,15 +193,15 @@ def create_repo_explorer_tab() -> Tuple[Dict[str, gr.components.Component], Dict
|
|
192 |
"repo_chatbot": repo_chatbot,
|
193 |
"repo_msg_input": repo_msg_input,
|
194 |
"repo_send_btn": repo_send_btn,
|
195 |
-
"repo_content_display": repo_content_display
|
196 |
}
|
197 |
|
198 |
return components, states
|
199 |
|
200 |
-
def handle_load_repository(repo_id: str) -> Tuple[str, str
|
201 |
"""Load a specific repository and prepare it for exploration with chunk-based analysis."""
|
202 |
if not repo_id.strip():
|
203 |
-
return "
|
204 |
|
205 |
try:
|
206 |
logger.info(f"Loading repository for exploration: {repo_id}")
|
@@ -212,9 +213,6 @@ def handle_load_repository(repo_id: str) -> Tuple[str, str, str]:
|
|
212 |
with open(txt_path, "r", encoding="utf-8") as f:
|
213 |
repo_content = f.read()
|
214 |
|
215 |
-
# Create a preview (first 2000 characters)
|
216 |
-
preview = repo_content[:2000] + "..." if len(repo_content) > 2000 else repo_content
|
217 |
-
|
218 |
status = f"β
Repository '{repo_id}' loaded successfully!\nπ Files processed and ready for exploration.\nπ Analyzing repository in chunks for comprehensive context...\nπ¬ You can now ask questions about this repository."
|
219 |
|
220 |
# Create comprehensive context summary using chunk analysis
|
@@ -222,12 +220,12 @@ def handle_load_repository(repo_id: str) -> Tuple[str, str, str]:
|
|
222 |
context_summary = create_repo_context_summary(repo_content, repo_id)
|
223 |
|
224 |
logger.info(f"Repository {repo_id} loaded and analyzed successfully for exploration")
|
225 |
-
return status,
|
226 |
|
227 |
except Exception as e:
|
228 |
logger.error(f"Error loading repository {repo_id}: {e}")
|
229 |
error_status = f"β Error loading repository: {e}"
|
230 |
-
return error_status, ""
|
231 |
|
232 |
def handle_repo_user_message(user_message: str, history: List[Dict[str, str]], repo_context_summary: str, repo_id: str) -> Tuple[List[Dict[str, str]], str]:
|
233 |
"""Handle user messages in the repo-specific chatbot."""
|
@@ -300,7 +298,7 @@ def setup_repo_explorer_events(components: Dict[str, gr.components.Component], s
|
|
300 |
components["load_repo_btn"].click(
|
301 |
fn=handle_load_repository,
|
302 |
inputs=[components["repo_explorer_input"]],
|
303 |
-
outputs=[components["repo_status_display"],
|
304 |
).then(
|
305 |
fn=lambda repo_id: repo_id,
|
306 |
inputs=[components["repo_explorer_input"]],
|
|
|
155 |
with gr.Column(scale=2):
|
156 |
repo_chatbot = gr.Chatbot(
|
157 |
label="π€ Repository Assistant",
|
158 |
+
height=400,
|
159 |
type="messages",
|
160 |
avatar_images=(
|
161 |
"https://cdn-icons-png.flaticon.com/512/149/149071.png",
|
|
|
175 |
)
|
176 |
repo_send_btn = gr.Button("π€ Send", variant="primary", scale=1)
|
177 |
|
178 |
+
# with gr.Column(scale=1):
|
179 |
+
# # Repository content preview
|
180 |
+
# repo_content_display = gr.Textbox(
|
181 |
+
# label="π Repository Content Preview",
|
182 |
+
# lines=20,
|
183 |
+
# show_copy_button=True,
|
184 |
+
# interactive=False,
|
185 |
+
# info="Overview of the loaded repository structure and content"
|
186 |
+
# )
|
187 |
|
188 |
# Component references
|
189 |
components = {
|
|
|
193 |
"repo_chatbot": repo_chatbot,
|
194 |
"repo_msg_input": repo_msg_input,
|
195 |
"repo_send_btn": repo_send_btn,
|
196 |
+
# "repo_content_display": repo_content_display
|
197 |
}
|
198 |
|
199 |
return components, states
|
200 |
|
201 |
+
def handle_load_repository(repo_id: str) -> Tuple[str, str]:
|
202 |
"""Load a specific repository and prepare it for exploration with chunk-based analysis."""
|
203 |
if not repo_id.strip():
|
204 |
+
return "Status: Please enter a repository ID.", ""
|
205 |
|
206 |
try:
|
207 |
logger.info(f"Loading repository for exploration: {repo_id}")
|
|
|
213 |
with open(txt_path, "r", encoding="utf-8") as f:
|
214 |
repo_content = f.read()
|
215 |
|
|
|
|
|
|
|
216 |
status = f"β
Repository '{repo_id}' loaded successfully!\nπ Files processed and ready for exploration.\nπ Analyzing repository in chunks for comprehensive context...\nπ¬ You can now ask questions about this repository."
|
217 |
|
218 |
# Create comprehensive context summary using chunk analysis
|
|
|
220 |
context_summary = create_repo_context_summary(repo_content, repo_id)
|
221 |
|
222 |
logger.info(f"Repository {repo_id} loaded and analyzed successfully for exploration")
|
223 |
+
return status, context_summary
|
224 |
|
225 |
except Exception as e:
|
226 |
logger.error(f"Error loading repository {repo_id}: {e}")
|
227 |
error_status = f"β Error loading repository: {e}"
|
228 |
+
return error_status, ""
|
229 |
|
230 |
def handle_repo_user_message(user_message: str, history: List[Dict[str, str]], repo_context_summary: str, repo_id: str) -> Tuple[List[Dict[str, str]], str]:
|
231 |
"""Handle user messages in the repo-specific chatbot."""
|
|
|
298 |
components["load_repo_btn"].click(
|
299 |
fn=handle_load_repository,
|
300 |
inputs=[components["repo_explorer_input"]],
|
301 |
+
outputs=[components["repo_status_display"], states["repo_context_summary"]]
|
302 |
).then(
|
303 |
fn=lambda repo_id: repo_id,
|
304 |
inputs=[components["repo_explorer_input"]],
|