DronA23 commited on
Commit
206a47d
·
verified ·
1 Parent(s): b638ecb

Update Deliverable2.py

Browse files
Files changed (1) hide show
  1. Deliverable2.py +17 -34
Deliverable2.py CHANGED
@@ -2,11 +2,14 @@ import requests
2
  from bs4 import BeautifulSoup
3
  from sentence_transformers import SentenceTransformer, util
4
  from transformers import pipeline
 
 
5
  from deliverable2 import URLValidator
 
 
6
  validator = URLValidator()
7
  print("Validator loaded successfully!")
8
 
9
-
10
  class URLValidator:
11
  def __init__(self):
12
  self.similarity_model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
@@ -33,23 +36,21 @@ class URLValidator:
33
  sentiment_result = self.sentiment_analyzer(content[:512])[0]
34
  return 100 if sentiment_result["label"] == "POSITIVE" else 50 if sentiment_result["label"] == "NEUTRAL" else 30
35
 
36
- def validate_url(user_query, url_to_check):
37
- try:
38
- result = validator.rate_url_validity(user_query, url_to_check)
39
- print("Validation Result:", result) # Debugging line
40
-
41
- if "Validation Error" in result:
42
- return {"Error": result["Validation Error"]}
43
 
44
- return {
45
- "Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
46
- "Bias Score": f"{result['raw_score']['Bias Score']} / 100",
47
- "Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
48
- }
49
- except Exception as e:
50
- return {"Error": str(e)}
51
 
52
- }}
 
 
 
 
 
 
53
 
54
  queries_urls = [
55
  ("Climate change effects", "https://www.nationalgeographic.com/environment/article/climate-change-overview"),
@@ -64,29 +65,12 @@ queries_urls = [
64
  ("Mental health awareness", "https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response")
65
  ]
66
 
67
- validator = URLValidator()
68
  results = [validator.rate_url_validity(query, url) for query, url in queries_urls]
69
 
70
  for result in results:
71
  print(result)
72
 
73
  # Generate formatted output for the 10 predefined queries and URLs
74
- queries_urls = [
75
- ("Climate change effects", "https://www.nationalgeographic.com/environment/article/climate-change-overview"),
76
- ("COVID-19 vaccine effectiveness", "https://www.cdc.gov/coronavirus/2019-ncov/vaccines/effectiveness.html"),
77
- ("Latest AI advancements", "https://www.technologyreview.com/topic/artificial-intelligence"),
78
- ("Stock market trends", "https://www.bloomberg.com/markets"),
79
- ("Healthy diet tips", "https://www.healthline.com/nutrition/healthy-eating-tips"),
80
- ("Space exploration missions", "https://www.nasa.gov/missions"),
81
- ("Electric vehicle benefits", "https://www.tesla.com/benefits"),
82
- ("History of the internet", "https://www.history.com/topics/inventions/history-of-the-internet"),
83
- ("Python programming tutorials", "https://realpython.com"),
84
- ("Mental health awareness", "https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response")
85
- ]
86
-
87
- # Placeholder function ratings for demonstration
88
- import random
89
-
90
  formatted_output = []
91
 
92
  for query, url in queries_urls:
@@ -100,4 +84,3 @@ for query, url in queries_urls:
100
 
101
  # Display the formatted output
102
  formatted_output
103
-
 
2
  from bs4 import BeautifulSoup
3
  from sentence_transformers import SentenceTransformer, util
4
  from transformers import pipeline
5
+ import random
6
+
7
  from deliverable2 import URLValidator
8
+
9
+ # Instantiate the validator
10
  validator = URLValidator()
11
  print("Validator loaded successfully!")
12
 
 
13
  class URLValidator:
14
  def __init__(self):
15
  self.similarity_model = SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
 
36
  sentiment_result = self.sentiment_analyzer(content[:512])[0]
37
  return 100 if sentiment_result["label"] == "POSITIVE" else 50 if sentiment_result["label"] == "NEUTRAL" else 30
38
 
39
+ def validate_url(self, user_query, url_to_check):
40
+ try:
41
+ result = self.rate_url_validity(user_query, url_to_check)
42
+ print("Validation Result:", result) # Debugging line
 
 
 
43
 
44
+ if "Validation Error" in result:
45
+ return {"Error": result["Validation Error"]}
 
 
 
 
 
46
 
47
+ return {
48
+ "Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
49
+ "Bias Score": f"{result['raw_score']['Bias Score']} / 100",
50
+ "Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
51
+ }
52
+ except Exception as e:
53
+ return {"Error": str(e)}
54
 
55
  queries_urls = [
56
  ("Climate change effects", "https://www.nationalgeographic.com/environment/article/climate-change-overview"),
 
65
  ("Mental health awareness", "https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response")
66
  ]
67
 
 
68
  results = [validator.rate_url_validity(query, url) for query, url in queries_urls]
69
 
70
  for result in results:
71
  print(result)
72
 
73
  # Generate formatted output for the 10 predefined queries and URLs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  formatted_output = []
75
 
76
  for query, url in queries_urls:
 
84
 
85
  # Display the formatted output
86
  formatted_output