Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,82 +1,79 @@
|
|
1 |
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
from deliverable2 import URLValidator
|
4 |
|
5 |
# β
Instantiate the URLValidator class
|
6 |
validator = URLValidator()
|
7 |
|
8 |
-
# β
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def validate_url(user_query, url_to_check):
|
10 |
"""Runs the credibility validation process and returns results."""
|
11 |
result = validator.rate_url_validity(user_query, url_to_check)
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Extract relevant fields from the result dictionary
|
14 |
-
func_rating = round(result["raw_score"]["Final Validity Score"] / 20) # Convert to 1-5
|
15 |
custom_rating = min(func_rating + 1, 5) # Ensure max rating is 5
|
16 |
-
explanation = result["explanation"]
|
17 |
stars = result["stars"]["icon"]
|
|
|
18 |
|
19 |
return func_rating, custom_rating, stars, explanation
|
20 |
|
21 |
-
# β
Batch processing for all queries & URLs
|
22 |
-
def validate_all():
|
23 |
-
"""Runs validation for all 15 queries & URLs and saves to CSV."""
|
24 |
-
sample_queries = [
|
25 |
-
"How does artificial intelligence impact the job market?",
|
26 |
-
"What are the risks of genetically modified organisms (GMOs)?",
|
27 |
-
"What are the environmental effects of plastic pollution?",
|
28 |
-
"How does 5G technology affect human health?",
|
29 |
-
"What are the latest treatments for Alzheimer's disease?",
|
30 |
-
"Is red meat consumption linked to heart disease?",
|
31 |
-
"How does cryptocurrency mining impact the environment?",
|
32 |
-
"What are the benefits of electric cars?",
|
33 |
-
"How does sleep deprivation affect cognitive function?",
|
34 |
-
"What are the effects of social media on teenage mental health?",
|
35 |
-
"What are the ethical concerns of facial recognition technology?",
|
36 |
-
"How does air pollution contribute to lung diseases?",
|
37 |
-
"What are the potential dangers of artificial general intelligence?",
|
38 |
-
"How does meditation impact brain function?",
|
39 |
-
"What are the psychological effects of video game addiction?"
|
40 |
-
]
|
41 |
-
|
42 |
-
sample_urls = [
|
43 |
-
"https://www.forbes.com/sites/forbestechcouncil/2023/10/15/impact-of-ai-on-the-job-market/",
|
44 |
-
"https://www.fda.gov/food/food-labeling-nutrition/consumers-guide-gmo-foods",
|
45 |
-
"https://www.nationalgeographic.com/environment/article/plastic-pollution",
|
46 |
-
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7453195/",
|
47 |
-
"https://www.alz.org/alzheimers-dementia/treatments",
|
48 |
-
"https://www.heart.org/en/news/2021/02/10/how-red-meat-affects-heart-health",
|
49 |
-
"https://www.scientificamerican.com/article/how-bitcoin-mining-impacts-the-environment/",
|
50 |
-
"https://www.tesla.com/blog/environmental-benefits-electric-cars",
|
51 |
-
"https://www.sleepfoundation.org/sleep-deprivation",
|
52 |
-
"https://www.psychologytoday.com/us/basics/teenagers-and-social-media",
|
53 |
-
"https://www.brookings.edu/research/facial-recognition-technology-ethical-concerns/",
|
54 |
-
"https://www.who.int/news-room/fact-sheets/detail/ambient-(outdoor)-air-quality-and-health",
|
55 |
-
"https://futureoflife.org/background/benefits-risks-of-artificial-intelligence/",
|
56 |
-
"https://www.mindful.org/meditation/mindfulness-getting-started/",
|
57 |
-
"https://www.apa.org/news/press/releases/stress/2020/video-games"
|
58 |
-
]
|
59 |
-
|
60 |
-
# Process all queries & URLs
|
61 |
-
results = []
|
62 |
-
for query, url in zip(sample_queries, sample_urls):
|
63 |
-
func_rating, custom_rating, stars, explanation = validate_url(query, url)
|
64 |
-
results.append([query, url, func_rating, custom_rating, stars, explanation])
|
65 |
-
|
66 |
-
# Save results to CSV
|
67 |
-
df = pd.DataFrame(results, columns=["user_query", "url_to_check", "func_rating", "custom_rating", "stars", "explanation"])
|
68 |
-
df.to_csv("url_validation_results.csv", index=False)
|
69 |
-
|
70 |
-
return df
|
71 |
-
|
72 |
# β
Define the Gradio UI interface
|
73 |
with gr.Blocks() as app:
|
74 |
-
gr.Markdown("# π URL Credibility Validator
|
75 |
-
gr.Markdown("
|
76 |
|
77 |
-
#
|
78 |
-
user_query = gr.
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Output fields
|
82 |
func_rating_output = gr.Textbox(label="π’ Function Rating (1-5)", interactive=False)
|
@@ -84,7 +81,7 @@ with gr.Blocks() as app:
|
|
84 |
stars_output = gr.Textbox(label="π Star Rating", interactive=False)
|
85 |
explanation_output = gr.Textbox(label="π Explanation", interactive=False)
|
86 |
|
87 |
-
# Validate Button
|
88 |
validate_button = gr.Button("β
Validate URL")
|
89 |
validate_button.click(
|
90 |
validate_url,
|
@@ -92,11 +89,5 @@ with gr.Blocks() as app:
|
|
92 |
outputs=[func_rating_output, custom_rating_output, stars_output, explanation_output]
|
93 |
)
|
94 |
|
95 |
-
# Batch Validate Button
|
96 |
-
gr.Markdown("## Validate All Predefined Queries & URLs")
|
97 |
-
batch_validate_button = gr.Button("π Validate All")
|
98 |
-
results_table = gr.DataFrame()
|
99 |
-
batch_validate_button.click(validate_all, outputs=results_table)
|
100 |
-
|
101 |
# β
Launch Gradio App
|
102 |
app.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from deliverable2 import URLValidator
|
3 |
|
4 |
# β
Instantiate the URLValidator class
|
5 |
validator = URLValidator()
|
6 |
|
7 |
+
# β
Define the queries and URLs (15 entries each)
|
8 |
+
sample_queries = [
|
9 |
+
"What are the symptoms of the flu?",
|
10 |
+
"How does artificial intelligence impact the job market?",
|
11 |
+
"What are the risks of genetically modified organisms (GMOs)?",
|
12 |
+
"What are the environmental effects of plastic pollution?",
|
13 |
+
"How does 5G technology affect human health?",
|
14 |
+
"What are the latest treatments for Alzheimer's disease?",
|
15 |
+
"Is red meat consumption linked to heart disease?",
|
16 |
+
"How does cryptocurrency mining impact the environment?",
|
17 |
+
"What are the benefits of electric cars?",
|
18 |
+
"How does sleep deprivation affect cognitive function?",
|
19 |
+
"What are the effects of social media on teenage mental health?",
|
20 |
+
"What are the ethical concerns of facial recognition technology?",
|
21 |
+
"How does air pollution contribute to lung diseases?",
|
22 |
+
"What are the potential dangers of artificial general intelligence?",
|
23 |
+
"How does meditation impact brain function?"
|
24 |
+
]
|
25 |
+
|
26 |
+
sample_urls = [
|
27 |
+
"https://www.bbc.com/news/world-us-canada-64879434",
|
28 |
+
"https://www.forbes.com/sites/forbestechcouncil/2023/10/15/impact-of-ai-on-the-job-market/",
|
29 |
+
"https://www.fda.gov/food/food-labeling-nutrition/consumers-guide-gmo-foods",
|
30 |
+
"https://www.nationalgeographic.com/environment/article/plastic-pollution",
|
31 |
+
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7453195/",
|
32 |
+
"https://www.alz.org/alzheimers-dementia/treatments",
|
33 |
+
"https://www.heart.org/en/news/2021/02/10/how-red-meat-affects-heart-health",
|
34 |
+
"https://www.scientificamerican.com/article/how-bitcoin-mining-impacts-the-environment/",
|
35 |
+
"https://www.tesla.com/blog/environmental-benefits-electric-cars",
|
36 |
+
"https://www.sleepfoundation.org/sleep-deprivation",
|
37 |
+
"https://www.psychologytoday.com/us/basics/teenagers-and-social-media",
|
38 |
+
"https://www.brookings.edu/research/facial-recognition-technology-ethical-concerns/",
|
39 |
+
"https://www.who.int/news-room/fact-sheets/detail/ambient-(outdoor)-air-quality-and-health",
|
40 |
+
"https://futureoflife.org/background/benefits-risks-of-artificial-intelligence/",
|
41 |
+
"https://www.mindful.org/meditation/mindfulness-getting-started/"
|
42 |
+
]
|
43 |
+
|
44 |
+
# β
Function to validate a selected query and URL
|
45 |
def validate_url(user_query, url_to_check):
|
46 |
"""Runs the credibility validation process and returns results."""
|
47 |
result = validator.rate_url_validity(user_query, url_to_check)
|
48 |
|
49 |
+
# Handle cases where validation fails
|
50 |
+
if "Validation Error" in result:
|
51 |
+
return "Error", "Error", "Error", result["Validation Error"]
|
52 |
+
|
53 |
# Extract relevant fields from the result dictionary
|
54 |
+
func_rating = round(result["raw_score"]["Final Validity Score"] / 20) # Convert 100-scale to 1-5
|
55 |
custom_rating = min(func_rating + 1, 5) # Ensure max rating is 5
|
|
|
56 |
stars = result["stars"]["icon"]
|
57 |
+
explanation = result["explanation"]
|
58 |
|
59 |
return func_rating, custom_rating, stars, explanation
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# β
Define the Gradio UI interface
|
62 |
with gr.Blocks() as app:
|
63 |
+
gr.Markdown("# π URL Credibility Validator")
|
64 |
+
gr.Markdown("Validate the credibility of any webpage using AI.")
|
65 |
|
66 |
+
# Dropdown for selecting a query
|
67 |
+
user_query = gr.Dropdown(
|
68 |
+
label="Select a search query:",
|
69 |
+
choices=sample_queries
|
70 |
+
)
|
71 |
+
|
72 |
+
# Dropdown for selecting a URL
|
73 |
+
url_to_check = gr.Dropdown(
|
74 |
+
label="Select a URL to validate:",
|
75 |
+
choices=sample_urls
|
76 |
+
)
|
77 |
|
78 |
# Output fields
|
79 |
func_rating_output = gr.Textbox(label="π’ Function Rating (1-5)", interactive=False)
|
|
|
81 |
stars_output = gr.Textbox(label="π Star Rating", interactive=False)
|
82 |
explanation_output = gr.Textbox(label="π Explanation", interactive=False)
|
83 |
|
84 |
+
# Validate Button
|
85 |
validate_button = gr.Button("β
Validate URL")
|
86 |
validate_button.click(
|
87 |
validate_url,
|
|
|
89 |
outputs=[func_rating_output, custom_rating_output, stars_output, explanation_output]
|
90 |
)
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
# β
Launch Gradio App
|
93 |
app.launch()
|