Spaces:
Running
Running
RamiIbrahim
commited on
Commit
•
0c8ac4b
1
Parent(s):
bac5e0b
Update app.py
Browse files
app.py
CHANGED
@@ -14,11 +14,15 @@ def predict_sentiment(text):
|
|
14 |
|
15 |
sentiment = "Positive" if prediction == 1 else "Negative"
|
16 |
|
17 |
-
return
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
|
23 |
# Example texts
|
24 |
examples = [
|
@@ -28,16 +32,25 @@ examples = [
|
|
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
examples=
|
41 |
title="Tunisian Arabiz Sentiment Analysis",
|
42 |
description="""
|
43 |
This model predicts the sentiment of Tunisian Arabiz text as either Positive or Negative.
|
|
|
14 |
|
15 |
sentiment = "Positive" if prediction == 1 else "Negative"
|
16 |
|
17 |
+
return (
|
18 |
+
sentiment,
|
19 |
+
f"{confidence:.2f}",
|
20 |
+
f"The model predicts this text is {sentiment.lower()} with {confidence:.2%} confidence."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Function to get predictions for examples
|
24 |
+
def get_example_predictions(examples):
|
25 |
+
return [predict_sentiment(ex[0]) for ex in examples]
|
26 |
|
27 |
# Example texts
|
28 |
examples = [
|
|
|
32 |
["ennes el kol za3nin w ma3andhomch flous"]
|
33 |
]
|
34 |
|
35 |
+
# Get predictions for examples
|
36 |
+
example_predictions = get_example_predictions(examples)
|
37 |
+
|
38 |
+
# Create formatted examples with predictions
|
39 |
+
formatted_examples = [
|
40 |
+
[ex[0], f"{pred[0]} (Confidence: {pred[1]})"]
|
41 |
+
for ex, pred in zip(examples, example_predictions)
|
42 |
+
]
|
43 |
+
|
44 |
# Create Gradio interface
|
45 |
iface = gr.Interface(
|
46 |
fn=predict_sentiment,
|
47 |
inputs=gr.Textbox(lines=3, placeholder="Enter Tunisian Arabiz text here..."),
|
48 |
+
outputs=[
|
49 |
+
gr.Label(label="Predicted Sentiment"),
|
50 |
+
gr.Label(label="Confidence Score"),
|
51 |
+
gr.Textbox(label="Explanation")
|
52 |
+
],
|
53 |
+
examples=formatted_examples,
|
54 |
title="Tunisian Arabiz Sentiment Analysis",
|
55 |
description="""
|
56 |
This model predicts the sentiment of Tunisian Arabiz text as either Positive or Negative.
|