Spaces:
Sleeping
Sleeping
import gradio as gr | |
from deliverable2 import URLValidator | |
# β Instantiate the URLValidator class | |
validator = URLValidator() | |
# β Define the queries and URLs (15 entries each) | |
sample_queries = [ | |
"What are the symptoms of the flu?", | |
"How does artificial intelligence impact the job market?", | |
"What are the risks of genetically modified organisms (GMOs)?", | |
"What are the environmental effects of plastic pollution?", | |
"How does 5G technology affect human health?", | |
"What are the latest treatments for Alzheimer's disease?", | |
"Is red meat consumption linked to heart disease?", | |
"How does cryptocurrency mining impact the environment?", | |
"What are the benefits of electric cars?", | |
"How does sleep deprivation affect cognitive function?", | |
"What are the effects of social media on teenage mental health?", | |
"What are the ethical concerns of facial recognition technology?", | |
"How does air pollution contribute to lung diseases?", | |
"What are the potential dangers of artificial general intelligence?", | |
"How does meditation impact brain function?" | |
] | |
sample_urls = [ | |
"https://www.bbc.com/news/world-us-canada-64879434", | |
"https://www.forbes.com/sites/forbestechcouncil/2023/10/15/impact-of-ai-on-the-job-market/", | |
"https://www.fda.gov/food/food-labeling-nutrition/consumers-guide-gmo-foods", | |
"https://www.nationalgeographic.com/environment/article/plastic-pollution", | |
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7453195/", | |
"https://www.alz.org/alzheimers-dementia/treatments", | |
"https://www.heart.org/en/news/2021/02/10/how-red-meat-affects-heart-health", | |
"https://www.scientificamerican.com/article/how-bitcoin-mining-impacts-the-environment/", | |
"https://www.tesla.com/blog/environmental-benefits-electric-cars", | |
"https://www.sleepfoundation.org/sleep-deprivation", | |
"https://www.psychologytoday.com/us/basics/teenagers-and-social-media", | |
"https://www.brookings.edu/research/facial-recognition-technology-ethical-concerns/", | |
"https://www.who.int/news-room/fact-sheets/detail/ambient-(outdoor)-air-quality-and-health", | |
"https://futureoflife.org/background/benefits-risks-of-artificial-intelligence/", | |
"https://www.mindful.org/meditation/mindfulness-getting-started/" | |
] | |
# β Function to validate a selected query and URL | |
def validate_url(user_query, url_to_check): | |
"""Runs the credibility validation process and returns results.""" | |
result = validator.rate_url_validity(user_query, url_to_check) | |
# Handle cases where validation fails | |
if "Validation Error" in result: | |
return "Error", "Error", "Error", result["Validation Error"] | |
# Extract relevant fields from the result dictionary | |
func_rating = round(result["raw_score"]["Final Validity Score"] / 20) # Convert 100-scale to 1-5 | |
custom_rating = min(func_rating + 1, 5) # Ensure max rating is 5 | |
stars = result["stars"]["icon"] | |
explanation = result["explanation"] | |
return func_rating, custom_rating, stars, explanation | |
# β Define the Gradio UI interface | |
with gr.Blocks() as app: | |
gr.Markdown("# π URL Credibility Validator") | |
gr.Markdown("Validate the credibility of any webpage using AI.") | |
# Dropdown for selecting a query | |
user_query = gr.Dropdown( | |
label="Select a search query:", | |
choices=sample_queries | |
) | |
# Dropdown for selecting a URL | |
url_to_check = gr.Dropdown( | |
label="Select a URL to validate:", | |
choices=sample_urls | |
) | |
# Output fields | |
func_rating_output = gr.Textbox(label="π’ Function Rating (1-5)", interactive=False) | |
custom_rating_output = gr.Textbox(label="β Custom Rating (1-5)", interactive=False) | |
stars_output = gr.Textbox(label="π Star Rating", interactive=False) | |
explanation_output = gr.Textbox(label="π Explanation", interactive=False) | |
# Validate Button | |
validate_button = gr.Button("β Validate URL") | |
validate_button.click( | |
validate_url, | |
inputs=[user_query, url_to_check], | |
outputs=[func_rating_output, custom_rating_output, stars_output, explanation_output] | |
) | |
# β Launch Gradio App | |
app.launch() | |