Spaces:
Sleeping
Sleeping
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.") |