omar3241 commited on
Commit
f1b6696
·
verified ·
1 Parent(s): e6484e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -3,19 +3,17 @@
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
  import gradio as gr
5
 
6
- # تحميل نموذج التحليل الفارسي العام (مش خاص بمنتجات)
7
  model_name = "m3hrdadfi/bert-fa-base-uncased-sentiment"
8
-
9
- # تحميل التوكنيزر والموديل
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
12
 
13
- # إنشاء الـ pipeline مع تفعيل عرض كل النتائج
14
  sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, return_all_scores=True)
15
 
16
  # دالة التحليل
17
  def analyze_sentiment(text):
18
- results = sentiment_analyzer(text)[0] # بنجيب كل الاحتمالات (إيجابي / سلبي / محايد)
19
  output = ""
20
  for r in results:
21
  label = r["label"]
@@ -35,7 +33,8 @@ iface = gr.Interface(
35
  inputs=gr.Textbox(lines=2, placeholder="متن خود را وارد کنید..."),
36
  outputs="text",
37
  title="تحلیل احساسات متون فارسی",
38
- description="نمایش احتمال مثبت، منفی و خنثی بودن متن فارسی با مدل عمومی BERT."
39
  )
40
 
41
  iface.launch()
 
 
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
  import gradio as gr
5
 
6
+ # تحميل نموذج التحليل الفارسي
7
  model_name = "m3hrdadfi/bert-fa-base-uncased-sentiment"
 
 
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
10
 
11
+ # إنشاء الـ pipeline
12
  sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer, return_all_scores=True)
13
 
14
  # دالة التحليل
15
  def analyze_sentiment(text):
16
+ results = sentiment_analyzer(text)[0] # نجيب كل النتائج (إيجابي، سلبي، محايد)
17
  output = ""
18
  for r in results:
19
  label = r["label"]
 
33
  inputs=gr.Textbox(lines=2, placeholder="متن خود را وارد کنید..."),
34
  outputs="text",
35
  title="تحلیل احساسات متون فارسی",
36
+ description="نمایش احتمال مثبت، منفی و خنثی بودن متن فارسی."
37
  )
38
 
39
  iface.launch()
40
+