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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -3,17 +3,19 @@
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,8 +35,7 @@ iface = gr.Interface(
33
  inputs=gr.Textbox(lines=2, placeholder="متن خود را وارد کنید..."),
34
  outputs="text",
35
  title="تحلیل احساسات متون فارسی",
36
- description="نمایش احتمال مثبت، منفی و خنثی بودن متن فارسی."
37
  )
38
 
39
- iface.launch()
40
-
 
3
  from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
  import gradio as gr
5
 
6
+
7
+ model_name = "HooshvareLab/bert-fa-base-uncased-sentiment-snappfood"
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
  inputs=gr.Textbox(lines=2, placeholder="متن خود را وارد کنید..."),
36
  outputs="text",
37
  title="تحلیل احساسات متون فارسی",
38
+ description="نمایش احتمال مثبت، منفی و خنثی بودن متن فارسی با مدل Snapfood."
39
  )
40
 
41
+ iface.launch()