Mohzen321 commited on
Commit
5077404
·
verified ·
1 Parent(s): dd537e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -2,14 +2,7 @@ import streamlit as st
2
  from transformers import pipeline
3
 
4
  # تحميل النموذج
5
- classifier = pipeline("text-classification", model="distilbert-base-uncased")
6
-
7
- # قائمة العلامات
8
- labels = {
9
- "LABEL_0": "shopping",
10
- "LABEL_1": "gaming",
11
- "LABEL_2": "streaming"
12
- }
13
 
14
  # عنوان التطبيق
15
  st.title("Text Classification App")
@@ -20,9 +13,14 @@ text = st.text_area("Enter your text here:")
20
  # زر التصنيف
21
  if st.button("Classify"):
22
  if text:
23
- result = classifier(text)
24
- label = result[0]['label']
25
- mapped_label = labels.get(label, "Unknown")
26
- st.write(f"Classification Result: {mapped_label}")
 
 
 
 
 
27
  else:
28
  st.warning("Please enter some text!")
 
2
  from transformers import pipeline
3
 
4
  # تحميل النموذج
5
+ classifier = pipeline("zero-shot-classification", model="joeddav/xlm-roberta-large-xnli")
 
 
 
 
 
 
 
6
 
7
  # عنوان التطبيق
8
  st.title("Text Classification App")
 
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!")