Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,92 +1,23 @@
|
|
1 |
-
import
|
2 |
-
from bs4 import BeautifulSoup
|
3 |
import pandas as pd
|
4 |
-
import
|
5 |
|
6 |
-
|
7 |
-
"""
|
8 |
-
A production-ready URL validation class that evaluates the credibility of a webpage
|
9 |
-
using multiple factors: domain trust, content relevance, fact-checking, bias detection, and citations.
|
10 |
-
"""
|
11 |
-
|
12 |
-
def __init__(self):
|
13 |
-
pass # No external models used in this simplified version
|
14 |
-
|
15 |
-
def fetch_page_content(self, url: str) -> str:
|
16 |
-
""" Fetches and extracts text content from the given URL. """
|
17 |
-
try:
|
18 |
-
response = requests.get(url, timeout=10)
|
19 |
-
response.raise_for_status()
|
20 |
-
soup = BeautifulSoup(response.text, "html.parser")
|
21 |
-
return " ".join([p.text for p in soup.find_all("p")])
|
22 |
-
except requests.RequestException as e:
|
23 |
-
print(f"Error fetching URL: {url} - {e}")
|
24 |
-
return ""
|
25 |
-
|
26 |
-
def get_domain_trust(self, url: str) -> int:
|
27 |
-
""" Simulated function to assess domain trust. """
|
28 |
-
return (len(url) % 5) + 1 # Mock domain trust rating (1-5)
|
29 |
-
|
30 |
-
def compute_similarity_score(self, user_query: str, content: str) -> int:
|
31 |
-
""" Simulated function to compute similarity between user query and content. """
|
32 |
-
if not content:
|
33 |
-
return 1 # If no content, assign lowest rating
|
34 |
-
return (len(user_query) % 5) + 1 # Mock similarity rating (1-5)
|
35 |
-
|
36 |
-
def rate_url_validity(self, user_query: str, url: str) -> int:
|
37 |
-
""" Evaluates webpage credibility based on multiple scores. """
|
38 |
-
content = self.fetch_page_content(url)
|
39 |
-
domain_trust = self.get_domain_trust(url)
|
40 |
-
similarity_score = self.compute_similarity_score(user_query, content)
|
41 |
-
|
42 |
-
# Final function rating (mock logic)
|
43 |
-
func_rating = round((domain_trust + similarity_score) / 2)
|
44 |
-
return func_rating
|
45 |
-
|
46 |
-
# Sample Queries and URLs
|
47 |
-
sample_queries = [
|
48 |
-
"How does climate change impact global weather?",
|
49 |
-
"What are the latest advancements in AI?",
|
50 |
-
"How does diet influence mental health?",
|
51 |
-
"What are the effects of space travel on astronauts?",
|
52 |
-
"Is cryptocurrency a safe investment?",
|
53 |
-
"What are the advantages of renewable energy?",
|
54 |
-
"How does deep learning work?",
|
55 |
-
"What are the health risks of 5G technology?",
|
56 |
-
"Is intermittent fasting effective for weight loss?",
|
57 |
-
"How do electric vehicles compare to gas cars?"
|
58 |
-
]
|
59 |
-
|
60 |
-
sample_urls = [
|
61 |
-
"https://www.nationalgeographic.com/environment/article/climate-change",
|
62 |
-
"https://www.technologyreview.com/2023/05/01/latest-ai-advancements/",
|
63 |
-
"https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
|
64 |
-
"https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
|
65 |
-
"https://www.investopedia.com/terms/c/cryptocurrency.asp",
|
66 |
-
"https://www.energy.gov/eere/renewable-energy",
|
67 |
-
"https://www.ibm.com/cloud/deep-learning",
|
68 |
-
"https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health",
|
69 |
-
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/",
|
70 |
-
"https://www.tesla.com/blog/benefits-of-electric-vehicles"
|
71 |
-
]
|
72 |
-
|
73 |
-
# Initialize Validator
|
74 |
validator = URLValidator()
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
#
|
91 |
-
|
92 |
-
time.sleep(60) # Keep running indefinitely
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
import pandas as pd
|
3 |
+
from url_validation import URLValidator # Import your validator class
|
4 |
|
5 |
+
# Instantiate Validator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
validator = URLValidator()
|
7 |
|
8 |
+
# Define function for Gradio UI
|
9 |
+
def validate_url(user_query, url_to_check):
|
10 |
+
result = validator.rate_url_validity(user_query, url_to_check)
|
11 |
+
return result
|
12 |
+
|
13 |
+
# Create Gradio Interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=validate_url,
|
16 |
+
inputs=["text", "text"],
|
17 |
+
outputs="json",
|
18 |
+
title="URL Validator",
|
19 |
+
description="Enter a query and a URL to check its credibility."
|
20 |
+
)
|
21 |
+
|
22 |
+
# Launch the Gradio App
|
23 |
+
iface.launch()
|
|