RamiIbrahim commited on
Commit
bac5e0b
1 Parent(s): af08641

Stable version 1

Browse files
Files changed (1) hide show
  1. app.py +43 -11
app.py CHANGED
@@ -7,28 +7,60 @@ model = joblib.load('tunisian_arabiz_sentiment_analysis_model.pkl')
7
  vectorizer = joblib.load('tfidf_vectorizer.pkl')
8
 
9
  def predict_sentiment(text):
10
- # Transform the input text using the loaded vectorizer
11
  text_vectorized = vectorizer.transform([text])
12
-
13
- # Make prediction
14
  prediction = model.predict(text_vectorized)[0]
15
-
16
- # Convert prediction to sentiment
17
- sentiment = "Positive" if prediction == 1 else "Negative"
18
-
19
- # Get prediction probability
20
  probabilities = model.predict_proba(text_vectorized)[0]
21
  confidence = max(probabilities)
22
 
23
- return f"Sentiment: {sentiment}\nConfidence: {confidence:.2f}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Create Gradio interface
26
  iface = gr.Interface(
27
  fn=predict_sentiment,
28
  inputs=gr.Textbox(lines=3, placeholder="Enter Tunisian Arabiz text here..."),
29
- outputs="text",
 
 
 
 
 
30
  title="Tunisian Arabiz Sentiment Analysis",
31
- description="This model predicts the sentiment of Tunisian Arabiz text as either Positive or Negative."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  )
33
 
34
  # Launch the interface
 
7
  vectorizer = joblib.load('tfidf_vectorizer.pkl')
8
 
9
  def predict_sentiment(text):
 
10
  text_vectorized = vectorizer.transform([text])
 
 
11
  prediction = model.predict(text_vectorized)[0]
 
 
 
 
 
12
  probabilities = model.predict_proba(text_vectorized)[0]
13
  confidence = max(probabilities)
14
 
15
+ sentiment = "Positive" if prediction == 1 else "Negative"
16
+
17
+ return {
18
+ "Sentiment": sentiment,
19
+ "Confidence": f"{confidence:.2f}",
20
+ "Explanation": f"The model predicts this text is {sentiment.lower()} with {confidence:.2%} confidence."
21
+ }
22
+
23
+ # Example texts
24
+ examples = [
25
+ ["3ajbetni barcha el film hedhi"],
26
+ ["ma7abitch el akla mte3 el restaurant"],
27
+ ["el jaw fi tounes a7la 7aja"],
28
+ ["ennes el kol za3nin w ma3andhomch flous"]
29
+ ]
30
 
31
  # Create Gradio interface
32
  iface = gr.Interface(
33
  fn=predict_sentiment,
34
  inputs=gr.Textbox(lines=3, placeholder="Enter Tunisian Arabiz text here..."),
35
+ outputs={
36
+ "Sentiment": gr.Label(label="Predicted Sentiment"),
37
+ "Confidence": gr.Label(label="Confidence Score"),
38
+ "Explanation": gr.Textbox(label="Explanation")
39
+ },
40
+ examples=examples,
41
  title="Tunisian Arabiz Sentiment Analysis",
42
+ description="""
43
+ This model predicts the sentiment of Tunisian Arabiz text as either Positive or Negative.
44
+
45
+ Tunisian Arabiz is a form of writing Arabic (specifically Tunisian dialect) using Latin characters and numbers.
46
+
47
+ Example:
48
+ - "3ajbetni" means "I liked it"
49
+ - "7aja" means "thing"
50
+
51
+ Try the examples below or enter your own text!
52
+ """,
53
+ article="""
54
+ <div style="text-align: center;">
55
+ <img src="https://upload.wikimedia.org/wikipedia/commons/c/ce/Flag_of_Tunisia.svg" alt="Tunisian Flag" style="width:150px;"/>
56
+ </div>
57
+ <h3>About the Model</h3>
58
+ <p>This sentiment analysis model was trained on a dataset combining TuniziDataset and the Tunisian Dialect Corpus.
59
+ It uses TF-IDF vectorization for feature extraction and Logistic Regression for classification.</p>
60
+ <h3>Limitations</h3>
61
+ <p>The model may not perform well on very colloquial expressions or new slang terms not present in the training data.
62
+ It's also important to note that sentiment can be nuanced and context-dependent, which may not always be captured by this model.</p>
63
+ """
64
  )
65
 
66
  # Launch the interface