Spaces:
Sleeping
Sleeping
import os | |
import gradio as gr | |
import gradio as gr | |
from find_similar_issues import get_similar_issues | |
import requests | |
from html2image import Html2Image | |
import io | |
hti = Html2Image(size=(1920, 1080 * 3)) | |
from defaults import OWNER, REPO, TOKEN | |
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 find_similar_issues(issue, token): | |
similar_issues = get_similar_issues(issue, token=token) | |
similar_issues_summary = [f"#{issue['number']} - {issue['title']}" for issue in similar_issues] | |
return similar_issues_summary | |
def render_issue_as_image(issue, filename="image.png"): | |
url = issue["html_url"] | |
print(url) | |
hti.screenshot(url=url, save_as=filename) | |
return filename | |
def run_find_similar_issues(issue, token, n_issues): | |
issue_information = get_query_issue_information(issue, token=token) | |
# issue_information_summary = f"#{issue_information['number']} - {issue_information['title']}\n\n{issue_information['body']}" | |
similar_issues = get_similar_issues(issue, token=token, top_k=n_issues) | |
# similar_issues_summary = [f"#{issue['number']} - {issue['title']}" for issue in similar_issues] | |
issue_image = render_issue_as_image(issue_information, filename="query_issue.png") | |
image_names = [] | |
for i, issue in enumerate(similar_issues): | |
image_names.append(render_issue_as_image(issue, filename=f"image{i}.png")) | |
# return issue_information_summary, image_names | |
page_html = requests.get(issue_information["html_url"]).text | |
return issue_image, page_html, image_names | |
with gr.Blocks(title="Github Bot") as demo: | |
with gr.Tab("Find similar issues"): | |
with gr.Row(): | |
with gr.Column(): | |
with gr.Row(): | |
issue = gr.Textbox(label="Github Issue", placeholder="Github issue you want to find similar issues to") | |
token = gr.Textbox(label="Github Token", placeholder="Your github token for authentication. This is not stored anywhere.") | |
with gr.Row(): | |
n_issues = gr.Slider(1, 50, value=5, 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.Column(): | |
issue_image = gr.Image(type="filepath", label="Your issue") | |
with gr.Column(): | |
similar_issues_screenshots = gr.Gallery(label="Similar Issues") | |
issue_text = gr.HTML(label="Issue text", elem_id="issue_text") | |
submit_button.click(run_find_similar_issues, outputs=[issue_image, issue_text, similar_issues_screenshots], inputs=[issue, token, n_issues]) | |
with gr.Tab("Search issues"): | |
with gr.Row(): | |
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.") | |
with gr.Row(): | |
pass | |
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() | |