ramagururadhakrishnan commited on
Commit
a3f3ce7
·
verified ·
1 Parent(s): 73283ab

Application

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ import time
4
+ import csv
5
+ import os
6
+ import pandas as pd
7
+
8
+ TEST_SCRIPT = "./tests/test_script.sh"
9
+ OUTPUT_CSV = "grading_results.csv"
10
+
11
+ def run_cmd(cmd):
12
+ result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
13
+ return result.stdout.strip(), result.stderr.strip(), result.returncode
14
+
15
+ def grade_single_image(image_name):
16
+ out, err, code = run_cmd(f"docker pull {image_name}")
17
+ if code != 0:
18
+ return {"docker_image": image_name, "score": 0, "remark": "Pull failed"}
19
+
20
+ out, err, code = run_cmd(f"docker run -d -p 5000:5000 {image_name}")
21
+ if code != 0:
22
+ return {"docker_image": image_name, "score": 0, "remark": "Run failed"}
23
+
24
+ container_id = out.strip()
25
+ time.sleep(3)
26
+
27
+ score_out, _, _ = run_cmd(f"bash {TEST_SCRIPT} {container_id}")
28
+ try:
29
+ score = int(score_out.strip())
30
+ except:
31
+ score = 0
32
+
33
+ run_cmd(f"docker stop {container_id}")
34
+ run_cmd(f"docker rm {container_id}")
35
+
36
+ return {"docker_image": image_name, "score": score, "remark": "Success" if score > 0 else "Failed Tests"}
37
+
38
+ def grade_images(image_list):
39
+ results = []
40
+ for image_name in image_list.splitlines():
41
+ image_name = image_name.strip()
42
+ if not image_name:
43
+ continue
44
+ results.append(grade_single_image(image_name))
45
+
46
+ df = pd.DataFrame(results)
47
+ df.to_csv(OUTPUT_CSV, index=False)
48
+ return df, OUTPUT_CSV
49
+
50
+ with gr.Blocks(theme=gr.themes.Soft()) as app:
51
+ gr.Markdown("## 🐳 Docker AutoGrader")
52
+ gr.Markdown("Enter Docker Hub image names (one per line) to automatically test and grade them.")
53
+
54
+ image_input = gr.Textbox(
55
+ label="Docker Image List",
56
+ placeholder="e.g.,\nramguru/student1_app:latest\nramguru/student2_app:v1",
57
+ lines=6
58
+ )
59
+
60
+ grade_button = gr.Button("Run AutoGrader 🚀")
61
+ output_table = gr.Dataframe(label="Grading Results", interactive=False)
62
+ output_file = gr.File(label="Download CSV Report")
63
+
64
+ grade_button.click(grade_images, inputs=image_input, outputs=[output_table, output_file])
65
+
66
+ app.launch()