Spaces:
Runtime error
Runtime error
create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
|
4 |
+
# Load the dataset from Hugging Face
|
5 |
+
dataset = load_dataset("princeton-nlp/SWE-bench")
|
6 |
+
|
7 |
+
# Define a function to display a sample from the dataset
|
8 |
+
|
9 |
+
def get_result(id,name):
|
10 |
+
if name == "":
|
11 |
+
return get_sample(id)
|
12 |
+
return get_sample_filter(name)
|
13 |
+
|
14 |
+
def get_sample(sample_id):
|
15 |
+
try:
|
16 |
+
# Get the sample from the dataset
|
17 |
+
sample = dataset['test'][int(sample_id)]
|
18 |
+
return sample
|
19 |
+
except:
|
20 |
+
return {"error": "Invalid sample ID"}
|
21 |
+
|
22 |
+
def get_sample_filter(repo_name):
|
23 |
+
try:
|
24 |
+
# Find the sample with the specified repository name in 'train' dataset
|
25 |
+
result = []
|
26 |
+
for sample in dataset['test']:
|
27 |
+
if repo_name in sample["repo"]:
|
28 |
+
|
29 |
+
issue_id=sample["instance_id"].split("-")[1]
|
30 |
+
repo=sample["repo"]
|
31 |
+
issue_url=f"https://{sample['repo']}/issues/{issue_id}"
|
32 |
+
base_commit=sample["base_commit"]
|
33 |
+
result.append({"repo":repo,"base_commit":base_commit,"issue_url":issue_url}) # Return the found sample as a response
|
34 |
+
|
35 |
+
return result
|
36 |
+
except Exception as e:
|
37 |
+
return {"error": f"Invalid repository name or error occurred: {str(e)}"}
|
38 |
+
|
39 |
+
|
40 |
+
# Create the Gradio interface
|
41 |
+
#repo_name = gr.Slider(value=0, min=0, max=len(dataset["test"]), step=1, label='Repository Name')
|
42 |
+
#repo_name = gr.Slider(value=0, min=0, max=len(dataset["test"]), step=1, label='Repository Name')
|
43 |
+
slider = gr.Slider(label="Select ID", minimum=0, maximum=2248, step=1, value=0)
|
44 |
+
input_box=gr.Textbox(lines=1, placeholder="Enter sample ID (integer)")
|
45 |
+
|
46 |
+
iface = gr.Interface(
|
47 |
+
fn=get_result,
|
48 |
+
#inputs=gr.Textbox(lines=1, placeholder="Enter sample ID (integer)"),
|
49 |
+
inputs=[slider,input_box],
|
50 |
+
outputs=gr.JSON(),
|
51 |
+
title="SWE-bench Dataset Viewer",
|
52 |
+
description="Enter a sample ID to view the corresponding data from the SWE-bench dataset."
|
53 |
+
)
|
54 |
+
|
55 |
+
# Launch the interface
|
56 |
+
if __name__ == "__main__":
|
57 |
+
iface.launch(share=True)
|