Spaces:
Sleeping
Sleeping
adding
Browse files- .vscode/settings.json +5 -0
- app.py +1 -1
- main.py +111 -0
.vscode/settings.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"background.windowBackgrounds": [
|
3 |
+
"c:/Users/Asus/OneDrive/Pictures/Saved Pictures/e777b374-6905-4aeb-beb6-1881e33a909c.jpg"
|
4 |
+
]
|
5 |
+
}
|
app.py
CHANGED
@@ -11,7 +11,7 @@ def analyze_sentiment(text):
|
|
11 |
return f"Sentiment: {label} (confidence: {score:.2f})"
|
12 |
|
13 |
iface = gr.Interface(
|
14 |
-
fn=analyze_sentiment,
|
15 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
16 |
outputs="text",
|
17 |
title="Sentiment Analysis",
|
|
|
11 |
return f"Sentiment: {label} (confidence: {score:.2f})"
|
12 |
|
13 |
iface = gr.Interface(
|
14 |
+
fn=analyze_sentiment,
|
15 |
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
16 |
outputs="text",
|
17 |
title="Sentiment Analysis",
|
main.py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template_string, request
|
2 |
+
import requests
|
3 |
+
from bs4 import BeautifulSoup
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
HTML_TEMPLATE = """
|
8 |
+
<!doctype html>
|
9 |
+
<html lang="en">
|
10 |
+
<head>
|
11 |
+
<title>π Privacy Score Analyzer</title>
|
12 |
+
<style>
|
13 |
+
body { font-family: Arial, sans-serif; background-color: #f2f2f2; padding: 30px; }
|
14 |
+
.container { max-width: 700px; margin: auto; background-color: white; padding: 25px; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.1); }
|
15 |
+
h1 { color: #333; }
|
16 |
+
.score { font-size: 1.5em; color: #007bff; margin-top: 20px; }
|
17 |
+
.issues { color: red; }
|
18 |
+
.success { color: green; }
|
19 |
+
input[type="text"] { width: 100%; padding: 10px; margin-top: 10px; margin-bottom: 15px; border-radius: 5px; border: 1px solid #ccc; }
|
20 |
+
input[type="submit"] { padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; }
|
21 |
+
input[type="submit"]:hover { background-color: #0056b3; }
|
22 |
+
</style>
|
23 |
+
</head>
|
24 |
+
<body>
|
25 |
+
<div class="container">
|
26 |
+
<h1>π Privacy Score Analyzer</h1>
|
27 |
+
<form method="post">
|
28 |
+
<label for="url">Enter a website:</label>
|
29 |
+
<input type="text" name="url" placeholder="e.g. nytimes.com" required>
|
30 |
+
<input type="submit" value="Analyze">
|
31 |
+
</form>
|
32 |
+
{% if score is not none %}
|
33 |
+
<div class="score">π Privacy Score: {{ score }}/100</div>
|
34 |
+
{% if issues %}
|
35 |
+
<div class="issues">
|
36 |
+
<h3>β οΈ Issues Found:</h3>
|
37 |
+
<ul>
|
38 |
+
{% for issue in issues %}
|
39 |
+
<li>{{ issue }}</li>
|
40 |
+
{% endfor %}
|
41 |
+
</ul>
|
42 |
+
</div>
|
43 |
+
{% else %}
|
44 |
+
<div class="success">β
Excellent! No major privacy issues found.</div>
|
45 |
+
{% endif %}
|
46 |
+
{% endif %}
|
47 |
+
{% if error %}
|
48 |
+
<div class="issues"><strong>Error:</strong> {{ error }}</div>
|
49 |
+
{% endif %}
|
50 |
+
</div>
|
51 |
+
</body>
|
52 |
+
</html>
|
53 |
+
"""
|
54 |
+
|
55 |
+
@app.route('/', methods=['GET', 'POST'])
|
56 |
+
def analyze():
|
57 |
+
score = None
|
58 |
+
issues = []
|
59 |
+
error = None
|
60 |
+
|
61 |
+
if request.method == 'POST':
|
62 |
+
url_input = request.form.get('url', '').strip()
|
63 |
+
if not url_input:
|
64 |
+
error = "Please enter a valid URL."
|
65 |
+
else:
|
66 |
+
try:
|
67 |
+
# Add http:// if missing
|
68 |
+
if not url_input.startswith("http"):
|
69 |
+
url_input = "http://" + url_input
|
70 |
+
|
71 |
+
headers = {
|
72 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
73 |
+
}
|
74 |
+
response = requests.get(url_input, headers=headers, timeout=8)
|
75 |
+
html = response.text
|
76 |
+
soup = BeautifulSoup(html, "html.parser")
|
77 |
+
|
78 |
+
score = 100
|
79 |
+
final_url = response.url
|
80 |
+
|
81 |
+
# Check HTTPS
|
82 |
+
if not final_url.startswith("https"):
|
83 |
+
score -= 20
|
84 |
+
issues.append("β Website does not use HTTPS.")
|
85 |
+
|
86 |
+
# Check trackers
|
87 |
+
tracker_keywords = ["google-analytics", "doubleclick", "facebook.net"]
|
88 |
+
trackers_found = []
|
89 |
+
for script in soup.find_all("script"):
|
90 |
+
for keyword in tracker_keywords:
|
91 |
+
if keyword in str(script).lower():
|
92 |
+
trackers_found.append(keyword)
|
93 |
+
if trackers_found:
|
94 |
+
score -= 20
|
95 |
+
issues.append(f"β Trackers found: {', '.join(set(trackers_found))}")
|
96 |
+
|
97 |
+
# Check Content-Security-Policy
|
98 |
+
meta_csp = soup.find("meta", attrs={"http-equiv": "Content-Security-Policy"})
|
99 |
+
if not meta_csp:
|
100 |
+
score -= 10
|
101 |
+
issues.append("β Missing Content-Security-Policy tag.")
|
102 |
+
|
103 |
+
except requests.exceptions.RequestException as e:
|
104 |
+
error = f"Network error: {e}"
|
105 |
+
except Exception as e:
|
106 |
+
error = f"Unexpected error: {e}"
|
107 |
+
|
108 |
+
return render_template_string(HTML_TEMPLATE, score=score, issues=issues, error=error)
|
109 |
+
|
110 |
+
if __name__ == '__main__':
|
111 |
+
app.run(debug=True)
|