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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,11 +1,11 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Ensure the model is correctly loaded
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": "إيجابي",
@@ -13,30 +13,21 @@ label_mapping = {
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 {
23
- "التصنيف": sentiment_label,
24
- "نسبة الثقة": f"{confidence}%",
25
- }
26
 
27
- # Define Gradio interface with better UI
28
  with gr.Blocks(theme=gr.themes.Default()) as iface:
29
  gr.Markdown("<h1 style='text-align: center;'>🍽️ تحليل مشاعر مراجعات المطاعم 🚀</h1>")
30
- gr.Markdown(
31
- "<p style='text-align: center;'> 🤖 أدخل مراجعة مطعم بالعربية، وسيقوم النموذج بتحليل المشاعر وتحديدها **إيجابية** أو **سلبية**.</p>"
32
- )
33
 
34
  with gr.Row():
35
- review_input = gr.Textbox(
36
- label="✍️ أدخل مراجعتك",
37
- placeholder="اكتب مراجعتك هنا...",
38
- lines=2
39
- )
40
 
41
  submit_button = gr.Button("🔍 تحليل المراجعة")
42
 
@@ -59,4 +50,4 @@ with gr.Blocks(theme=gr.themes.Default()) as iface:
59
 
60
  # Launch the app with public sharing enabled
61
  if __name__ == "__main__":
62
- iface.launch(share=True)
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the sentiment analysis model
5
  model_name = "Abduuu/ArabReview-Sentiment"
6
  sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name)
7
 
8
+ # Define label mapping (handling both possible label formats)
9
  label_mapping = {
10
  "LABEL_0": "سلبي",
11
  "LABEL_1": "إيجابي",
 
13
  "Positive": "إيجابي"
14
  }
15
 
16
+ # Function to predict sentiment
17
  def predict_sentiment(review):
18
  result = sentiment_pipeline(review)[0]
19
+ sentiment_label = label_mapping.get(result["label"], "غير معروف") # Handle unexpected labels
20
+ confidence = f"{(result['score'] * 100):.2f}%"
21
 
22
+ return sentiment_label, confidence # Return as separate values
 
 
 
23
 
24
+ # Define Gradio interface
25
  with gr.Blocks(theme=gr.themes.Default()) as iface:
26
  gr.Markdown("<h1 style='text-align: center;'>🍽️ تحليل مشاعر مراجعات المطاعم 🚀</h1>")
27
+ gr.Markdown("<p style='text-align: center;'> 🤖 أدخل مراجعة مطعم بالعربية، وسيقوم النموذج بتحليل المشاعر.</p>")
 
 
28
 
29
  with gr.Row():
30
+ review_input = gr.Textbox(label="✍️ أدخل مراجعتك", placeholder="اكتب مراجعتك هنا...", lines=2)
 
 
 
 
31
 
32
  submit_button = gr.Button("🔍 تحليل المراجعة")
33
 
 
50
 
51
  # Launch the app with public sharing enabled
52
  if __name__ == "__main__":
53
+ iface.launch(share=True)