codelion commited on
Commit
d6b7027
β€’
1 Parent(s): 86d1445

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -5
app.py CHANGED
@@ -2,7 +2,11 @@ import gradio as gr
2
  import os
3
  import time
4
  import markdown
5
- from github_repo_analyzer import main as analyze_repo, get_repo_info
 
 
 
 
6
 
7
  # Emojis and fun statements for progress updates
8
  PROGRESS_STEPS = [
@@ -18,6 +22,14 @@ def analyze_github_repo(repo_input, github_token=None):
18
  if github_token:
19
  os.environ["GITHUB_TOKEN"] = github_token
20
 
 
 
 
 
 
 
 
 
21
  progress_html = ""
22
  yield progress_html, "" # Initial empty output
23
 
@@ -28,17 +40,59 @@ def analyze_github_repo(repo_input, github_token=None):
28
 
29
  try:
30
  owner, repo_name = get_repo_info(repo_input)
31
- max_issues = 10
32
- max_prs = 10
33
 
34
- report = analyze_repo(repo_input, max_issues, max_prs)
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  # Convert markdown to HTML
37
  html_report = markdown.markdown(report)
38
 
39
  return progress_html + "<p>βœ… Analysis complete!</p>", html_report
40
  except Exception as e:
41
  error_message = f"<p>❌ An error occurred: {str(e)}</p>"
 
42
  return progress_html + error_message, ""
43
 
44
  # Define the Gradio interface
@@ -63,4 +117,4 @@ with gr.Blocks() as app:
63
 
64
  # Launch the app
65
  if __name__ == "__main__":
66
- app.launch()
 
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
8
+ from github import Github
9
+ from openai import OpenAI
10
 
11
  # Emojis and fun statements for progress updates
12
  PROGRESS_STEPS = [
 
22
  if github_token:
23
  os.environ["GITHUB_TOKEN"] = github_token
24
 
25
+ github_token = os.environ.get("GITHUB_TOKEN")
26
+ if not github_token:
27
+ return "<p>❌ Error: GITHUB_TOKEN environment variable not set.</p>", ""
28
+
29
+ openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")
30
+ if not openrouter_api_key:
31
+ return "<p>❌ Error: OPENROUTER_API_KEY environment variable not set.</p>", ""
32
+
33
  progress_html = ""
34
  yield progress_html, "" # Initial empty output
35
 
 
40
 
41
  try:
42
  owner, repo_name = get_repo_info(repo_input)
43
+ repo_url = f"https://github.com/{owner}/{repo_name}"
 
44
 
45
+ g = Github(github_token)
46
+ github_repo = g.get_repo(f"{owner}/{repo_name}")
47
 
48
+ client = OpenAI(api_key=openrouter_api_key, base_url="https://openrouter.ai/api/v1")
49
+
50
+ max_issues = 10
51
+ max_prs = 10
52
+
53
+ with tempfile.TemporaryDirectory() as temp_dir:
54
+ repo_path = clone_repo(owner, repo_name, temp_dir)
55
+
56
+ progress_html += "<p>πŸ”¬ Analyzing code structure...</p>"
57
+ yield progress_html, ""
58
+ code_analysis = analyze_code(repo_path)
59
+ code_analysis['llm_analysis'] = llm_analyze_code(client, code_analysis)
60
+
61
+ progress_html += f"<p>πŸ“Š Analyzing issues (max {max_issues})...</p>"
62
+ yield progress_html, ""
63
+ issues_data = analyze_issues(github_repo, max_issues)
64
+ issues_analysis = llm_analyze_issues(client, issues_data, repo_url)
65
+
66
+ progress_html += f"<p>πŸ”€ Analyzing pull requests (max {max_prs})...</p>"
67
+ yield progress_html, ""
68
+ prs_data = analyze_pull_requests(github_repo, max_prs)
69
+ pr_analysis = llm_analyze_prs(client, prs_data, repo_url)
70
+
71
+ progress_html += "<p>🧠 Synthesizing findings...</p>"
72
+ yield progress_html, ""
73
+ final_analysis = llm_synthesize_findings(
74
+ client,
75
+ code_analysis.get('llm_analysis', ''),
76
+ issues_analysis.get('summary', ''),
77
+ pr_analysis.get('summary', '')
78
+ )
79
+
80
+ repo_info = {
81
+ "owner": owner,
82
+ "repo_name": repo_name,
83
+ }
84
+
85
+ progress_html += "<p>πŸ“ Generating report...</p>"
86
+ yield progress_html, ""
87
+ report = generate_report(repo_info, code_analysis, issues_analysis, pr_analysis, final_analysis)
88
+
89
  # Convert markdown to HTML
90
  html_report = markdown.markdown(report)
91
 
92
  return progress_html + "<p>βœ… Analysis complete!</p>", html_report
93
  except Exception as e:
94
  error_message = f"<p>❌ An error occurred: {str(e)}</p>"
95
+ traceback.print_exc()
96
  return progress_html + error_message, ""
97
 
98
  # Define the Gradio interface
 
117
 
118
  # Launch the app
119
  if __name__ == "__main__":
120
+ app.launch()