Mohzen321 commited on
Commit
95a596a
·
verified ·
1 Parent(s): 4c32405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -16
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
- text = st.text_area("Enter your text here:")
12
-
13
- # زر التصنيف
14
- if st.button("Classify"):
15
- if text:
16
- # تحديد الفئات التي تريد تصنيف النص إليها
17
- categories = ["shopping", "gaming", "streaming"]
18
- result = classifier(text, categories)
19
-
20
- # الحصول على الفئة الأكثر احتمالاً
 
 
 
 
 
 
 
 
21
  best_category = result['labels'][0]
22
- score = round(result['scores'][0], 2)
23
-
24
- st.write(f"Classification Result: {best_category} (Confidence: {score})")
25
- else:
26
- st.warning("Please enter some text!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.")