Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -37,6 +37,11 @@ if uploaded_file is not None:
|
|
37 |
"unknown_params": []
|
38 |
}
|
39 |
|
|
|
|
|
|
|
|
|
|
|
40 |
# متغيرات للتحكم في العملية
|
41 |
progress_bar = st.progress(0)
|
42 |
pause_button = st.button("Pause")
|
@@ -44,36 +49,42 @@ if uploaded_file is not None:
|
|
44 |
continue_button = st.button("Continue")
|
45 |
paused = False
|
46 |
stopped = False
|
47 |
-
current_index = 0
|
|
|
48 |
|
49 |
-
# دالة تصنيف
|
50 |
-
def
|
51 |
global paused, stopped, current_index
|
52 |
total_items = len(items)
|
53 |
-
for i
|
54 |
-
current_index = i
|
55 |
if stopped:
|
56 |
break
|
57 |
if paused:
|
58 |
time.sleep(0.5)
|
59 |
continue
|
60 |
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
elif best_category == "game" and score > 0.5:
|
69 |
-
gaming_items.append(item)
|
70 |
-
elif best_category == "stream" and score > 0.5:
|
71 |
-
streaming_items.append(item)
|
72 |
-
else:
|
73 |
-
unknown_items.append(item)
|
74 |
|
75 |
# تحديث شريط التقدم
|
76 |
-
progress = (current_index
|
77 |
progress_bar.progress(progress)
|
78 |
|
79 |
# تحديث النتائج في الوقت الحقيقي
|
@@ -86,33 +97,52 @@ if uploaded_file is not None:
|
|
86 |
def classify_parameters(items, categories, start_index=0):
|
87 |
global paused, stopped, current_index
|
88 |
total_items = len(items)
|
89 |
-
for i
|
90 |
-
current_index = i
|
91 |
if stopped:
|
92 |
break
|
93 |
if paused:
|
94 |
time.sleep(0.5)
|
95 |
continue
|
96 |
|
97 |
-
#
|
98 |
-
|
99 |
-
for
|
100 |
-
#
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
else:
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
# تحديث شريط التقدم
|
115 |
-
progress = (current_index
|
116 |
progress_bar.progress(progress)
|
117 |
|
118 |
# تحديث النتائج في الوقت الحقيقي
|
@@ -135,6 +165,13 @@ if uploaded_file is not None:
|
|
135 |
st.session_state.stream_params = "\n".join(param_categories["stream_params"])
|
136 |
st.session_state.unknown_params = "\n".join(param_categories["unknown_params"])
|
137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
# زر البدء
|
139 |
if st.button("Start"):
|
140 |
stopped = False
|
@@ -142,7 +179,7 @@ if uploaded_file is not None:
|
|
142 |
current_index = 0
|
143 |
|
144 |
if operation == "Filter Keywords":
|
145 |
-
|
146 |
elif operation == "Extra & Filter Param (URLs)":
|
147 |
classify_parameters(items, categories, start_index=current_index)
|
148 |
|
@@ -156,7 +193,7 @@ if uploaded_file is not None:
|
|
156 |
paused = False
|
157 |
st.write("Classification resumed.")
|
158 |
if operation == "Filter Keywords":
|
159 |
-
|
160 |
elif operation == "Extra & Filter Param (URLs)":
|
161 |
classify_parameters(items, categories, start_index=current_index)
|
162 |
|
@@ -210,5 +247,22 @@ if uploaded_file is not None:
|
|
210 |
st.session_state.unknown_params = ""
|
211 |
st.text_area("Copy the unknown parameters here:", value=st.session_state.unknown_params, height=200, key="unknown_params")
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
else:
|
214 |
st.warning("Please upload a text file to start classification.")
|
|
|
37 |
"unknown_params": []
|
38 |
}
|
39 |
|
40 |
+
# قوائم لتحليل الصيغ وأنواع الروابط
|
41 |
+
extensions = {}
|
42 |
+
internal_links = []
|
43 |
+
external_links = []
|
44 |
+
|
45 |
# متغيرات للتحكم في العملية
|
46 |
progress_bar = st.progress(0)
|
47 |
pause_button = st.button("Pause")
|
|
|
49 |
continue_button = st.button("Continue")
|
50 |
paused = False
|
51 |
stopped = False
|
52 |
+
current_index = 0 # مؤشر للكلمة الحالية
|
53 |
+
batch_size = 10 # عدد العناصر التي يتم معالجتها في الدفعة الواحدة
|
54 |
|
55 |
+
# دالة تصنيف الكلمات باستخدام الدفعات
|
56 |
+
def classify_keywords_batch(items, categories, start_index=0):
|
57 |
global paused, stopped, current_index
|
58 |
total_items = len(items)
|
59 |
+
for i in range(start_index, total_items, batch_size):
|
|
|
60 |
if stopped:
|
61 |
break
|
62 |
if paused:
|
63 |
time.sleep(0.5)
|
64 |
continue
|
65 |
|
66 |
+
# معالجة دفعة من العناصر
|
67 |
+
batch = items[i:i + batch_size]
|
68 |
+
results = classifier(batch, categories)
|
69 |
+
|
70 |
+
for j, result in enumerate(results):
|
71 |
+
best_category = result['labels'][0]
|
72 |
+
score = result['scores'][0]
|
73 |
+
|
74 |
+
if best_category == "shop" and score > 0.5:
|
75 |
+
shopping_items.append(batch[j])
|
76 |
+
elif best_category == "game" and score > 0.5:
|
77 |
+
gaming_items.append(batch[j])
|
78 |
+
elif best_category == "stream" and score > 0.5:
|
79 |
+
streaming_items.append(batch[j])
|
80 |
+
else:
|
81 |
+
unknown_items.append(batch[j])
|
82 |
|
83 |
+
# تحديث المؤشر الحالي
|
84 |
+
current_index = i + batch_size
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
# تحديث شريط التقدم
|
87 |
+
progress = (current_index) / total_items
|
88 |
progress_bar.progress(progress)
|
89 |
|
90 |
# تحديث النتائج في الوقت الحقيقي
|
|
|
97 |
def classify_parameters(items, categories, start_index=0):
|
98 |
global paused, stopped, current_index
|
99 |
total_items = len(items)
|
100 |
+
for i in range(start_index, total_items, batch_size):
|
|
|
101 |
if stopped:
|
102 |
break
|
103 |
if paused:
|
104 |
time.sleep(0.5)
|
105 |
continue
|
106 |
|
107 |
+
# معالجة دفعة من الروابط
|
108 |
+
batch = items[i:i + batch_size]
|
109 |
+
for url in batch:
|
110 |
+
# استخراج الباراميترات من الرابط باستخدام RegEx
|
111 |
+
params = re.findall(r'(\w+)=\w+', url)
|
112 |
+
for param in params:
|
113 |
+
# تصنيف الباراميتر باستخدام zero-shot-classification
|
114 |
+
result = classifier(param, categories)
|
115 |
+
best_category = result['labels'][0]
|
116 |
+
score = result['scores'][0]
|
117 |
+
|
118 |
+
if best_category == "shop" and score > 0.5:
|
119 |
+
param_categories["shop_params"].append(f"{param}={re.search(param + r'=([^&]*)', url).group(1)}")
|
120 |
+
elif best_category == "game" and score > 0.5:
|
121 |
+
param_categories["game_params"].append(f"{param}={re.search(param + r'=([^&]*)', url).group(1)}")
|
122 |
+
elif best_category == "stream" and score > 0.5:
|
123 |
+
param_categories["stream_params"].append(f"{param}={re.search(param + r'=([^&]*)', url).group(1)}")
|
124 |
+
else:
|
125 |
+
param_categories["unknown_params"].append(f"{param}={re.search(param + r'=([^&]*)', url).group(1)}")
|
126 |
+
|
127 |
+
# تصنيف الرابط بناءً على نوعه (داخلي/خارجي)
|
128 |
+
if re.match(r'^https?://[^/]+\.example\.com', url):
|
129 |
+
internal_links.append(url)
|
130 |
else:
|
131 |
+
external_links.append(url)
|
132 |
+
|
133 |
+
# استخراج الصيغ (Extensions) من الروابط
|
134 |
+
match = re.search(r'\.([a-zA-Z0-9]+)$', url)
|
135 |
+
if match:
|
136 |
+
ext = match.group(1)
|
137 |
+
if ext not in extensions:
|
138 |
+
extensions[ext] = []
|
139 |
+
extensions[ext].append(url)
|
140 |
+
|
141 |
+
# تحديث المؤشر الحالي
|
142 |
+
current_index = i + batch_size
|
143 |
|
144 |
# تحديث شريط التقدم
|
145 |
+
progress = (current_index) / total_items
|
146 |
progress_bar.progress(progress)
|
147 |
|
148 |
# تحديث النتائج في الوقت الحقيقي
|
|
|
165 |
st.session_state.stream_params = "\n".join(param_categories["stream_params"])
|
166 |
st.session_state.unknown_params = "\n".join(param_categories["unknown_params"])
|
167 |
|
168 |
+
# تحديث محتوى المربعات الخاصة بأنواع الروابط
|
169 |
+
st.session_state.internal_links = "\n".join(internal_links)
|
170 |
+
st.session_state.external_links = "\n".join(external_links)
|
171 |
+
|
172 |
+
# تحديث محتوى المربعات الخاصة بالصيغ
|
173 |
+
st.session_state.extensions_text = "\n\n".join([f"{k}: {', '.join(v)}" for k, v in extensions.items()])
|
174 |
+
|
175 |
# زر البدء
|
176 |
if st.button("Start"):
|
177 |
stopped = False
|
|
|
179 |
current_index = 0
|
180 |
|
181 |
if operation == "Filter Keywords":
|
182 |
+
classify_keywords_batch(items, categories, start_index=current_index)
|
183 |
elif operation == "Extra & Filter Param (URLs)":
|
184 |
classify_parameters(items, categories, start_index=current_index)
|
185 |
|
|
|
193 |
paused = False
|
194 |
st.write("Classification resumed.")
|
195 |
if operation == "Filter Keywords":
|
196 |
+
classify_keywords_batch(items, categories, start_index=current_index)
|
197 |
elif operation == "Extra & Filter Param (URLs)":
|
198 |
classify_parameters(items, categories, start_index=current_index)
|
199 |
|
|
|
247 |
st.session_state.unknown_params = ""
|
248 |
st.text_area("Copy the unknown parameters here:", value=st.session_state.unknown_params, height=200, key="unknown_params")
|
249 |
|
250 |
+
# عرض أنواع الروابط
|
251 |
+
st.header("Internal Links")
|
252 |
+
if 'internal_links' not in st.session_state:
|
253 |
+
st.session_state.internal_links = ""
|
254 |
+
st.text_area("Copy the internal links here:", value=st.session_state.internal_links, height=200, key="internal_links")
|
255 |
+
|
256 |
+
st.header("External Links")
|
257 |
+
if 'external_links' not in st.session_state:
|
258 |
+
st.session_state.external_links = ""
|
259 |
+
st.text_area("Copy the external links here:", value=st.session_state.external_links, height=200, key="external_links")
|
260 |
+
|
261 |
+
# عرض الصيغ
|
262 |
+
st.header("File Extensions")
|
263 |
+
if 'extensions_text' not in st.session_state:
|
264 |
+
st.session_state.extensions_text = ""
|
265 |
+
st.text_area("Copy the file extensions here:", value=st.session_state.extensions_text, height=200, key="extensions")
|
266 |
+
|
267 |
else:
|
268 |
st.warning("Please upload a text file to start classification.")
|