File size: 1,733 Bytes
ced22e1
 
 
 
4c32405
ced22e1
 
 
 
95a596a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5077404
95a596a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
from transformers import pipeline

# تحميل النموذج
classifier = pipeline("zero-shot-classification", model="cross-encoder/nli-distilroberta-base")

# عنوان التطبيق
st.title("Text Classification App")

# إدخال الملف النصي
uploaded_file = st.file_uploader("Upload a text file containing keywords", type=["txt"])

if uploaded_file is not None:
    # قراءة الملف النصي
    content = uploaded_file.read().decode("utf-8")
    keywords = [line.strip() for line in content.splitlines() if line.strip()]

    # تحديد الفئات
    categories = ["shopping", "gaming", "streaming"]

    # قوائم لتخزين الكلمات حسب الفئة
    shopping_words = []
    gaming_words = []
    streaming_words = []

    # تصنيف الكلمات
    for word in keywords:
        result = classifier(word, categories)
        best_category = result['labels'][0]
        if best_category == "shopping":
            shopping_words.append(word)
        elif best_category == "gaming":
            gaming_words.append(word)
        elif best_category == "streaming":
            streaming_words.append(word)

    # عرض النتائج في مربعات نصية قابلة للنسخ
    st.header("Shopping Keywords")
    st.text_area("Copy the shopping keywords here:", value="\n".join(shopping_words), height=200)

    st.header("Gaming Keywords")
    st.text_area("Copy the gaming keywords here:", value="\n".join(gaming_words), height=200)

    st.header("Streaming Keywords")
    st.text_area("Copy the streaming keywords here:", value="\n".join(streaming_words), height=200)
else:
    st.warning("Please upload a text file to classify the keywords.")