Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,11 @@ import torch
|
|
4 |
from transformers import BertTokenizer, AutoModel
|
5 |
import tensorflow as tf
|
6 |
|
7 |
-
# Load tokenizer and BERT model for embeddings extraction
|
8 |
model_name = "aubmindlab/bert-base-arabertv02"
|
9 |
tokenizer = BertTokenizer.from_pretrained(model_name)
|
10 |
bert_model = AutoModel.from_pretrained(model_name)
|
11 |
bert_model.eval()
|
12 |
|
13 |
-
# Load your trained RNN model
|
14 |
model = tf.keras.models.load_model("rnn_Bi.h5")
|
15 |
print("✅ Model loaded successfully!")
|
16 |
|
@@ -29,7 +27,6 @@ def predict_sentiment(text):
|
|
29 |
confidence = pred if pred > 0.5 else 1 - pred
|
30 |
return label, confidence
|
31 |
|
32 |
-
# Custom CSS for better Arabic support and styling
|
33 |
css = """
|
34 |
body {
|
35 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
@@ -60,28 +57,18 @@ body {
|
|
60 |
|
61 |
with gr.Blocks(css=css) as iface:
|
62 |
gr.Markdown("## تحليل المشاعر بالعربية 📝", elem_id="title")
|
63 |
-
gr.Markdown(
|
64 |
-
|
65 |
-
elem_id="description"
|
66 |
-
)
|
67 |
-
text_input = gr.Textbox(
|
68 |
-
lines=3,
|
69 |
-
placeholder="اكتب جملتك هنا...",
|
70 |
-
label="النص"
|
71 |
-
)
|
72 |
predict_btn = gr.Button("تنبؤ")
|
73 |
sentiment_output = gr.Label(label="النتيجة")
|
74 |
-
|
75 |
|
76 |
def on_predict(text):
|
77 |
label, confidence = predict_sentiment(text)
|
78 |
-
|
|
|
79 |
|
80 |
-
predict_btn.click(
|
81 |
-
fn=on_predict,
|
82 |
-
inputs=text_input,
|
83 |
-
outputs=[sentiment_output, confidence_bar]
|
84 |
-
)
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
iface.launch()
|
|
|
4 |
from transformers import BertTokenizer, AutoModel
|
5 |
import tensorflow as tf
|
6 |
|
|
|
7 |
model_name = "aubmindlab/bert-base-arabertv02"
|
8 |
tokenizer = BertTokenizer.from_pretrained(model_name)
|
9 |
bert_model = AutoModel.from_pretrained(model_name)
|
10 |
bert_model.eval()
|
11 |
|
|
|
12 |
model = tf.keras.models.load_model("rnn_Bi.h5")
|
13 |
print("✅ Model loaded successfully!")
|
14 |
|
|
|
27 |
confidence = pred if pred > 0.5 else 1 - pred
|
28 |
return label, confidence
|
29 |
|
|
|
30 |
css = """
|
31 |
body {
|
32 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
57 |
|
58 |
with gr.Blocks(css=css) as iface:
|
59 |
gr.Markdown("## تحليل المشاعر بالعربية 📝", elem_id="title")
|
60 |
+
gr.Markdown("أدخل جملة لتحليل المشاعر: هل هي **إيجابية** أم **سلبية**؟", elem_id="description")
|
61 |
+
text_input = gr.Textbox(lines=3, placeholder="اكتب جملتك هنا...", label="النص")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
predict_btn = gr.Button("تنبؤ")
|
63 |
sentiment_output = gr.Label(label="النتيجة")
|
64 |
+
confidence_score = gr.Textbox(label="نسبة الثقة")
|
65 |
|
66 |
def on_predict(text):
|
67 |
label, confidence = predict_sentiment(text)
|
68 |
+
confidence_percent = f"{confidence*100:.1f}%"
|
69 |
+
return label, confidence_percent
|
70 |
|
71 |
+
predict_btn.click(fn=on_predict, inputs=text_input, outputs=[sentiment_output, confidence_score])
|
|
|
|
|
|
|
|
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
iface.launch()
|