Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -52,25 +52,27 @@ def generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, fina
|
|
52 |
"""
|
53 |
|
54 |
def analyze_github_repo(repo_input, github_token=None):
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
github_token = os.environ.get("GITHUB_TOKEN")
|
59 |
-
if not github_token:
|
60 |
-
print("GitHub token not found")
|
61 |
-
return "β Error: GITHUB_TOKEN environment variable not set.", gr.update(visible=True), gr.update(visible=False)
|
62 |
-
|
63 |
-
openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")
|
64 |
-
if not openrouter_api_key:
|
65 |
-
print("OpenRouter API key not found")
|
66 |
-
return "β Error: OPENROUTER_API_KEY environment variable not set.", gr.update(visible=True), gr.update(visible=False)
|
67 |
|
68 |
-
progress_md = ""
|
69 |
-
|
70 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
owner, repo_name = get_repo_info(repo_input)
|
72 |
repo_url = f"https://github.com/{owner}/{repo_name}"
|
73 |
-
|
74 |
|
75 |
g = Github(github_token)
|
76 |
github_repo = g.get_repo(f"{owner}/{repo_name}")
|
@@ -82,53 +84,46 @@ def analyze_github_repo(repo_input, github_token=None):
|
|
82 |
|
83 |
with tempfile.TemporaryDirectory() as temp_dir:
|
84 |
repo_path = clone_repo(owner, repo_name, temp_dir)
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
89 |
code_analysis = analyze_code(repo_path)
|
90 |
code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
|
91 |
-
|
92 |
|
93 |
-
|
94 |
-
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
95 |
issues_data = analyze_issues(github_repo, max_issues)
|
96 |
issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
|
97 |
-
|
98 |
|
99 |
-
|
100 |
-
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
101 |
prs_data = analyze_pull_requests(github_repo, max_prs)
|
102 |
pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
107 |
final_analysis = llm_synthesize_findings(
|
108 |
client,
|
109 |
code_analysis.get('llm_analysis', ''),
|
110 |
issues_analysis.get('summary', ''),
|
111 |
pr_analysis.get('summary', '')
|
112 |
)
|
113 |
-
|
114 |
|
115 |
repo_info = {
|
116 |
"owner": owner,
|
117 |
"repo_name": repo_name,
|
118 |
}
|
119 |
|
120 |
-
|
121 |
-
yield progress_md, gr.update(visible=True), gr.update(visible=False)
|
122 |
report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
return progress_md + "β
Analysis complete!", gr.update(visible=False), gr.update(visible=True, value=report)
|
127 |
except Exception as e:
|
128 |
error_message = f"β An error occurred: {str(e)}"
|
129 |
-
print(f"Error occurred: {error_message}")
|
130 |
traceback.print_exc()
|
131 |
-
|
132 |
|
133 |
# Define the Gradio interface
|
134 |
with gr.Blocks() as app:
|
@@ -141,13 +136,12 @@ with gr.Blocks() as app:
|
|
141 |
|
142 |
analyze_button = gr.Button("Analyze Repository")
|
143 |
|
144 |
-
|
145 |
-
report_output = gr.Markdown(label="Analysis Report", visible=False)
|
146 |
|
147 |
analyze_button.click(
|
148 |
analyze_github_repo,
|
149 |
inputs=[repo_input, github_token],
|
150 |
-
outputs=
|
151 |
)
|
152 |
|
153 |
# Launch the app
|
|
|
52 |
"""
|
53 |
|
54 |
def analyze_github_repo(repo_input, github_token=None):
|
55 |
+
def update_output(message):
|
56 |
+
print(message) # Console log
|
57 |
+
return message # Update Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
|
|
|
|
59 |
try:
|
60 |
+
if github_token:
|
61 |
+
os.environ["GITHUB_TOKEN"] = github_token
|
62 |
+
|
63 |
+
github_token = os.environ.get("GITHUB_TOKEN")
|
64 |
+
if not github_token:
|
65 |
+
return update_output("β Error: GITHUB_TOKEN environment variable not set.")
|
66 |
+
|
67 |
+
openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")
|
68 |
+
if not openrouter_api_key:
|
69 |
+
return update_output("β Error: OPENROUTER_API_KEY environment variable not set.")
|
70 |
+
|
71 |
+
yield update_output("π Starting analysis...")
|
72 |
+
|
73 |
owner, repo_name = get_repo_info(repo_input)
|
74 |
repo_url = f"https://github.com/{owner}/{repo_name}"
|
75 |
+
yield update_output(f"π Analyzing repository: {repo_url}")
|
76 |
|
77 |
g = Github(github_token)
|
78 |
github_repo = g.get_repo(f"{owner}/{repo_name}")
|
|
|
84 |
|
85 |
with tempfile.TemporaryDirectory() as temp_dir:
|
86 |
repo_path = clone_repo(owner, repo_name, temp_dir)
|
87 |
+
yield update_output(f"π Cloned repository to temporary directory")
|
88 |
|
89 |
+
yield update_output("π¬ Analyzing code structure...")
|
|
|
90 |
code_analysis = analyze_code(repo_path)
|
91 |
code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
|
92 |
+
yield update_output("β
Code analysis complete")
|
93 |
|
94 |
+
yield update_output(f"π Analyzing issues (max {max_issues})...")
|
|
|
95 |
issues_data = analyze_issues(github_repo, max_issues)
|
96 |
issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
|
97 |
+
yield update_output("β
Issues analysis complete")
|
98 |
|
99 |
+
yield update_output(f"π Analyzing pull requests (max {max_prs})...")
|
|
|
100 |
prs_data = analyze_pull_requests(github_repo, max_prs)
|
101 |
pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
|
102 |
+
yield update_output("β
Pull requests analysis complete")
|
103 |
|
104 |
+
yield update_output("π§ Synthesizing findings...")
|
|
|
105 |
final_analysis = llm_synthesize_findings(
|
106 |
client,
|
107 |
code_analysis.get('llm_analysis', ''),
|
108 |
issues_analysis.get('summary', ''),
|
109 |
pr_analysis.get('summary', '')
|
110 |
)
|
111 |
+
yield update_output("β
Findings synthesized")
|
112 |
|
113 |
repo_info = {
|
114 |
"owner": owner,
|
115 |
"repo_name": repo_name,
|
116 |
}
|
117 |
|
118 |
+
yield update_output("π Generating report...")
|
|
|
119 |
report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
|
120 |
+
yield update_output("β
Report generated")
|
121 |
|
122 |
+
yield update_output("π Analysis complete! Here's the report:\n\n" + report)
|
|
|
123 |
except Exception as e:
|
124 |
error_message = f"β An error occurred: {str(e)}"
|
|
|
125 |
traceback.print_exc()
|
126 |
+
yield update_output(error_message)
|
127 |
|
128 |
# Define the Gradio interface
|
129 |
with gr.Blocks() as app:
|
|
|
136 |
|
137 |
analyze_button = gr.Button("Analyze Repository")
|
138 |
|
139 |
+
output = gr.Markdown(label="Analysis Output")
|
|
|
140 |
|
141 |
analyze_button.click(
|
142 |
analyze_github_repo,
|
143 |
inputs=[repo_input, github_token],
|
144 |
+
outputs=output,
|
145 |
)
|
146 |
|
147 |
# Launch the app
|