File size: 4,162 Bytes
eaed23e
0dfc3de
3bb0a69
babc141
dcd88b4
322f2c4
c25b170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0dfc3de
babc141
0dfc3de
 
c25b170
 
 
 
babc141
c25b170
babc141
 
c25b170
babc141
 
 
 
 
c25b170
 
babc141
c25b170
 
 
 
 
 
 
 
 
 
 
babc141
 
 
 
 
 
 
c25b170
babc141
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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()