Spaces:
Sleeping
Sleeping
import datetime | |
import gradio as gr | |
import os | |
from find_similar_issues import get_similar_issues | |
import requests | |
from defaults import OWNER, REPO | |
import build_issue_dict | |
import build_embeddings | |
import shutil | |
from fetch import get_issues | |
from update_stored_issues import update_issues | |
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"<a href='{issue['html_url']}' target='_blank'>#{issue['number']} - {issue['title']}</a>" for issue in similar_issues] | |
issues_html = "<br>".join(issues_html) | |
return issues_html | |
def update_issues(): | |
# Archive the stored issues | |
if os.path.exists("issues.json"): | |
date_time = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") | |
shutil.copy("issues.json", f"{date_time}_issues.json") | |
# Retrieve new issues | |
get_issues(overwrite=False, update=True, output_filename="issues.json") | |
# Update any issues that have been updated since the last update | |
update_issues() | |
# Update the dictionary of issues | |
build_issue_dict.build_json_file("issues.json", "issues_dict.json") | |
# Update the embeddings | |
build_embeddings.embed_issues( | |
input_filename="issues_dict.json", | |
issue_type="issue", | |
model_id="all-mpnet-base-v2", | |
update=True | |
) | |
with gr.Blocks(title="Github Bot") as demo: | |
with gr.Tab("Find similar issues"): | |
with gr.Row(): | |
# with gr.Column(): | |
with gr.Column(): | |
gr.Markdown("Find similar issues to a given issue or query") | |
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.Column(): | |
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") | |
update_button = gr.Button(value="Update issues") | |
update_button.click(update_issues) | |
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") | |
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() | |