sujitv14 commited on
Commit
e8d17f3
·
verified ·
1 Parent(s): 4cf5ddf

Create evaluator.py

Browse files
Files changed (1) hide show
  1. src/evaluator.py +37 -0
src/evaluator.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from bs4 import BeautifulSoup
2
+
3
+ def evaluate_html(content):
4
+ score = 0
5
+ feedback = []
6
+
7
+ soup = BeautifulSoup(content, 'html.parser')
8
+
9
+ if soup.html:
10
+ score += 1
11
+ else:
12
+ feedback.append("Missing <html> tag")
13
+
14
+ if soup.head and soup.title:
15
+ score += 1
16
+ else:
17
+ feedback.append("Missing <head> or <title>")
18
+
19
+ if soup.body:
20
+ score += 1
21
+ else:
22
+ feedback.append("Missing <body>")
23
+
24
+ tags = ['p', 'h1', 'href', 'h2', 'img', 'a', 'table']
25
+ used = [tag for tag in tags if soup.find(tag)]
26
+
27
+ if len(used) >= 3:
28
+ score += 1
29
+ else:
30
+ feedback.append("Use at least 3 different HTML tags")
31
+
32
+ if len(soup.text.strip()) > 20:
33
+ score += 1
34
+ else:
35
+ feedback.append("Content too short")
36
+
37
+ return score, feedback