Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,18 @@
|
|
1 |
-
import gradio as gr
|
2 |
from deliverable2 import URLValidator
|
|
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
|
7 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
queries = [
|
9 |
"How blockchain works",
|
10 |
"Climate change effects",
|
@@ -16,9 +24,10 @@ queries = [
|
|
16 |
"Electric vehicle benefits",
|
17 |
"History of the internet",
|
18 |
"Nutritional benefits of a vegan diet",
|
19 |
-
"Mental health awareness"
|
20 |
]
|
21 |
|
|
|
22 |
urls = [
|
23 |
"https://www.ibm.com/topics/what-is-blockchain",
|
24 |
"https://www.nationalgeographic.com/environment/article/climate-change-overview",
|
@@ -33,31 +42,15 @@ urls = [
|
|
33 |
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
|
34 |
]
|
35 |
|
36 |
-
#
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
# Gradio UI
|
50 |
-
with gr.Blocks() as app:
|
51 |
-
gr.Markdown("# 🌍 URL Credibility Validator")
|
52 |
-
gr.Markdown("### Validate the credibility of any webpage using AI")
|
53 |
-
|
54 |
-
user_query = gr.Dropdown(queries, label="Select a search query:")
|
55 |
-
url_to_check = gr.Dropdown(urls, label="Select a URL to validate:")
|
56 |
-
|
57 |
-
result_output = gr.JSON(label="Validation Results")
|
58 |
-
|
59 |
-
submit_button = gr.Button("Validate URL")
|
60 |
-
submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output)
|
61 |
-
|
62 |
-
# Launch the app
|
63 |
-
app.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
1 |
from deliverable2 import URLValidator
|
2 |
+
import os
|
3 |
+
import json
|
4 |
|
5 |
+
# Retrieve API key from environment variables
|
6 |
+
SERPAPI_API_KEY = os.getenv("SERPAPI_API_KEY")
|
7 |
|
8 |
+
# Ensure API key is provided before initializing
|
9 |
+
if not SERPAPI_API_KEY:
|
10 |
+
raise ValueError("SERPAPI_API_KEY is not set. Please configure your environment variables.")
|
11 |
+
|
12 |
+
# Initialize the validator correctly
|
13 |
+
validator = URLValidator(serpapi_key=SERPAPI_API_KEY)
|
14 |
+
|
15 |
+
# List of queries
|
16 |
queries = [
|
17 |
"How blockchain works",
|
18 |
"Climate change effects",
|
|
|
24 |
"Electric vehicle benefits",
|
25 |
"History of the internet",
|
26 |
"Nutritional benefits of a vegan diet",
|
27 |
+
"Mental health awareness"
|
28 |
]
|
29 |
|
30 |
+
# Corresponding URLs
|
31 |
urls = [
|
32 |
"https://www.ibm.com/topics/what-is-blockchain",
|
33 |
"https://www.nationalgeographic.com/environment/article/climate-change-overview",
|
|
|
42 |
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
|
43 |
]
|
44 |
|
45 |
+
# Process queries and URLs separately but use them together
|
46 |
+
results = []
|
47 |
+
for query, url in zip(queries, urls):
|
48 |
+
result = validator.rate_url_validity(query, url)
|
49 |
+
results.append({
|
50 |
+
"Query": query,
|
51 |
+
"URL": url,
|
52 |
+
"Result": result
|
53 |
+
})
|
54 |
+
|
55 |
+
# Print formatted output
|
56 |
+
print(json.dumps(results, indent=2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|