FariaNoumi09 commited on
Commit
3ddf13f
·
verified ·
1 Parent(s): dbf8b72

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -72
app.py CHANGED
@@ -91,75 +91,4 @@ class URLValidator:
91
  def get_star_rating(self, score: float) -> tuple:
92
  """ Converts a score (0-100) into a 1-5 star rating. """
93
  stars = max(1, min(5, round(score / 20))) # Normalize 100-scale to 5-star scale
94
- return stars, "⭐" * stars
95
-
96
- def generate_explanation(self, domain_trust, similarity_score, fact_check_score, bias_score, citation_score, final_score) -> str:
97
- """ Generates a human-readable explanation for the score. """
98
- reasons = []
99
- if domain_trust < 50:
100
- reasons.append("The source has low domain authority.")
101
- if similarity_score < 50:
102
- reasons.append("The content is not highly relevant to your query.")
103
- if fact_check_score < 50:
104
- reasons.append("Limited fact-checking verification found.")
105
- if bias_score < 50:
106
- reasons.append("Potential bias detected in the content.")
107
- if citation_score < 30:
108
- reasons.append("Few citations found for this content.")
109
-
110
- return " ".join(reasons) if reasons else "This source is highly credible and relevant."
111
-
112
- def rate_url_validity(self, user_query: str, url: str) -> dict:
113
- """ Main function to evaluate the validity of a webpage. """
114
- content = self.fetch_page_content(url)
115
-
116
- domain_trust = self.get_domain_trust(url, content)
117
- similarity_score = self.compute_similarity_score(user_query, content)
118
- fact_check_score = self.check_facts(content)
119
- bias_score = self.detect_bias(content)
120
- citation_score = self.check_google_scholar(url)
121
-
122
- final_score = (
123
- (0.3 * domain_trust) +
124
- (0.3 * similarity_score) +
125
- (0.2 * fact_check_score) +
126
- (0.1 * bias_score) +
127
- (0.1 * citation_score)
128
- )
129
-
130
- stars, icon = self.get_star_rating(final_score)
131
- explanation = self.generate_explanation(domain_trust, similarity_score, fact_check_score, bias_score, citation_score, final_score)
132
-
133
- return {
134
- "raw_score": {
135
- "Domain Trust": domain_trust,
136
- "Content Relevance": similarity_score,
137
- "Fact-Check Score": fact_check_score,
138
- "Bias Score": bias_score,
139
- "Citation Score": citation_score,
140
- "Final Validity Score": final_score
141
- },
142
- "stars": {
143
- "score": stars,
144
- "icon": icon
145
- },
146
- "explanation": explanation
147
- }
148
-
149
- # User input fields
150
- user_prompt = "I have just been on an international flight, can I come back home to hold my 1-month-old newborn?"
151
- url_to_check = "https://www.mayoclinic.org/healthy-lifestyle/infant-and-toddler-health/expert-answers/air-travel-with-infant/faq-20058539"
152
-
153
- # Run validation when the button is clicked
154
- if st.button("Validate URL"):
155
- if not user_prompt.strip() or not url_to_check.strip():
156
- st.warning("Please enter both a search query and a URL.") # Correct method call
157
- else:
158
- with st.spinner("Validating URL..."):
159
- # Instantiate the URLValidator class
160
- validator = URLValidator()
161
- result = validator.rate_url_validity(user_prompt, url_to_check)
162
-
163
- # Display results in JSON format
164
- st.subheader("Validation Results")
165
- st.json(result)
 
91
  def get_star_rating(self, score: float) -> tuple:
92
  """ Converts a score (0-100) into a 1-5 star rating. """
93
  stars = max(1, min(5, round(score / 20))) # Normalize 100-scale to 5-star scale
94
+ return stars, "⭐" * sta