Spaces:
Sleeping
Sleeping
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) | |
# β Ensure result is always a dictionary | |
if not isinstance(result, dict): | |
return {"error": "Unexpected error occurred, please try again."} | |
# β Check if an error occurred before accessing "raw_score" | |
if "Validation Error" in result: | |
return {"error": result["Validation Error"]} | |
# β Ensure "raw_score" exists in result | |
raw_score = result.get("raw_score", {}) | |
return { | |
"Domain Trust": raw_score.get("Domain Trust", "N/A"), | |
"Content Relevance": raw_score.get("Content Relevance", "N/A"), | |
"Fact-Check Score": raw_score.get("Fact-Check Score", "N/A"), | |
"Bias Score": raw_score.get("Bias Score", "N/A"), | |
"Final Validity Score": 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() | |