Deliverable2 / app.py
Inara132000's picture
Update app.py
992f04e verified
raw
history blame
2.32 kB
import gradio as gr
from deliverable2 import URLValidator
# Instantiate the validator
validator = URLValidator()
# βœ… Updated queries and URLs
queries = [
"How blockchain works",
"Climate change effects",
"COVID-19 vaccine effectiveness",
"Latest AI advancements",
"Stock market trends",
"Healthy diet tips",
"Space exploration missions",
"Electric vehicle benefits",
"History of the internet",
"Nutritional benefits of a vegan diet",
"Mental health awareness",
]
urls = [
"https://www.ibm.com/topics/what-is-blockchain",
"https://www.nationalgeographic.com/environment/article/climate-change-overview",
"https://www.cdc.gov/coronavirus/2019-ncov/vaccines/effectiveness.html",
"https://www.technologyreview.com/topic/artificial-intelligence",
"https://www.bloomberg.com/markets",
"https://www.healthline.com/nutrition/healthy-eating-tips",
"https://www.nasa.gov/missions",
"https://www.tesla.com/benefits",
"https://www.history.com/topics/inventions/history-of-the-internet",
"https://www.hsph.harvard.edu/nutritionsource/healthy-weight/diet-reviews/vegan-diet/",
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
]
# Function to validate URL
def validate_url(user_query, url_to_check):
result = validator.rate_url_validity(user_query, url_to_check)
if "Validation Error" in result:
return {"Error": result["Validation Error"]}
return {
"Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
"Bias Score": f"{result['raw_score']['Bias Score']} / 100",
"Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
}
# Gradio UI
with gr.Blocks() as app:
gr.Markdown("# 🌍 URL Credibility Validator")
gr.Markdown("### Validate the credibility of any webpage using AI")
user_query = gr.Dropdown(queries, label="Select a search query:")
url_to_check = gr.Dropdown(urls, label="Select a URL to validate:")
result_output = gr.JSON(label="Validation Results")
submit_button = gr.Button("Validate URL")
submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output)
# Launch the app
app.launch(server_name="0.0.0.0", server_port=7860)