Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,71 +1,53 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
from deliverable2 import URLValidator # Ensure this file exists
|
4 |
-
import os
|
5 |
-
os.system("pip install --upgrade --force-reinstall sentence-transformers")
|
6 |
|
7 |
-
|
8 |
-
# Instantiate Validator
|
9 |
validator = URLValidator()
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
"How does climate change impact global weather?",
|
14 |
"What are the latest advancements in AI?",
|
15 |
"How does diet influence mental health?",
|
16 |
"What are the effects of space travel on astronauts?",
|
17 |
"Is cryptocurrency a safe investment?",
|
18 |
"What are the advantages of renewable energy?",
|
19 |
-
"How does deep learning work?",
|
20 |
-
"What are the health risks of 5G technology?",
|
21 |
-
"Is intermittent fasting effective for weight loss?",
|
22 |
-
"How do electric vehicles compare to gas cars?"
|
23 |
]
|
24 |
|
25 |
-
|
26 |
-
sample_urls = [
|
27 |
"https://www.nationalgeographic.com/environment/article/climate-change",
|
28 |
"https://www.technologyreview.com/2023/05/01/latest-ai-advancements/",
|
29 |
"https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
|
30 |
"https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
|
31 |
-
"https://www.investopedia.com/terms/c/cryptocurrency.asp",
|
32 |
-
"https://www.energy.gov/eere/renewable-energy",
|
33 |
-
"https://www.ibm.com/cloud/deep-learning",
|
34 |
-
"https://www.who.int/news-room/questions-and-answers/item/radiation-5g-mobile-networks-and-health",
|
35 |
-
"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6167940/",
|
36 |
-
"https://www.tesla.com/blog/benefits-of-electric-vehicles"
|
37 |
]
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
return {
|
43 |
-
"Domain Trust": result["raw_score"]["Domain Trust"],
|
44 |
-
"Content Relevance": result["raw_score"]["Content Relevance"],
|
45 |
-
"Fact-Check Score": result["raw_score"]["Fact-Check Score"],
|
46 |
-
"Bias Score": result["raw_score"]["Bias Score"],
|
47 |
-
"Citation Score": result["raw_score"]["Citation Score"],
|
48 |
-
"Final Validity Score": result["raw_score"]["Final Validity Score"],
|
49 |
-
"Star Rating": result["stars"]["icon"],
|
50 |
-
"Explanation": result["explanation"]
|
51 |
-
}
|
52 |
-
|
53 |
-
# Create Gradio Interface
|
54 |
-
with gr.Blocks() as app:
|
55 |
-
gr.Markdown("## π URL Credibility Validator")
|
56 |
-
gr.Markdown("### Validate the credibility of any webpage using AI")
|
57 |
-
|
58 |
-
user_query = gr.Dropdown(sample_queries, label="Select a search query:")
|
59 |
-
url_to_check = gr.Dropdown(sample_urls, label="Select a URL to validate:")
|
60 |
-
|
61 |
-
validation_result = gr.Textbox(label="Validation Results", interactive=False)
|
62 |
-
|
63 |
-
validate_button = gr.Button("Validate URL")
|
64 |
|
65 |
-
|
66 |
-
|
|
|
67 |
|
68 |
-
|
|
|
69 |
|
70 |
-
|
71 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from deliverable2 import URLValidator
|
|
|
|
|
|
|
3 |
|
4 |
+
# Initialize Validator
|
|
|
5 |
validator = URLValidator()
|
6 |
|
7 |
+
def validate_url(user_query, url_to_check):
|
8 |
+
result = validator.rate_url_validity(user_query, url_to_check)
|
9 |
+
|
10 |
+
# β
Check if an error occurred before accessing "raw_score"
|
11 |
+
if "Validation Error" in result:
|
12 |
+
return f"β οΈ {result['Validation Error']}"
|
13 |
+
|
14 |
+
# β
Access safely without crashing
|
15 |
+
return {
|
16 |
+
"Domain Trust": result.get("raw_score", {}).get("Domain Trust", "N/A"),
|
17 |
+
"Content Relevance": result.get("raw_score", {}).get("Content Relevance", "N/A"),
|
18 |
+
"Fact-Check Score": result.get("raw_score", {}).get("Fact-Check Score", "N/A"),
|
19 |
+
"Bias Score": result.get("raw_score", {}).get("Bias Score", "N/A"),
|
20 |
+
"Final Validity Score": result.get("raw_score", {}).get("Final Validity Score", "N/A"),
|
21 |
+
"Star Rating": result.get("stars", {}).get("icon", "N/A"),
|
22 |
+
"Explanation": result.get("explanation", "No explanation available.")
|
23 |
+
}
|
24 |
+
|
25 |
+
# UI Components
|
26 |
+
query_options = [
|
27 |
"How does climate change impact global weather?",
|
28 |
"What are the latest advancements in AI?",
|
29 |
"How does diet influence mental health?",
|
30 |
"What are the effects of space travel on astronauts?",
|
31 |
"Is cryptocurrency a safe investment?",
|
32 |
"What are the advantages of renewable energy?",
|
|
|
|
|
|
|
|
|
33 |
]
|
34 |
|
35 |
+
url_options = [
|
|
|
36 |
"https://www.nationalgeographic.com/environment/article/climate-change",
|
37 |
"https://www.technologyreview.com/2023/05/01/latest-ai-advancements/",
|
38 |
"https://www.health.harvard.edu/mind-and-mood/foods-linked-to-better-brainpower",
|
39 |
"https://www.nasa.gov/hrp/long-term-health-risks-of-space-travel",
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
]
|
41 |
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown("# π URL Credibility Validator")
|
44 |
+
gr.Markdown("Validate the credibility of any webpage using AI")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
user_query = gr.Dropdown(label="Select a search query:", choices=query_options)
|
47 |
+
url_to_check = gr.Dropdown(label="Select a URL to validate:", choices=url_options)
|
48 |
+
output = gr.JSON(label="Validation Results")
|
49 |
|
50 |
+
btn = gr.Button("Validate URL")
|
51 |
+
btn.click(fn=validate_url, inputs=[user_query, url_to_check], outputs=output)
|
52 |
|
53 |
+
demo.launch()
|
|