Spaces:
Sleeping
Sleeping
import gradio as gr | |
import os | |
import time | |
import markdown | |
from github_repo_analyzer import main as analyze_repo, get_repo_info | |
# Emojis and fun statements for progress updates | |
PROGRESS_STEPS = [ | |
("π΅οΈββοΈ", "Investigating the GitHub realm..."), | |
("π§¬", "Decoding repository DNA..."), | |
("π", "Hunting for bugs and features..."), | |
("π", "Examining pull request tea leaves..."), | |
("π§ ", "Activating AI brain cells..."), | |
("π", "Crafting the legendary report..."), | |
] | |
def analyze_github_repo(repo_input, github_token=None): | |
if github_token: | |
os.environ["GITHUB_TOKEN"] = github_token | |
progress_html = "" | |
yield progress_html, "" # Initial empty output | |
for emoji, message in PROGRESS_STEPS: | |
progress_html += f"<p>{emoji} {message}</p>" | |
yield progress_html, "" | |
time.sleep(1) # Simulate work being done | |
try: | |
owner, repo_name = get_repo_info(repo_input) | |
max_issues = 10 | |
max_prs = 10 | |
report = analyze_repo(repo_input, max_issues, max_prs) | |
# Convert markdown to HTML | |
html_report = markdown.markdown(report) | |
return progress_html + "<p>β Analysis complete!</p>", html_report | |
except Exception as e: | |
error_message = f"<p>β An error occurred: {str(e)}</p>" | |
return progress_html + error_message, "" | |
# Define the Gradio interface | |
with gr.Blocks() as app: | |
gr.Markdown("# GitHub Repository Analyzer") | |
repo_input = gr.Textbox(label="Enter GitHub Repository Slug or URL") | |
with gr.Accordion("Advanced Settings", open=False): | |
github_token = gr.Textbox(label="GitHub Token (optional)", type="password") | |
analyze_button = gr.Button("Analyze Repository") | |
progress_output = gr.HTML(label="Progress") | |
report_output = gr.HTML(label="Analysis Report") | |
analyze_button.click( | |
analyze_github_repo, | |
inputs=[repo_input, github_token], | |
outputs=[progress_output, report_output], | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
app.launch() | |