RamiIbrahim
commited on
Commit
•
49f7354
1
Parent(s):
7ae7652
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
3 |
|
4 |
-
# Load
|
5 |
-
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
-
def
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
iface = gr.Interface(
|
18 |
-
fn=
|
19 |
-
inputs=gr.Textbox(lines=
|
20 |
-
outputs="
|
21 |
-
title="
|
22 |
-
description="
|
23 |
)
|
24 |
|
25 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
|
5 |
+
# Load the saved model and vectorizer
|
6 |
+
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
|