Abdulrahman Al-Ghamdi commited on
Commit
dc1c5f1
·
verified ·
1 Parent(s): f9e4334

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -5,16 +5,18 @@ from transformers import pipeline
5
  model_name = "Abduuu/ArabReview-Sentiment"
6
  sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name)
7
 
8
- # Define label mapping for better readability
9
  label_mapping = {
10
- "LABEL_0": "سـلـبـي 😞",
11
- "LABEL_1": "إيـجـابـي 😊"
 
 
12
  }
13
 
14
  # Function to predict sentiment with confidence visualization
15
  def predict_sentiment(review):
16
  result = sentiment_pipeline(review)[0]
17
- sentiment_label = label_mapping[result["label"]]
18
  confidence = round(result["score"] * 100, 2)
19
 
20
  return {
@@ -46,15 +48,15 @@ with gr.Blocks(theme=gr.themes.Default()) as iface:
46
 
47
  gr.Examples(
48
  examples=[
49
- ["🍛 الطعام لذيذ جدًا والخدمة ممتازة!"],
50
- ["🤢 للأسف، التجربة كانت سيئة والطعام غير نظيف!"],
51
- ["👎 الخدمة كانت بطيئة والأسعار مرتفعة جدًا."],
52
- ["👌 تجربة رائعة، سأعود مجددًا!"],
53
- ["🔥 أفضل مطعم جربته على الإطلاق!"],
54
  ],
55
  inputs=review_input,
56
  )
57
 
58
- # Launch the app
59
  if __name__ == "__main__":
60
- iface.launch()
 
5
  model_name = "Abduuu/ArabReview-Sentiment"
6
  sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name)
7
 
8
+ # Define label mapping (ensure it matches actual model outputs)
9
  label_mapping = {
10
+ "LABEL_0": "سلبي",
11
+ "LABEL_1": "إيجابي",
12
+ "Negative": "سلبي",
13
+ "Positive": "إيجابي"
14
  }
15
 
16
  # Function to predict sentiment with confidence visualization
17
  def predict_sentiment(review):
18
  result = sentiment_pipeline(review)[0]
19
+ sentiment_label = label_mapping.get(result["label"], result["label"]) # Handle unexpected labels
20
  confidence = round(result["score"] * 100, 2)
21
 
22
  return {
 
48
 
49
  gr.Examples(
50
  examples=[
51
+ ["الطعام لذيذ جدًا والخدمة ممتازة"],
52
+ ["التجربة كانت سيئة والطعام غير نظيف"],
53
+ ["الخدمة كانت بطيئة والأسعار مرتفعة جدًا"],
54
+ ["تجربة رائعة، سأعود مجددًا"],
55
+ ["أفضل مطعم جربته على الإطلاق"],
56
  ],
57
  inputs=review_input,
58
  )
59
 
60
+ # Launch the app with public sharing enabled
61
  if __name__ == "__main__":
62
+ iface.launch(share=True)