codelion commited on
Commit
b034517
Β·
verified Β·
1 Parent(s): 400ce48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -24,18 +24,18 @@ def analyze_github_repo(repo_input, github_token=None):
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
 
36
  for emoji, message in PROGRESS_STEPS:
37
  progress_html += f"<p>{emoji} {message}</p>"
38
- yield progress_html, ""
39
  time.sleep(4) # Simulate work being done
40
 
41
  try:
@@ -54,22 +54,22 @@ def analyze_github_repo(repo_input, github_token=None):
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', ''),
@@ -83,18 +83,18 @@ def analyze_github_repo(repo_input, github_token=None):
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
- print(html_report)
92
 
93
- return progress_html + "<p>βœ… Analysis complete!</p>", html_report
 
94
  except Exception as e:
95
  error_message = f"<p>❌ An error occurred: {str(e)}</p>"
96
  traceback.print_exc()
97
- return progress_html + error_message, ""
98
 
99
  # Define the Gradio interface
100
  with gr.Blocks() as app:
@@ -107,13 +107,12 @@ with gr.Blocks() as app:
107
 
108
  analyze_button = gr.Button("Analyze Repository")
109
 
110
- progress_output = gr.HTML(label="Progress")
111
- report_output = gr.HTML(label="Analysis Report")
112
 
113
  analyze_button.click(
114
  analyze_github_repo,
115
  inputs=[repo_input, github_token],
116
- outputs=[progress_output, report_output],
117
  )
118
 
119
  # Launch the app
 
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
 
36
  for emoji, message in PROGRESS_STEPS:
37
  progress_html += f"<p>{emoji} {message}</p>"
38
+ yield progress_html
39
  time.sleep(4) # Simulate work being done
40
 
41
  try:
 
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', ''),
 
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 the final HTML report, which will overwrite the progress output
93
+ return html_report
94
  except Exception as e:
95
  error_message = f"<p>❌ An error occurred: {str(e)}</p>"
96
  traceback.print_exc()
97
+ return progress_html + error_message
98
 
99
  # Define the Gradio interface
100
  with gr.Blocks() as app:
 
107
 
108
  analyze_button = gr.Button("Analyze Repository")
109
 
110
+ output = gr.HTML(label="Analysis Output")
 
111
 
112
  analyze_button.click(
113
  analyze_github_repo,
114
  inputs=[repo_input, github_token],
115
+ outputs=[output],
116
  )
117
 
118
  # Launch the app