import gradio as gr from find_similar_issues import get_similar_issues import requests from defaults import OWNER, REPO def get_query_issue_information(issue_no, token): headers = { "Accept": "application/vnd.github+json", "Authorization": f"{token}", "X-GitHub-Api-Version": "2022-11-28", "User-Agent": "amyeroberts", } request = requests.get( f"https://api.github.com/repos/{OWNER}/{REPO}/issues/{issue_no}", headers=headers, ) if request.status_code != 200: raise ValueError(f"Request failed with status code {request.status_code} and message {request.text}") return request.json() def run_find_similar_issues(token, n_issues, issue_no, query): if issue_no == "": issue_no = None if query == "": query = None similar_issues = get_similar_issues(issue_no=issue_no, query=query, token=token, top_k=n_issues) issues_html = [f"#{issue['number']} - {issue['title']}" for issue in similar_issues] issues_html = "
".join(issues_html) return issues_html with gr.Blocks(title="Github Bot") as demo: with gr.Tab("Find similar issues"): with gr.Row(): with gr.Column(): with gr.Row(): issue_no = gr.Textbox(label="Github Issue", placeholder="Github issue you want to find similar issues to") query = gr.Textbox(label="Query", placeholder="Search for issues") with gr.Row(): token = gr.Textbox(label="Github Token", placeholder="Your github token for authentication. This is not stored anywhere.") n_issues = gr.Slider(1, 50, value=5, step=1, label="Number of similar issues", info="Choose between 1 and 50") with gr.Row(): submit_button = gr.Button(value="Submit") with gr.Row(): with gr.Row(): issues_html = gr.HTML(label="Issue text", elem_id="issue_html") with gr.Row(): submit_button.click(run_find_similar_issues, outputs=[issues_html], inputs=[token, n_issues, issue_no, query]) with gr.Tab("Find maintainers to ping"): with gr.Row(): issue = gr.Textbox(label="Github Issue / PR", placeholder="Issue or PR you want to find maintainers to ping for") with gr.Row(): token = gr.Textbox(label="Github Token", placeholder="Your github token for authentication. This is not stored anywhere.") if __name__ == "__main__": demo.launch()