Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import time
|
4 |
-
import markdown
|
5 |
import tempfile
|
6 |
import traceback
|
7 |
from github_repo_analyzer import get_repo_info, clone_repo, analyze_code, analyze_issues, analyze_pull_requests, llm_analyze_code, llm_analyze_issues, llm_analyze_prs, llm_synthesize_findings, generate_report
|
@@ -30,13 +29,13 @@ def analyze_github_repo(repo_input, github_token=None):
|
|
30 |
if not openrouter_api_key:
|
31 |
return "β Error: OPENROUTER_API_KEY environment variable not set.", gr.update(visible=True), gr.update(visible=False)
|
32 |
|
33 |
-
|
34 |
-
yield
|
35 |
|
36 |
for emoji, message in PROGRESS_STEPS:
|
37 |
-
|
38 |
-
yield
|
39 |
-
time.sleep(
|
40 |
|
41 |
try:
|
42 |
owner, repo_name = get_repo_info(repo_input)
|
@@ -53,23 +52,23 @@ def analyze_github_repo(repo_input, github_token=None):
|
|
53 |
with tempfile.TemporaryDirectory() as temp_dir:
|
54 |
repo_path = clone_repo(owner, repo_name, temp_dir)
|
55 |
|
56 |
-
|
57 |
-
yield
|
58 |
code_analysis = analyze_code(repo_path)
|
59 |
code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
|
60 |
|
61 |
-
|
62 |
-
yield
|
63 |
issues_data = analyze_issues(github_repo, max_issues)
|
64 |
issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
|
65 |
|
66 |
-
|
67 |
-
yield
|
68 |
prs_data = analyze_pull_requests(github_repo, max_prs)
|
69 |
pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
|
70 |
|
71 |
-
|
72 |
-
yield
|
73 |
final_analysis = llm_synthesize_findings(
|
74 |
client,
|
75 |
code_analysis.get('llm_analysis', ''),
|
@@ -82,19 +81,16 @@ def analyze_github_repo(repo_input, github_token=None):
|
|
82 |
"repo_name": repo_name,
|
83 |
}
|
84 |
|
85 |
-
|
86 |
-
yield
|
87 |
report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
|
88 |
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
-
# Return the final HTML report
|
93 |
-
return progress_html + "β
Analysis complete!", gr.update(visible=False), gr.update(visible=True, value=html_report)
|
94 |
except Exception as e:
|
95 |
error_message = f"β An error occurred: {str(e)}"
|
96 |
traceback.print_exc()
|
97 |
-
return
|
98 |
|
99 |
# Define the Gradio interface
|
100 |
with gr.Blocks() as app:
|
@@ -107,8 +103,8 @@ with gr.Blocks() as app:
|
|
107 |
|
108 |
analyze_button = gr.Button("Analyze Repository")
|
109 |
|
110 |
-
progress_output = gr.
|
111 |
-
report_output = gr.
|
112 |
|
113 |
analyze_button.click(
|
114 |
analyze_github_repo,
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import time
|
|
|
4 |
import tempfile
|
5 |
import traceback
|
6 |
from github_repo_analyzer import get_repo_info, clone_repo, analyze_code, analyze_issues, analyze_pull_requests, llm_analyze_code, llm_analyze_issues, llm_analyze_prs, llm_synthesize_findings, generate_report
|
|
|
29 |
if not openrouter_api_key:
|
30 |
return "β Error: OPENROUTER_API_KEY environment variable not set.", gr.update(visible=True), gr.update(visible=False)
|
31 |
|
32 |
+
progress_md = ""
|
33 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False) # Initial empty output
|
34 |
|
35 |
for emoji, message in PROGRESS_STEPS:
|
36 |
+
progress_md += f"{emoji} {message} \n"
|
37 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
38 |
+
time.sleep(4)
|
39 |
|
40 |
try:
|
41 |
owner, repo_name = get_repo_info(repo_input)
|
|
|
52 |
with tempfile.TemporaryDirectory() as temp_dir:
|
53 |
repo_path = clone_repo(owner, repo_name, temp_dir)
|
54 |
|
55 |
+
progress_md += "π¬ Analyzing code structure... \n"
|
56 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
57 |
code_analysis = analyze_code(repo_path)
|
58 |
code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
|
59 |
|
60 |
+
progress_md += f"π Analyzing issues (max {max_issues})... \n"
|
61 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
62 |
issues_data = analyze_issues(github_repo, max_issues)
|
63 |
issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
|
64 |
|
65 |
+
progress_md += f"π Analyzing pull requests (max {max_prs})... \n"
|
66 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
67 |
prs_data = analyze_pull_requests(github_repo, max_prs)
|
68 |
pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
|
69 |
|
70 |
+
progress_md += "π§ Synthesizing findings... \n"
|
71 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
72 |
final_analysis = llm_synthesize_findings(
|
73 |
client,
|
74 |
code_analysis.get('llm_analysis', ''),
|
|
|
81 |
"repo_name": repo_name,
|
82 |
}
|
83 |
|
84 |
+
progress_md += "π Generating report... \n"
|
85 |
+
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
86 |
report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
|
87 |
|
88 |
+
# Return the final Markdown report
|
89 |
+
return progress_md + "β
Analysis complete!", gr.update(visible=False), gr.update(visible=True, value=report)
|
|
|
|
|
|
|
90 |
except Exception as e:
|
91 |
error_message = f"β An error occurred: {str(e)}"
|
92 |
traceback.print_exc()
|
93 |
+
return progress_md + error_message, gr.update(visible=True), gr.update(visible=False)
|
94 |
|
95 |
# Define the Gradio interface
|
96 |
with gr.Blocks() as app:
|
|
|
103 |
|
104 |
analyze_button = gr.Button("Analyze Repository")
|
105 |
|
106 |
+
progress_output = gr.Markdown(label="Progress")
|
107 |
+
report_output = gr.Markdown(label="Analysis Report", visible=False)
|
108 |
|
109 |
analyze_button.click(
|
110 |
analyze_github_repo,
|