Project2 / app.py
SaiKumar1627's picture
Update app.py
0dfc3de verified
raw
history blame
2.18 kB
import gradio as gr
from deliverable2 import URLValidator
# Initialize Validator
validator = URLValidator()
def validate_url(user_query, url_to_check):
result = validator.rate_url_validity(user_query, url_to_check)
# βœ… Check if an error occurred before accessing "raw_score"
if "Validation Error" in result:
return f"⚠️ {result['Validation Error']}"
# βœ… Access safely without crashing
return {
"Domain Trust": result.get("raw_score", {}).get("Domain Trust", "N/A"),
"Content Relevance": result.get("raw_score", {}).get("Content Relevance", "N/A"),
"Fact-Check Score": result.get("raw_score", {}).get("Fact-Check Score", "N/A"),
"Bias Score": result.get("raw_score", {}).get("Bias Score", "N/A"),
"Final Validity Score": result.get("raw_score", {}).get("Final Validity Score", "N/A"),
"Star Rating": result.get("stars", {}).get("icon", "N/A"),
"Explanation": result.get("explanation", "No explanation available.")
}
# UI Components
query_options = [
"How does climate change impact global weather?",
"What are the latest advancements in AI?",
"How does diet influence mental health?",
"What are the effects of space travel on astronauts?",
"Is cryptocurrency a safe investment?",
"What are the advantages of renewable energy?",
]
url_options = [
"https://www.nationalgeographic.com/environment/article/climate-change",
"https://www.technologyreview.com/2023/05/01/latest-ai-advancements/",
"https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
"https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
]
with gr.Blocks() as demo:
gr.Markdown("# 🌍 URL Credibility Validator")
gr.Markdown("Validate the credibility of any webpage using AI")
user_query = gr.Dropdown(label="Select a search query:", choices=query_options)
url_to_check = gr.Dropdown(label="Select a URL to validate:", choices=url_options)
output = gr.JSON(label="Validation Results")
btn = gr.Button("Validate URL")
btn.click(fn=validate_url, inputs=[user_query, url_to_check], outputs=output)
demo.launch()