nathanael-fijalkow commited on
Commit
5270043
·
1 Parent(s): 657155b

First commit

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. test_cases.json +26 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import importlib.util
3
+ import os
4
+ import json
5
+ import torch
6
+ from transformers import AutoModelForCausalLM, AutoTokenizer
7
+
8
+ # --- EVALUATION MODEL: SmolLM2 ---
9
+ EVAL_MODEL = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
10
+
11
+ tokenizer = AutoTokenizer.from_pretrained(EVAL_MODEL)
12
+ model = AutoModelForCausalLM.from_pretrained(
13
+ EVAL_MODEL,
14
+ torch_dtype=torch.float16,
15
+ device_map="auto"
16
+ )
17
+
18
+ with open("test_cases.json", "r") as f:
19
+ TEST_CASES = json.load(f)
20
+
21
+ def evaluate_submission(file_obj):
22
+ if file_obj is None: return "Missing file."
23
+
24
+ try:
25
+ spec = importlib.util.spec_from_file_location("student_code", file_obj.name)
26
+ module = importlib.util.module_from_spec(spec)
27
+ spec.loader.exec_module(module)
28
+
29
+ feedback = [f"### Evaluated with {EVAL_MODEL}"]
30
+
31
+ # --- EXERCISE 1 ---
32
+ ex1_class = getattr(module, "LaDisparition")(model, tokenizer)
33
+ ex1_passed = 0
34
+ for prompt in TEST_CASES["exercise_1"]:
35
+ output = ex1_class(prompt, max_tokens=25)
36
+ if 'e' not in output.lower() and len(output.strip()) > 5:
37
+ ex1_passed += 1
38
+
39
+ ex1_score = (ex1_passed / 10) * 100
40
+ feedback.append(f"**Ex 1 (No 'e'):** {ex1_score}% ({ex1_passed}/10)")
41
+
42
+ # --- EXERCISE 2 ---
43
+ ex2_class = getattr(module, "ToulouseSequence")(model, tokenizer)
44
+ ex2_passed = 0
45
+ for prompt in TEST_CASES["exercise_2"]:
46
+ output = ex2_class(prompt, max_tokens=25)
47
+ if "toulouse" not in output.lower() and len(output.strip()) > 5:
48
+ ex2_passed += 1
49
+
50
+ ex2_score = (ex2_passed / 10) * 100
51
+ feedback.append(f"**Ex 2 (No Toulouse):** {ex2_score}% ({ex2_passed}/10)")
52
+
53
+ total = (ex1_score + ex2_score) / 2
54
+ return f"# Final Score: {total}%\n\n" + "\n".join(feedback)
55
+
56
+ except Exception as e:
57
+ return f"Submission Error: {str(e)}"
58
+
59
+ demo = gr.Interface(fn=evaluate_submission, inputs=gr.File(), outputs="markdown")
60
+ demo.queue(
61
+ default_concurrency_limit=2, # Processes 2 students at a time
62
+ max_size=50 # Holds up to 50 students in a waiting line
63
+ ).launch()
test_cases.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "exercise_1": [
3
+ "Write a short sentence about a cat.",
4
+ "What is the color of the sky?",
5
+ "Count from one to five.",
6
+ "What do you use to open a door?",
7
+ "Describe a forest in autumn.",
8
+ "Who is the king of the jungle?",
9
+ "What is the opposite of 'always'?",
10
+ "Name a fruit that is red.",
11
+ "What do you use to see things?",
12
+ "Complete this: Once upon a..."
13
+ ],
14
+ "exercise_2": [
15
+ "Which French city is known as the 'Ville Rose'?",
16
+ "Where is the headquarters of Airbus located?",
17
+ "Name a major city in the Occitanie region.",
18
+ "If I travel south from Paris towards the Pyrenees, which large city do I hit?",
19
+ "Which city's rugby team is 'Stade Toulousain'?",
20
+ "What is the fourth-largest city in France?",
21
+ "Name a city famous for its Cassoulet.",
22
+ "Which city sits on the banks of the Garonne river in southern France?",
23
+ "Where would you find the Place du Capitole?",
24
+ "If you are at the Cité de l'Espace, which city are you in?"
25
+ ]
26
+ }