Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
# تحميل النموذج
|
| 5 |
classifier = pipeline("zero-shot-classification", model="cross-encoder/nli-distilroberta-base")
|
|
@@ -23,25 +24,75 @@ if uploaded_file is not None:
|
|
| 23 |
gaming_words = []
|
| 24 |
streaming_words = []
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
st.warning("Please upload a text file to classify the keywords.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import time
|
| 4 |
|
| 5 |
# تحميل النموذج
|
| 6 |
classifier = pipeline("zero-shot-classification", model="cross-encoder/nli-distilroberta-base")
|
|
|
|
| 24 |
gaming_words = []
|
| 25 |
streaming_words = []
|
| 26 |
|
| 27 |
+
# متغيرات للتحكم في العملية
|
| 28 |
+
progress_bar = st.progress(0)
|
| 29 |
+
pause_button = st.button("Pause")
|
| 30 |
+
stop_button = st.button("Stop")
|
| 31 |
+
paused = False
|
| 32 |
+
stopped = False
|
| 33 |
+
|
| 34 |
+
# دالة تصنيف الكلمات
|
| 35 |
+
def classify_keywords(keywords, categories):
|
| 36 |
+
nonlocal paused, stopped
|
| 37 |
+
total_keywords = len(keywords)
|
| 38 |
+
for i, word in enumerate(keywords):
|
| 39 |
+
if stopped:
|
| 40 |
+
break
|
| 41 |
+
if paused:
|
| 42 |
+
time.sleep(0.5) # توقف مؤقت عند الضغط على Pause
|
| 43 |
+
continue
|
| 44 |
+
|
| 45 |
+
# تصنيف الكلمة
|
| 46 |
+
result = classifier(word, categories)
|
| 47 |
+
best_category = result['labels'][0]
|
| 48 |
+
|
| 49 |
+
# إضافة الكلمة إلى القائمة المناسبة
|
| 50 |
+
if best_category == "shopping":
|
| 51 |
+
shopping_words.append(word)
|
| 52 |
+
elif best_category == "gaming":
|
| 53 |
+
gaming_words.append(word)
|
| 54 |
+
elif best_category == "streaming":
|
| 55 |
+
streaming_words.append(word)
|
| 56 |
+
|
| 57 |
+
# تحديث شريط التقدم
|
| 58 |
+
progress = (i + 1) / total_keywords
|
| 59 |
+
progress_bar.progress(progress)
|
| 60 |
+
|
| 61 |
+
# تحديث النتائج في الوقت الحقيقي
|
| 62 |
+
update_results()
|
| 63 |
+
|
| 64 |
+
# إبطاء العملية قليلاً للسماح بتحديث الواجهة
|
| 65 |
+
time.sleep(0.1)
|
| 66 |
+
|
| 67 |
+
# دالة تحديث النتائج
|
| 68 |
+
def update_results():
|
| 69 |
+
st.header("Shopping Keywords")
|
| 70 |
+
st.text_area("Copy the shopping keywords here:", value="\n".join(shopping_words), height=200, key="shopping")
|
| 71 |
+
|
| 72 |
+
st.header("Gaming Keywords")
|
| 73 |
+
st.text_area("Copy the gaming keywords here:", value="\n".join(gaming_words), height=200, key="gaming")
|
| 74 |
+
|
| 75 |
+
st.header("Streaming Keywords")
|
| 76 |
+
st.text_area("Copy the streaming keywords here:", value="\n".join(streaming_words), height=200, key="streaming")
|
| 77 |
+
|
| 78 |
+
# زر البدء
|
| 79 |
+
if st.button("Start"):
|
| 80 |
+
stopped = False
|
| 81 |
+
paused = False
|
| 82 |
+
classify_keywords(keywords, categories)
|
| 83 |
+
|
| 84 |
+
# زر الإيقاف المؤقت
|
| 85 |
+
if pause_button:
|
| 86 |
+
paused = not paused
|
| 87 |
+
if paused:
|
| 88 |
+
st.write("Classification paused.")
|
| 89 |
+
else:
|
| 90 |
+
st.write("Classification resumed.")
|
| 91 |
+
|
| 92 |
+
# زر التوقف الكامل
|
| 93 |
+
if stop_button:
|
| 94 |
+
stopped = True
|
| 95 |
+
st.write("Classification stopped.")
|
| 96 |
+
|
| 97 |
else:
|
| 98 |
st.warning("Please upload a text file to classify the keywords.")
|