codelion commited on
Commit
1f3d4e4
Β·
verified Β·
1 Parent(s): 05aecc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -38
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
- if github_token:
56
- os.environ["GITHUB_TOKEN"] = github_token
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
- print(f"Analyzing repository: {repo_url}")
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
- print(f"Cloned repository to: {repo_path}")
86
 
87
- progress_md += "πŸ”¬ Analyzing code structure... \n"
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
- print("Code analysis complete")
92
 
93
- progress_md += f"πŸ“Š Analyzing issues (max {max_issues})... \n"
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
- print("Issues analysis complete")
98
 
99
- progress_md += f"πŸ”€ Analyzing pull requests (max {max_prs})... \n"
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
- print("Pull requests analysis complete")
104
 
105
- progress_md += "🧠 Synthesizing findings... \n"
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
- print("Findings synthesized")
114
 
115
  repo_info = {
116
  "owner": owner,
117
  "repo_name": repo_name,
118
  }
119
 
120
- progress_md += "πŸ“ Generating report... \n"
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
- print("Report generated")
124
 
125
- print("Analysis complete, returning results")
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
- return progress_md + error_message, gr.update(visible=True), gr.update(visible=False)
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
- progress_output = gr.Markdown(label="Progress")
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=[progress_output, progress_output, report_output],
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