Project2 / app.py
SaiKumar1627's picture
Update app.py
bbcec74 verified
raw
history blame
2.8 kB
import gradio as gr
import pandas as pd
from deliverable2 import URLValidator # Ensure this file exists
# Instantiate Validator
validator = URLValidator()
# βœ… Add Your Own Queries
sample_queries = [
"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?",
"How does deep learning work?",
"What are the health risks of 5G technology?",
"Is intermittent fasting effective for weight loss?",
"How do electric vehicles compare to gas cars?"
]
# βœ… Add Your Own URLs
sample_urls = [
"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",
"https://www.investopedia.com/terms/c/cryptocurrency.asp",
"https://www.energy.gov/eere/renewable-energy",
"https://www.ibm.com/cloud/deep-learning",
"https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health",
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/",
"https://www.tesla.com/blog/benefits-of-electric-vehicles"
]
# Function to validate URLs
def validate_url(user_query, url_to_check):
result = validator.rate_url_validity(user_query, url_to_check)
return {
"Domain Trust": result["raw_score"]["Domain Trust"],
"Content Relevance": result["raw_score"]["Content Relevance"],
"Fact-Check Score": result["raw_score"]["Fact-Check Score"],
"Bias Score": result["raw_score"]["Bias Score"],
"Citation Score": result["raw_score"]["Citation Score"],
"Final Validity Score": result["raw_score"]["Final Validity Score"],
"Star Rating": result["stars"]["icon"],
"Explanation": result["explanation"]
}
# Create Gradio Interface
with gr.Blocks() as app:
gr.Markdown("## 🌍 URL Credibility Validator")
gr.Markdown("### Validate the credibility of any webpage using AI")
user_query = gr.Dropdown(sample_queries, label="Select a search query:")
url_to_check = gr.Dropdown(sample_urls, label="Select a URL to validate:")
validation_result = gr.Textbox(label="Validation Results", interactive=False)
validate_button = gr.Button("Validate URL")
def process(user_query, url_to_check):
return validate_url(user_query, url_to_check)
validate_button.click(fn=process, inputs=[user_query, url_to_check], outputs=validation_result)
# Launch Gradio App
app.launch()