Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,8 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
from deliverable2 import URLValidator
|
4 |
-
from transformers import pipeline
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
# Ensure API key is provided before initializing
|
10 |
-
if not SERPAPI_API_KEY:
|
11 |
-
raise ValueError("SERPAPI_API_KEY is not set. Please configure your environment variables.")
|
12 |
-
|
13 |
-
# Initialize the validator correctly
|
14 |
-
validator = URLValidator(serpapi_key=SERPAPI_API_KEY)
|
15 |
|
16 |
# List of queries
|
17 |
queries = [
|
@@ -43,41 +34,31 @@ urls = [
|
|
43 |
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
|
44 |
]
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
"Query": query,
|
60 |
-
"URL": url,
|
61 |
-
"Trust": fake_news_score,
|
62 |
-
"Relevance": relevance_score
|
63 |
-
})
|
64 |
-
else:
|
65 |
-
results.append({
|
66 |
-
"Query": query,
|
67 |
-
"URL": url,
|
68 |
-
"Trust": "Error fetching content",
|
69 |
-
"Relevance": 0.0
|
70 |
-
})
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
"URL": url,
|
77 |
-
"Trust": "Error",
|
78 |
-
"Relevance": "Error",
|
79 |
-
"Error": str(e)
|
80 |
-
})
|
81 |
|
82 |
-
#
|
83 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from Deliverable2 import URLValidator
|
|
|
|
|
3 |
|
4 |
+
# Instantiate the validator
|
5 |
+
validator = URLValidator()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# List of queries
|
8 |
queries = [
|
|
|
34 |
"https://www.who.int/news-room/fact-sheets/detail/mental-health-strengthening-our-response"
|
35 |
]
|
36 |
|
37 |
+
# Function to validate URL
|
38 |
+
def validate_url(user_query, url_to_check):
|
39 |
+
result = validator.rate_url_validity(user_query, url_to_check)
|
40 |
+
|
41 |
+
if "Validation Error" in result:
|
42 |
+
return {"Error": result["Validation Error"]}
|
43 |
+
|
44 |
+
return {
|
45 |
+
"Content Relevance Score": f"{result['raw_score']['Content Relevance']} / 100",
|
46 |
+
"Bias Score": f"{result['raw_score']['Bias Score']} / 100",
|
47 |
+
"Final Validity Score": f"{result['raw_score']['Final Validity Score']} / 100"
|
48 |
+
}
|
49 |
+
|
50 |
+
# Gradio UI
|
51 |
+
with gr.Blocks() as app:
|
52 |
+
gr.Markdown("# 🌍 URL Credibility Validator")
|
53 |
+
gr.Markdown("### Validate the credibility of any webpage using AI")
|
54 |
|
55 |
+
user_query = gr.Dropdown(queries, label="Select a search query:")
|
56 |
+
url_to_check = gr.Dropdown(urls, label="Select a URL to validate:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
result_output = gr.JSON(label="Validation Results")
|
59 |
+
|
60 |
+
submit_button = gr.Button("Validate URL")
|
61 |
+
submit_button.click(validate_url, inputs=[user_query, url_to_check], outputs=result_output)
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
# Launch the app
|
64 |
+
app.launch(server_name="0.0.0.0", server_port=7860)
|