Jrine commited on
Commit
ff3a809
·
verified ·
1 Parent(s): db90f23

Add Usage example script

Browse files
Files changed (1) hide show
  1. usage_example.py +58 -0
usage_example.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CO-PO Mapping Model - Usage Example
3
+ """
4
+
5
+ import pickle
6
+ import numpy as np
7
+ from huggingface_hub import hf_hub_download
8
+
9
+ def load_model():
10
+ """Download and load the CO-PO mapping model"""
11
+ model_path = hf_hub_download(
12
+ repo_id="Jrine/co-po",
13
+ filename="co_po_model_complete.pkl"
14
+ )
15
+
16
+ with open(model_path, 'rb') as f:
17
+ package = pickle.load(f)
18
+
19
+ return package['model'], package['vectorizer']
20
+
21
+ def predict_co_po(statement, model, vectorizer):
22
+ """Predict PO correlations for a CO statement"""
23
+ # Vectorize
24
+ vec = vectorizer.transform([statement])
25
+
26
+ # Predict
27
+ pred = model.predict(vec)[0]
28
+ pred_rounded = np.clip(np.round(pred), 0, 3).astype(int)
29
+
30
+ return pred_rounded
31
+
32
+ # Example usage
33
+ if __name__ == "__main__":
34
+ # Load model
35
+ print("Loading model...")
36
+ model, vectorizer = load_model()
37
+ print("Model loaded!\n")
38
+
39
+ # Example CO
40
+ co = "Design and implement machine learning solutions for real-world problems"
41
+
42
+ # Predict
43
+ predictions = predict_co_po(co, model, vectorizer)
44
+
45
+ # Display
46
+ po_names = ['Engineering Knowledge', 'Problem Analysis', 'Design/Development',
47
+ 'Investigation', 'Modern Tool Usage', 'Engineer and Society',
48
+ 'Environment', 'Ethics', 'Team Work', 'Communication',
49
+ 'Project Management']
50
+
51
+ levels = ['None', 'Low', 'Medium', 'High']
52
+
53
+ print(f"Course Outcome: {co}\n")
54
+ print("PO Mapping:")
55
+ print("-" * 70)
56
+
57
+ for i, (name, score) in enumerate(zip(po_names, predictions), 1):
58
+ print(f"PO{i:2d} ({name:30s}): {score} ({levels[score]})")