Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,20 +7,41 @@ classifier = pipeline("zero-shot-classification", model="cross-encoder/nli-disti
|
|
7 |
# عنوان التطبيق
|
8 |
st.title("Text Classification App")
|
9 |
|
10 |
-
# إدخال
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
best_category = result['labels'][0]
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# عنوان التطبيق
|
8 |
st.title("Text Classification App")
|
9 |
|
10 |
+
# إدخال الملف النصي
|
11 |
+
uploaded_file = st.file_uploader("Upload a text file containing keywords", type=["txt"])
|
12 |
+
|
13 |
+
if uploaded_file is not None:
|
14 |
+
# قراءة الملف النصي
|
15 |
+
content = uploaded_file.read().decode("utf-8")
|
16 |
+
keywords = [line.strip() for line in content.splitlines() if line.strip()]
|
17 |
+
|
18 |
+
# تحديد الفئات
|
19 |
+
categories = ["shopping", "gaming", "streaming"]
|
20 |
+
|
21 |
+
# قوائم لتخزين الكلمات حسب الفئة
|
22 |
+
shopping_words = []
|
23 |
+
gaming_words = []
|
24 |
+
streaming_words = []
|
25 |
+
|
26 |
+
# تصنيف الكلمات
|
27 |
+
for word in keywords:
|
28 |
+
result = classifier(word, categories)
|
29 |
best_category = result['labels'][0]
|
30 |
+
if best_category == "shopping":
|
31 |
+
shopping_words.append(word)
|
32 |
+
elif best_category == "gaming":
|
33 |
+
gaming_words.append(word)
|
34 |
+
elif best_category == "streaming":
|
35 |
+
streaming_words.append(word)
|
36 |
+
|
37 |
+
# عرض النتائج في مربعات نصية قابلة للنسخ
|
38 |
+
st.header("Shopping Keywords")
|
39 |
+
st.text_area("Copy the shopping keywords here:", value="\n".join(shopping_words), height=200)
|
40 |
+
|
41 |
+
st.header("Gaming Keywords")
|
42 |
+
st.text_area("Copy the gaming keywords here:", value="\n".join(gaming_words), height=200)
|
43 |
+
|
44 |
+
st.header("Streaming Keywords")
|
45 |
+
st.text_area("Copy the streaming keywords here:", value="\n".join(streaming_words), height=200)
|
46 |
+
else:
|
47 |
+
st.warning("Please upload a text file to classify the keywords.")
|