Update app.py
Browse files
app.py
CHANGED
@@ -1,81 +1,54 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from urllib.parse import urlparse
|
4 |
-
from bs4 import BeautifulSoup
|
5 |
-
|
6 |
|
|
|
7 |
def analyze_website(url):
|
8 |
-
"""
|
9 |
-
تحليل شامل للموقع.
|
10 |
-
"""
|
11 |
-
results = {
|
12 |
-
"أداء الموقع": "",
|
13 |
-
"تحليل الترافيك": "",
|
14 |
-
"تحليل الأمان": "",
|
15 |
-
"تحليل تجربة المستخدم": ""
|
16 |
-
}
|
17 |
-
|
18 |
try:
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
results["تحليل تجربة المستخدم"] = f"- عنوان الصفحة: {title}\n" \
|
45 |
-
f"- وصف الصفحة: {description}\n" \
|
46 |
-
f"- عدد الروابط الداخلية: {len(soup.find_all('a'))}"
|
47 |
-
|
48 |
-
except requests.RequestException as e:
|
49 |
-
error_msg = f"حدث خطأ أثناء الوصول إلى الموقع: {str(e)}"
|
50 |
-
return {"أداء الموقع": error_msg, "تحليل الترافيك": error_msg,
|
51 |
-
"تحليل الأمان": error_msg, "تحليل تجربة المستخدم": error_msg}
|
52 |
-
|
53 |
-
return results
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
|
59 |
-
gr.
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
with gr.Row():
|
70 |
-
security_output = gr.Textbox(label="تحليل الأمان", lines=3, interactive=False)
|
71 |
-
ux_output = gr.Textbox(label="تحليل تجربة المستخدم", lines=4, interactive=False)
|
72 |
-
|
73 |
-
analyze_button.click(
|
74 |
-
analyze_website,
|
75 |
-
inputs=[url_input],
|
76 |
-
outputs=[performance_output, traffic_output, security_output, ux_output]
|
77 |
-
)
|
78 |
|
79 |
-
#
|
80 |
-
|
81 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
|
|
3 |
|
4 |
+
# Function to analyze the website
|
5 |
def analyze_website(url):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
try:
|
7 |
+
# Ensure the URL has a protocol
|
8 |
+
if not url.startswith("http://") and not url.startswith("https://"):
|
9 |
+
url = "https://" + url
|
10 |
+
|
11 |
+
# Website performance analysis
|
12 |
+
response = requests.get(url, timeout=5)
|
13 |
+
response_time = response.elapsed.total_seconds()
|
14 |
+
status_code = response.status_code
|
15 |
+
content_size = len(response.content)
|
16 |
+
performance = f"- وقت الاستجابة: {response_time:.2f} ثانية.\n- حالة الموقع: {status_code}\n- حجم المحتوى: {content_size} بايت."
|
17 |
+
|
18 |
+
# Traffic analysis
|
19 |
+
traffic_analysis = f"- تحقق من ترتيب أليكسا هنا: https://www.alexa.com/siteinfo/{url.replace('https://', '').replace('http://', '')}"
|
20 |
+
|
21 |
+
# Security analysis
|
22 |
+
security_analysis = (
|
23 |
+
f"- تحقق من شهادة SSL: https://www.ssllabs.com/ssltest/analyze.html?d={url}\n"
|
24 |
+
f"- تحقق من الأمان مع Sucuri: https://sitecheck.sucuri.net/results/{url}"
|
25 |
+
)
|
26 |
+
|
27 |
+
# User experience analysis
|
28 |
+
page_title = response.text.split("<title>")[1].split("</title>")[0] if "<title>" in response.text else "غير متوفر"
|
29 |
+
link_count = response.text.count("<a href=")
|
30 |
+
page_description = "وصف الصفحة غير متوفر."
|
31 |
+
user_experience = f"- عنوان الصفحة: {page_title}\n- وصف الصفحة: {page_description}\n- عدد الروابط الداخلية: {link_count}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Return results in Arabic
|
34 |
+
return performance, traffic_analysis, security_analysis, user_experience
|
35 |
+
except Exception as e:
|
36 |
+
error_message = f"حدث خطأ أثناء تحليل الموقع: {str(e)}"
|
37 |
+
return error_message, error_message, error_message, error_message
|
38 |
|
39 |
+
# Gradio interface
|
40 |
+
interface = gr.Interface(
|
41 |
+
fn=analyze_website, # The function used
|
42 |
+
inputs=gr.Textbox(label="Website URL", placeholder="Enter website URL (e.g., example.com)"), # Input field
|
43 |
+
outputs=[
|
44 |
+
gr.Textbox(label="تحليل الأداء"),
|
45 |
+
gr.Textbox(label="تحليل الترافيك"),
|
46 |
+
gr.Textbox(label="تحليل الأمان"),
|
47 |
+
gr.Textbox(label="تحليل تجربة المستخدم")
|
48 |
+
],
|
49 |
+
title="Website Analysis Tool",
|
50 |
+
description="أدخل رابط الموقع لتحليل الأداء، الترافيك، الأمان، وتجربة المستخدم."
|
51 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
# Launch the app
|
54 |
+
interface.launch(share=True)
|
|