Spaces:
Sleeping
Sleeping
File size: 2,306 Bytes
eaed23e 0dfc3de 3bb0a69 0dfc3de dcd88b4 322f2c4 0dfc3de 83e59d3 0dfc3de 83e59d3 0dfc3de 83e59d3 0dfc3de 83e59d3 0dfc3de 83e59d3 0dfc3de bbcec74 0dfc3de bbcec74 0dfc3de bbcec74 0dfc3de bbcec74 0dfc3de bbcec74 0dfc3de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
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()
|