joermd commited on
Commit
0f66410
·
verified ·
1 Parent(s): af31829

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +187 -0
app.py ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whois
3
+ import requests
4
+ from urllib.parse import urlparse
5
+
6
+ def check_website(url):
7
+ """
8
+ Check website details and return information, tips, and traffic estimates
9
+ """
10
+ try:
11
+ # Get basic URL info
12
+ response = requests.get(url, timeout=10)
13
+ response.raise_for_status()
14
+
15
+ domain = urlparse(url).netloc
16
+ domain_info = whois.whois(domain)
17
+
18
+ # Gather website information
19
+ info = {
20
+ 'رابط': url,
21
+ 'بروتوكول': urlparse(url).scheme,
22
+ 'النطاق': domain,
23
+ 'رمز الحالة': response.status_code,
24
+ 'حجم المحتوى (بايت)': len(response.content),
25
+ 'نوع المحتوى': response.headers.get('Content-Type', 'غير متوفر'),
26
+ 'تاريخ الاستجابة': response.headers.get('Date', 'غير متوفر'),
27
+ 'مسجل النطاق': domain_info.get('registrar', 'غير متوفر'),
28
+ 'تاريخ تسجيل النطاق': str(domain_info.get('creation_date', 'غير متوفر')),
29
+ 'تاريخ انتهاء النطاق': str(domain_info.get('expiration_date', 'غير متوفر'))
30
+ }
31
+
32
+ # Generate tips based on status code
33
+ tips = []
34
+ if response.status_code == 200:
35
+ tips.append("- الموقع يعمل بشكل جيد. تأكد من تحسين سرعة التحميل وتجربة المستخدم.")
36
+ elif response.status_code == 404:
37
+ tips.append("- الصفحة غير موجودة. تأكد من تحديث الروابط أو إنشاء صفحة 404 مخصصة.")
38
+ elif response.status_code >= 500:
39
+ tips.append("- خطأ في الخادم. تحقق من تكوين الخادم وتأكد من عدم وجود مشاكل في البرمجة.")
40
+
41
+ # Generate traffic estimates
42
+ traffic_estimate = []
43
+ if 'example.com' in url:
44
+ traffic_estimate.append("- الموقع يستخدم مثالاً، لذا تقدير الزيارات غير ممكن.")
45
+ else:
46
+ if 'edu' in domain:
47
+ traffic_estimate.append("- المواقع التعليمية غالباً ما يكون لديها حركة مرور معتدلة إلى مرتفعة.")
48
+ else:
49
+ traffic_estimate.append("- تقدير عدد الزيارات غير متاح بدون أدوات تحليل متقدمة.")
50
+
51
+ # Format information for display
52
+ info_str = "\n".join([f"{k}: {v}" for k, v in info.items()])
53
+ tips_str = "\n".join(tips)
54
+ traffic_str = "\n".join(traffic_estimate)
55
+
56
+ return info_str, tips_str, traffic_str
57
+
58
+ except requests.RequestException as e:
59
+ error_msg = f'خطأ في الوصول إلى الرابط: {str(e)}'
60
+ return error_msg, error_msg, error_msg
61
+ except Exception as e:
62
+ error_msg = f'حدث خطأ أثناء جمع المعلومات: {str(e)}'
63
+ return error_msg, error_msg, error_msg
64
+
65
+ # Custom CSS for the interface
66
+ custom_css = """
67
+ @import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap');
68
+
69
+ :root {
70
+ --speedy-primary: #8B4513;
71
+ --speedy-dark: #5C2C0B;
72
+ --speedy-light: #F5E6DB;
73
+ --speedy-accent: #D2691E;
74
+ --speedy-bg: #FDF9F6;
75
+ --speedy-text: #3E2723;
76
+ --speedy-border: #DEB887;
77
+ }
78
+
79
+ .gradio-container {
80
+ font-family: 'Cairo', sans-serif !important;
81
+ background-color: var(--speedy-bg) !important;
82
+ margin: 0 auto;
83
+ max-width: 900px !important;
84
+ padding: 2rem !important;
85
+ }
86
+
87
+ .main-header {
88
+ text-align: center;
89
+ color: var(--speedy-primary);
90
+ font-size: 2.5em;
91
+ margin-bottom: 1rem;
92
+ }
93
+
94
+ .sub-header {
95
+ text-align: center;
96
+ color: var(--speedy-accent);
97
+ font-size: 1.2em;
98
+ margin-bottom: 2rem;
99
+ }
100
+
101
+ .gradio-button {
102
+ background: linear-gradient(135deg, #8B4513 0%, #5C2C0B 100%) !important;
103
+ color: white !important;
104
+ border: none !important;
105
+ border-radius: 12px !important;
106
+ padding: 0.8em 1.5em !important;
107
+ font-weight: 600 !important;
108
+ transition: transform 0.3s ease, box-shadow 0.3s ease !important;
109
+ }
110
+
111
+ .gradio-button:hover {
112
+ transform: translateY(-2px) !important;
113
+ box-shadow: 0 6px 12px rgba(92, 44, 11, 0.3) !important;
114
+ }
115
+
116
+ .gradio-textbox {
117
+ border: 2px solid var(--speedy-border) !important;
118
+ border-radius: 12px !important;
119
+ padding: 0.8em !important;
120
+ }
121
+
122
+ .gradio-textbox:focus {
123
+ border-color: var(--speedy-primary) !important;
124
+ box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.2) !important;
125
+ }
126
+
127
+ .output-panel {
128
+ background: white !important;
129
+ border-radius: 16px !important;
130
+ padding: 1.5rem !important;
131
+ margin-top: 1rem !important;
132
+ border: 1px solid var(--speedy-border) !important;
133
+ transition: transform 0.3s ease, box-shadow 0.3s ease !important;
134
+ }
135
+
136
+ .output-panel:hover {
137
+ transform: translateY(-3px) !important;
138
+ box-shadow: 0 4px 6px rgba(139, 69, 19, 0.2) !important;
139
+ }
140
+ """
141
+
142
+ # Create Gradio interface
143
+ with gr.Blocks(css=custom_css) as demo:
144
+ gr.HTML("""
145
+ <div class="main-header">سبيدي</div>
146
+ <div class="sub-header">فاحص المواقع السريع والذكي</div>
147
+ """)
148
+
149
+ with gr.Row():
150
+ url_input = gr.Textbox(
151
+ label="أدخل رابط الموقع",
152
+ placeholder="https://example.com",
153
+ dir="ltr"
154
+ )
155
+
156
+ with gr.Row():
157
+ check_button = gr.Button("فحص سريع", variant="primary")
158
+
159
+ with gr.Row():
160
+ with gr.Column():
161
+ info_output = gr.Textbox(
162
+ label="معلومات الموقع",
163
+ lines=10,
164
+ readonly=True
165
+ )
166
+ with gr.Column():
167
+ tips_output = gr.Textbox(
168
+ label="نصائح تحسين الموقع",
169
+ lines=4,
170
+ readonly=True
171
+ )
172
+ with gr.Column():
173
+ traffic_output = gr.Textbox(
174
+ label="تحليل الزيارات",
175
+ lines=4,
176
+ readonly=True
177
+ )
178
+
179
+ check_button.click(
180
+ fn=check_website,
181
+ inputs=[url_input],
182
+ outputs=[info_output, tips_output, traffic_output]
183
+ )
184
+
185
+ # Launch the app
186
+ if __name__ == "__main__":
187
+ demo.launch()