Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,46 +4,19 @@
|
|
| 4 |
# Multilingual UI: Français / العربية / English
|
| 5 |
# ============================================================
|
| 6 |
|
| 7 |
-
import os
|
| 8 |
import re
|
| 9 |
import html
|
| 10 |
-
from pathlib import Path
|
| 11 |
|
| 12 |
import torch
|
| 13 |
import gradio as gr
|
| 14 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 15 |
|
| 16 |
|
| 17 |
-
#
|
| 18 |
# 1) MODEL CONFIGURATION
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
#
|
| 22 |
-
# ./results_marbert_augmented_x4/final_model
|
| 23 |
-
# then:
|
| 24 |
-
# ./final_model
|
| 25 |
-
#
|
| 26 |
-
# You can also define MODEL_PATH as an environment variable.
|
| 27 |
-
|
| 28 |
-
# DEFAULT_MODEL_PATHS = [
|
| 29 |
-
# "results_marbert_augmented_x4/final_model",
|
| 30 |
-
# "final_model",
|
| 31 |
-
# ]
|
| 32 |
-
|
| 33 |
-
# MODEL_PATH = os.getenv("MODEL_PATH")
|
| 34 |
-
|
| 35 |
-
# if not MODEL_PATH:
|
| 36 |
-
# for candidate in DEFAULT_MODEL_PATHS:
|
| 37 |
-
# if Path(candidate).exists():
|
| 38 |
-
# MODEL_PATH = candidate
|
| 39 |
-
# break
|
| 40 |
-
|
| 41 |
-
# if not MODEL_PATH:
|
| 42 |
-
# raise FileNotFoundError(
|
| 43 |
-
# "Model folder not found. Upload the trained model folder as "
|
| 44 |
-
# "'results_marbert_augmented_x4/final_model' or 'final_model', "
|
| 45 |
-
# "or define the MODEL_PATH environment variable."
|
| 46 |
-
# )
|
| 47 |
MODEL_PATH = "."
|
| 48 |
|
| 49 |
ID2LABEL = {
|
|
@@ -98,10 +71,11 @@ COLORS = {
|
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
-
#
|
| 102 |
-
# 2)
|
| 103 |
-
#
|
| 104 |
|
|
|
|
| 105 |
ARABIC_REPLACEMENTS = {
|
| 106 |
# "أ": "ا",
|
| 107 |
# "إ": "ا",
|
|
@@ -121,48 +95,70 @@ DIACRITICS = re.compile(r"[ًٌٍَُِّْـ]")
|
|
| 121 |
def clean_hassaniya(text: str) -> str:
|
| 122 |
text = str(text)
|
| 123 |
|
|
|
|
| 124 |
text = re.sub(r"http\S+|www\S+", " ", text)
|
|
|
|
|
|
|
| 125 |
text = re.sub(r"@\w+|#\w+", " ", text)
|
|
|
|
|
|
|
| 126 |
text = re.sub(r"[a-zA-Z0-9]", " ", text)
|
|
|
|
|
|
|
| 127 |
text = re.sub(DIACRITICS, "", text)
|
| 128 |
|
|
|
|
| 129 |
for old, new in ARABIC_REPLACEMENTS.items():
|
| 130 |
text = text.replace(old, new)
|
| 131 |
|
|
|
|
| 132 |
text = re.sub(r"(.)\1{2,}", r"\1", text)
|
|
|
|
|
|
|
| 133 |
text = re.sub(r"[^\u0600-\u06FF\s]", " ", text)
|
|
|
|
|
|
|
| 134 |
text = re.sub(r"\s+", " ", text).strip()
|
| 135 |
|
| 136 |
return text
|
| 137 |
|
| 138 |
|
| 139 |
-
#
|
| 140 |
# 3) LOAD TOKENIZER + MODEL
|
| 141 |
-
#
|
| 142 |
|
| 143 |
-
device = torch.device(
|
|
|
|
|
|
|
| 144 |
|
| 145 |
print(f"Loading model from: {MODEL_PATH}")
|
| 146 |
print(f"Using device: {device}")
|
| 147 |
|
| 148 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
model.to(device)
|
| 152 |
model.eval()
|
| 153 |
|
| 154 |
|
| 155 |
-
#
|
| 156 |
# 4) PREDICTION
|
| 157 |
-
#
|
| 158 |
|
| 159 |
def predict_sentiment(text, language):
|
|
|
|
| 160 |
lang = language if language in UI_TEXT else "fr"
|
| 161 |
|
|
|
|
| 162 |
if not text or not str(text).strip():
|
| 163 |
return f"""
|
| 164 |
<div class="result-card">
|
| 165 |
-
<h3 class="empty-message">
|
|
|
|
|
|
|
| 166 |
</div>
|
| 167 |
"""
|
| 168 |
|
|
@@ -171,10 +167,13 @@ def predict_sentiment(text, language):
|
|
| 171 |
if not cleaned_text:
|
| 172 |
return f"""
|
| 173 |
<div class="result-card">
|
| 174 |
-
<h3 class="empty-message">
|
|
|
|
|
|
|
| 175 |
</div>
|
| 176 |
"""
|
| 177 |
|
|
|
|
| 178 |
inputs = tokenizer(
|
| 179 |
cleaned_text,
|
| 180 |
return_tensors="pt",
|
|
@@ -183,71 +182,120 @@ def predict_sentiment(text, language):
|
|
| 183 |
max_length=96,
|
| 184 |
)
|
| 185 |
|
| 186 |
-
inputs = {
|
|
|
|
|
|
|
|
|
|
| 187 |
|
|
|
|
| 188 |
with torch.inference_mode():
|
|
|
|
| 189 |
outputs = model(**inputs)
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
scores = {
|
| 193 |
ID2LABEL[i]: float(probs[i])
|
| 194 |
for i in range(len(ID2LABEL))
|
| 195 |
}
|
| 196 |
|
| 197 |
-
best_label = max(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
best_score = scores[best_label] * 100
|
| 199 |
best_color = COLORS[best_label]
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
bars_html = ""
|
| 202 |
|
| 203 |
-
for label in [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
percent = scores[label] * 100
|
| 205 |
color = COLORS[label]
|
| 206 |
display_label = LABELS[lang][label]
|
| 207 |
|
| 208 |
if label == "Negative":
|
| 209 |
text_color = "#dc2626"
|
|
|
|
| 210 |
elif label == "Positive":
|
| 211 |
text_color = "#2563eb"
|
|
|
|
| 212 |
else:
|
| 213 |
text_color = "#92400e"
|
| 214 |
|
| 215 |
bars_html += f"""
|
| 216 |
<div class="bar-row">
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
{display_label}
|
| 219 |
</div>
|
| 220 |
|
| 221 |
<div class="bar-track">
|
|
|
|
| 222 |
<div
|
| 223 |
class="bar-fill"
|
| 224 |
-
style="
|
|
|
|
|
|
|
|
|
|
| 225 |
></div>
|
|
|
|
| 226 |
</div>
|
| 227 |
|
| 228 |
<div class="bar-value">
|
| 229 |
{percent:.2f}%
|
| 230 |
</div>
|
|
|
|
| 231 |
</div>
|
| 232 |
"""
|
| 233 |
|
| 234 |
-
safe_cleaned_text = html.escape(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
return f"""
|
| 237 |
<div class="result-card">
|
| 238 |
|
| 239 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
<div class="prediction-title">
|
| 241 |
{UI_TEXT[lang]["prediction"]}
|
| 242 |
</div>
|
| 243 |
|
| 244 |
-
<div
|
|
|
|
|
|
|
|
|
|
| 245 |
{LABELS[lang][best_label]}
|
| 246 |
</div>
|
| 247 |
|
| 248 |
<div class="confidence">
|
| 249 |
-
{UI_TEXT[lang]["confidence"]}:
|
|
|
|
| 250 |
</div>
|
|
|
|
| 251 |
</div>
|
| 252 |
|
| 253 |
<div class="bars-container">
|
|
@@ -255,30 +303,50 @@ def predict_sentiment(text, language):
|
|
| 255 |
</div>
|
| 256 |
|
| 257 |
<div class="normalized-box">
|
| 258 |
-
|
| 259 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
</div>
|
| 261 |
|
| 262 |
</div>
|
| 263 |
"""
|
| 264 |
|
| 265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
def clear_fields():
|
|
|
|
| 267 |
return "", """
|
| 268 |
<div class="result-card">
|
|
|
|
| 269 |
<h3 class="result-placeholder">
|
| 270 |
Result will appear here
|
| 271 |
</h3>
|
|
|
|
| 272 |
</div>
|
| 273 |
"""
|
| 274 |
|
| 275 |
|
| 276 |
-
#
|
| 277 |
-
# 5)
|
| 278 |
-
#
|
| 279 |
|
| 280 |
custom_css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
.gradio-container {
|
|
|
|
| 282 |
background:
|
| 283 |
linear-gradient(
|
| 284 |
135deg,
|
|
@@ -286,368 +354,1040 @@ custom_css = """
|
|
| 286 |
#ffffff 47%,
|
| 287 |
#d01c1f 100%
|
| 288 |
) !important;
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
}
|
| 292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
#main-card {
|
|
|
|
|
|
|
|
|
|
| 294 |
max-width: 1180px;
|
|
|
|
| 295 |
margin: 28px auto;
|
|
|
|
| 296 |
padding: 30px;
|
|
|
|
|
|
|
|
|
|
| 297 |
border-radius: 26px;
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 301 |
}
|
| 302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
#header-box {
|
|
|
|
| 304 |
text-align: center;
|
|
|
|
| 305 |
padding: 30px;
|
|
|
|
| 306 |
border-radius: 22px;
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
margin-bottom: 24px;
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
| 311 |
}
|
| 312 |
|
|
|
|
| 313 |
#header-box h1 {
|
|
|
|
| 314 |
margin: 0;
|
|
|
|
| 315 |
font-size: 34px;
|
|
|
|
|
|
|
|
|
|
| 316 |
font-weight: 800;
|
|
|
|
|
|
|
| 317 |
}
|
| 318 |
|
|
|
|
| 319 |
#header-box p {
|
|
|
|
| 320 |
margin-top: 10px;
|
|
|
|
| 321 |
margin-bottom: 0;
|
|
|
|
| 322 |
font-size: 16px;
|
| 323 |
-
|
|
|
|
| 324 |
}
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
#language-selector {
|
|
|
|
| 327 |
margin-bottom: 14px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
}
|
| 329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
#input-box textarea {
|
|
|
|
| 331 |
direction: rtl !important;
|
|
|
|
| 332 |
text-align: right !important;
|
|
|
|
| 333 |
font-size: 18px !important;
|
|
|
|
| 334 |
line-height: 1.8 !important;
|
| 335 |
-
|
| 336 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
}
|
| 338 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
button.primary {
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
}
|
| 346 |
|
|
|
|
| 347 |
button.primary:hover {
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
}
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
.result-card {
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
}
|
| 359 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
.final-prediction {
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
}
|
| 368 |
|
|
|
|
| 369 |
.prediction-title {
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
}
|
| 375 |
|
|
|
|
| 376 |
.prediction-label {
|
| 377 |
-
|
| 378 |
-
font-
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
}
|
| 381 |
|
|
|
|
| 382 |
.confidence {
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 386 |
}
|
| 387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
.bars-container {
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
}
|
| 393 |
|
|
|
|
| 394 |
.bar-row {
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
}
|
| 400 |
|
|
|
|
| 401 |
.bar-label {
|
| 402 |
-
|
| 403 |
-
font-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
}
|
| 405 |
|
|
|
|
| 406 |
.bar-track {
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
}
|
| 413 |
|
|
|
|
| 414 |
.bar-fill {
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
}
|
| 419 |
|
|
|
|
| 420 |
.bar-value {
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
}
|
| 426 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
.normalized-box {
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
}
|
| 435 |
|
|
|
|
| 436 |
.normalized-box div {
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
}
|
| 442 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 443 |
.empty-message,
|
| 444 |
.result-placeholder {
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
}
|
| 449 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
footer {
|
| 451 |
-
|
|
|
|
|
|
|
| 452 |
}
|
| 453 |
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
.gradio-container {
|
| 457 |
-
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
}
|
| 460 |
|
|
|
|
| 461 |
#main-card {
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
}
|
| 468 |
|
|
|
|
|
|
|
|
|
|
| 469 |
#header-box {
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
}
|
| 474 |
|
|
|
|
| 475 |
#header-box h1 {
|
| 476 |
-
|
| 477 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
}
|
| 479 |
|
|
|
|
| 480 |
#header-box p {
|
| 481 |
-
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
}
|
| 484 |
|
|
|
|
|
|
|
|
|
|
| 485 |
#language-selector {
|
| 486 |
-
|
|
|
|
|
|
|
| 487 |
}
|
| 488 |
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
}
|
| 494 |
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 500 |
}
|
| 501 |
|
|
|
|
|
|
|
|
|
|
| 502 |
#input-box {
|
| 503 |
-
|
|
|
|
|
|
|
| 504 |
}
|
| 505 |
|
|
|
|
| 506 |
#input-box textarea {
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
}
|
| 512 |
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 517 |
}
|
| 518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 519 |
.result-card {
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
}
|
| 526 |
|
|
|
|
| 527 |
.final-prediction {
|
| 528 |
-
|
| 529 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
}
|
| 531 |
|
|
|
|
| 532 |
.prediction-title {
|
| 533 |
-
|
|
|
|
|
|
|
| 534 |
}
|
| 535 |
|
|
|
|
| 536 |
.prediction-label {
|
| 537 |
-
|
|
|
|
|
|
|
| 538 |
}
|
| 539 |
|
|
|
|
| 540 |
.confidence {
|
| 541 |
-
|
|
|
|
|
|
|
| 542 |
}
|
| 543 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
.bar-row {
|
| 545 |
-
|
| 546 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
}
|
| 548 |
|
|
|
|
| 549 |
.bar-label {
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
}
|
| 552 |
|
|
|
|
| 553 |
.bar-value {
|
| 554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
}
|
| 556 |
|
|
|
|
| 557 |
.bar-track {
|
| 558 |
-
|
|
|
|
|
|
|
| 559 |
}
|
| 560 |
|
|
|
|
|
|
|
|
|
|
| 561 |
.normalized-box {
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
}
|
| 566 |
|
|
|
|
| 567 |
.normalized-box div {
|
| 568 |
-
|
|
|
|
|
|
|
| 569 |
}
|
| 570 |
-
}
|
| 571 |
|
| 572 |
-
/* ------------------------------------------------------------
|
| 573 |
-
FIX TEXTE BLANC SUR FOND BLANC
|
| 574 |
-
------------------------------------------------------------ */
|
| 575 |
|
| 576 |
-
.
|
| 577 |
-
|
| 578 |
-
}
|
| 579 |
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
background: #ffffff !important;
|
| 584 |
-
-webkit-text-fill-color: #111827 !important;
|
| 585 |
-
}
|
| 586 |
|
| 587 |
-
/* Texte saisi */
|
| 588 |
-
textarea,
|
| 589 |
-
input {
|
| 590 |
-
color: #111827 !important;
|
| 591 |
-
background-color: #ffffff !important;
|
| 592 |
-
-webkit-text-fill-color: #111827 !important;
|
| 593 |
-
}
|
| 594 |
|
| 595 |
-
/*
|
| 596 |
-
label,
|
| 597 |
-
.gradio-container label,
|
| 598 |
-
.gradio-container span,
|
| 599 |
-
.gradio-container p {
|
| 600 |
-
color: #111827;
|
| 601 |
-
}
|
| 602 |
|
| 603 |
-
|
| 604 |
-
#language-selector {
|
| 605 |
-
color: #111827 !important;
|
| 606 |
-
}
|
| 607 |
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
}
|
| 611 |
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
|
| 618 |
-
.normalized-box {
|
| 619 |
-
color: #374151 !important;
|
| 620 |
-
background: #f3f4f6 !important;
|
| 621 |
}
|
| 622 |
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 629 |
}
|
|
|
|
| 630 |
"""
|
| 631 |
|
| 632 |
|
| 633 |
-
#
|
| 634 |
# 6) GRADIO INTERFACE
|
| 635 |
-
#
|
| 636 |
|
| 637 |
with gr.Blocks(
|
| 638 |
-
css=custom_css,
|
| 639 |
title="Hassaniya Sentiment Analysis",
|
| 640 |
) as demo:
|
| 641 |
|
| 642 |
-
with gr.Column(
|
|
|
|
|
|
|
| 643 |
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
|
| 652 |
language = gr.Radio(
|
| 653 |
choices=[
|
|
@@ -660,21 +1400,38 @@ with gr.Blocks(
|
|
| 660 |
elem_id="language-selector",
|
| 661 |
)
|
| 662 |
|
| 663 |
-
#
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
|
| 666 |
# INPUT
|
| 667 |
-
with gr.Column(
|
|
|
|
|
|
|
|
|
|
| 668 |
|
| 669 |
text_input = gr.Textbox(
|
| 670 |
lines=10,
|
| 671 |
placeholder="اكتب نصا بالحسانية هنا...",
|
| 672 |
-
label=
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
value="أنا ماشي عجلان يحنين حد",
|
| 674 |
elem_id="input-box",
|
| 675 |
)
|
| 676 |
|
| 677 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
btn = gr.Button(
|
| 679 |
"🔍 Analyser / تحليل / Analyze",
|
| 680 |
variant="primary",
|
|
@@ -682,55 +1439,86 @@ with gr.Blocks(
|
|
| 682 |
|
| 683 |
clear_btn = gr.Button(
|
| 684 |
"🗑️ Clear / Effacer / مسح",
|
|
|
|
| 685 |
)
|
| 686 |
|
|
|
|
| 687 |
# OUTPUT
|
| 688 |
-
with gr.Column(
|
|
|
|
|
|
|
|
|
|
| 689 |
|
| 690 |
output = gr.HTML(
|
| 691 |
value="""
|
| 692 |
<div class="result-card">
|
|
|
|
| 693 |
<h3 class="result-placeholder">
|
| 694 |
Result will appear here
|
| 695 |
</h3>
|
|
|
|
| 696 |
</div>
|
| 697 |
"""
|
| 698 |
)
|
| 699 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
gr.Examples(
|
| 701 |
examples=[
|
| 702 |
["ذ شغل زينة حته"],
|
| 703 |
["أنا ماشي عجلان يحنين حد"],
|
| 704 |
["الموقع عادي كاع ماه اكبر من كدو"],
|
| 705 |
-
["اشغل ماعجبتني"],
|
| 706 |
["شكرا بارك الله فيكم"],
|
| 707 |
],
|
| 708 |
-
inputs=[text_input
|
| 709 |
label="Examples / Exemples / أمثلة",
|
| 710 |
)
|
| 711 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 712 |
btn.click(
|
| 713 |
fn=predict_sentiment,
|
| 714 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
| 715 |
outputs=output,
|
| 716 |
)
|
| 717 |
|
| 718 |
text_input.submit(
|
| 719 |
fn=predict_sentiment,
|
| 720 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
| 721 |
outputs=output,
|
| 722 |
)
|
| 723 |
|
| 724 |
clear_btn.click(
|
| 725 |
fn=clear_fields,
|
| 726 |
inputs=None,
|
| 727 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
| 728 |
)
|
| 729 |
|
| 730 |
|
| 731 |
-
#
|
| 732 |
# 7) START APP
|
| 733 |
-
#
|
| 734 |
|
| 735 |
if __name__ == "__main__":
|
| 736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Multilingual UI: Français / العربية / English
|
| 5 |
# ============================================================
|
| 6 |
|
|
|
|
| 7 |
import re
|
| 8 |
import html
|
|
|
|
| 9 |
|
| 10 |
import torch
|
| 11 |
import gradio as gr
|
| 12 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 13 |
|
| 14 |
|
| 15 |
+
# ============================================================
|
| 16 |
# 1) MODEL CONFIGURATION
|
| 17 |
+
# ============================================================
|
| 18 |
+
|
| 19 |
+
# Model files are directly in the root of the Hugging Face Space
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
MODEL_PATH = "."
|
| 21 |
|
| 22 |
ID2LABEL = {
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
|
| 74 |
+
# ============================================================
|
| 75 |
+
# 2) HASSANIYA CLEANING
|
| 76 |
+
# ============================================================
|
| 77 |
|
| 78 |
+
# Keep this consistent with the preprocessing used during training.
|
| 79 |
ARABIC_REPLACEMENTS = {
|
| 80 |
# "أ": "ا",
|
| 81 |
# "إ": "ا",
|
|
|
|
| 95 |
def clean_hassaniya(text: str) -> str:
|
| 96 |
text = str(text)
|
| 97 |
|
| 98 |
+
# Remove URLs
|
| 99 |
text = re.sub(r"http\S+|www\S+", " ", text)
|
| 100 |
+
|
| 101 |
+
# Remove mentions and hashtags
|
| 102 |
text = re.sub(r"@\w+|#\w+", " ", text)
|
| 103 |
+
|
| 104 |
+
# Remove Latin characters and numbers
|
| 105 |
text = re.sub(r"[a-zA-Z0-9]", " ", text)
|
| 106 |
+
|
| 107 |
+
# Remove Arabic diacritics
|
| 108 |
text = re.sub(DIACRITICS, "", text)
|
| 109 |
|
| 110 |
+
# Optional Arabic normalization
|
| 111 |
for old, new in ARABIC_REPLACEMENTS.items():
|
| 112 |
text = text.replace(old, new)
|
| 113 |
|
| 114 |
+
# Reduce repeated characters
|
| 115 |
text = re.sub(r"(.)\1{2,}", r"\1", text)
|
| 116 |
+
|
| 117 |
+
# Keep Arabic characters only
|
| 118 |
text = re.sub(r"[^\u0600-\u06FF\s]", " ", text)
|
| 119 |
+
|
| 120 |
+
# Normalize spaces
|
| 121 |
text = re.sub(r"\s+", " ", text).strip()
|
| 122 |
|
| 123 |
return text
|
| 124 |
|
| 125 |
|
| 126 |
+
# ============================================================
|
| 127 |
# 3) LOAD TOKENIZER + MODEL
|
| 128 |
+
# ============================================================
|
| 129 |
|
| 130 |
+
device = torch.device(
|
| 131 |
+
"cuda" if torch.cuda.is_available() else "cpu"
|
| 132 |
+
)
|
| 133 |
|
| 134 |
print(f"Loading model from: {MODEL_PATH}")
|
| 135 |
print(f"Using device: {device}")
|
| 136 |
|
| 137 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
|
| 138 |
+
|
| 139 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 140 |
+
MODEL_PATH
|
| 141 |
+
)
|
| 142 |
|
| 143 |
model.to(device)
|
| 144 |
model.eval()
|
| 145 |
|
| 146 |
|
| 147 |
+
# ============================================================
|
| 148 |
# 4) PREDICTION
|
| 149 |
+
# ============================================================
|
| 150 |
|
| 151 |
def predict_sentiment(text, language):
|
| 152 |
+
|
| 153 |
lang = language if language in UI_TEXT else "fr"
|
| 154 |
|
| 155 |
+
# Empty input
|
| 156 |
if not text or not str(text).strip():
|
| 157 |
return f"""
|
| 158 |
<div class="result-card">
|
| 159 |
+
<h3 class="empty-message">
|
| 160 |
+
{UI_TEXT[lang]["empty"]}
|
| 161 |
+
</h3>
|
| 162 |
</div>
|
| 163 |
"""
|
| 164 |
|
|
|
|
| 167 |
if not cleaned_text:
|
| 168 |
return f"""
|
| 169 |
<div class="result-card">
|
| 170 |
+
<h3 class="empty-message">
|
| 171 |
+
{UI_TEXT[lang]["empty"]}
|
| 172 |
+
</h3>
|
| 173 |
</div>
|
| 174 |
"""
|
| 175 |
|
| 176 |
+
# Tokenization
|
| 177 |
inputs = tokenizer(
|
| 178 |
cleaned_text,
|
| 179 |
return_tensors="pt",
|
|
|
|
| 182 |
max_length=96,
|
| 183 |
)
|
| 184 |
|
| 185 |
+
inputs = {
|
| 186 |
+
key: value.to(device)
|
| 187 |
+
for key, value in inputs.items()
|
| 188 |
+
}
|
| 189 |
|
| 190 |
+
# Prediction
|
| 191 |
with torch.inference_mode():
|
| 192 |
+
|
| 193 |
outputs = model(**inputs)
|
| 194 |
+
|
| 195 |
+
probs = torch.softmax(
|
| 196 |
+
outputs.logits,
|
| 197 |
+
dim=-1
|
| 198 |
+
)[0].detach().cpu()
|
| 199 |
|
| 200 |
scores = {
|
| 201 |
ID2LABEL[i]: float(probs[i])
|
| 202 |
for i in range(len(ID2LABEL))
|
| 203 |
}
|
| 204 |
|
| 205 |
+
best_label = max(
|
| 206 |
+
scores,
|
| 207 |
+
key=scores.get
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
best_score = scores[best_label] * 100
|
| 211 |
best_color = COLORS[best_label]
|
| 212 |
|
| 213 |
+
# --------------------------------------------------------
|
| 214 |
+
# Sentiment bars
|
| 215 |
+
# --------------------------------------------------------
|
| 216 |
+
|
| 217 |
bars_html = ""
|
| 218 |
|
| 219 |
+
for label in [
|
| 220 |
+
"Positive",
|
| 221 |
+
"Neutral",
|
| 222 |
+
"Negative",
|
| 223 |
+
]:
|
| 224 |
+
|
| 225 |
percent = scores[label] * 100
|
| 226 |
color = COLORS[label]
|
| 227 |
display_label = LABELS[lang][label]
|
| 228 |
|
| 229 |
if label == "Negative":
|
| 230 |
text_color = "#dc2626"
|
| 231 |
+
|
| 232 |
elif label == "Positive":
|
| 233 |
text_color = "#2563eb"
|
| 234 |
+
|
| 235 |
else:
|
| 236 |
text_color = "#92400e"
|
| 237 |
|
| 238 |
bars_html += f"""
|
| 239 |
<div class="bar-row">
|
| 240 |
+
|
| 241 |
+
<div
|
| 242 |
+
class="bar-label"
|
| 243 |
+
style="color:{text_color} !important;"
|
| 244 |
+
>
|
| 245 |
{display_label}
|
| 246 |
</div>
|
| 247 |
|
| 248 |
<div class="bar-track">
|
| 249 |
+
|
| 250 |
<div
|
| 251 |
class="bar-fill"
|
| 252 |
+
style="
|
| 253 |
+
width:{percent:.2f}%;
|
| 254 |
+
background:{color};
|
| 255 |
+
"
|
| 256 |
></div>
|
| 257 |
+
|
| 258 |
</div>
|
| 259 |
|
| 260 |
<div class="bar-value">
|
| 261 |
{percent:.2f}%
|
| 262 |
</div>
|
| 263 |
+
|
| 264 |
</div>
|
| 265 |
"""
|
| 266 |
|
| 267 |
+
safe_cleaned_text = html.escape(
|
| 268 |
+
cleaned_text
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
# --------------------------------------------------------
|
| 272 |
+
# Result HTML
|
| 273 |
+
# --------------------------------------------------------
|
| 274 |
|
| 275 |
return f"""
|
| 276 |
<div class="result-card">
|
| 277 |
|
| 278 |
+
<div
|
| 279 |
+
class="final-prediction"
|
| 280 |
+
style="border-color:{best_color};"
|
| 281 |
+
>
|
| 282 |
+
|
| 283 |
<div class="prediction-title">
|
| 284 |
{UI_TEXT[lang]["prediction"]}
|
| 285 |
</div>
|
| 286 |
|
| 287 |
+
<div
|
| 288 |
+
class="prediction-label"
|
| 289 |
+
style="color:{best_color} !important;"
|
| 290 |
+
>
|
| 291 |
{LABELS[lang][best_label]}
|
| 292 |
</div>
|
| 293 |
|
| 294 |
<div class="confidence">
|
| 295 |
+
{UI_TEXT[lang]["confidence"]}:
|
| 296 |
+
{best_score:.2f}%
|
| 297 |
</div>
|
| 298 |
+
|
| 299 |
</div>
|
| 300 |
|
| 301 |
<div class="bars-container">
|
|
|
|
| 303 |
</div>
|
| 304 |
|
| 305 |
<div class="normalized-box">
|
| 306 |
+
|
| 307 |
+
<strong>
|
| 308 |
+
{UI_TEXT[lang]["normalized"]}:
|
| 309 |
+
</strong>
|
| 310 |
+
|
| 311 |
+
<div>
|
| 312 |
+
{safe_cleaned_text}
|
| 313 |
+
</div>
|
| 314 |
+
|
| 315 |
</div>
|
| 316 |
|
| 317 |
</div>
|
| 318 |
"""
|
| 319 |
|
| 320 |
|
| 321 |
+
# ============================================================
|
| 322 |
+
# CLEAR
|
| 323 |
+
# ============================================================
|
| 324 |
+
|
| 325 |
def clear_fields():
|
| 326 |
+
|
| 327 |
return "", """
|
| 328 |
<div class="result-card">
|
| 329 |
+
|
| 330 |
<h3 class="result-placeholder">
|
| 331 |
Result will appear here
|
| 332 |
</h3>
|
| 333 |
+
|
| 334 |
</div>
|
| 335 |
"""
|
| 336 |
|
| 337 |
|
| 338 |
+
# ============================================================
|
| 339 |
+
# 5) CSS
|
| 340 |
+
# ============================================================
|
| 341 |
|
| 342 |
custom_css = """
|
| 343 |
+
|
| 344 |
+
/* ============================================================
|
| 345 |
+
GLOBAL
|
| 346 |
+
============================================================ */
|
| 347 |
+
|
| 348 |
.gradio-container {
|
| 349 |
+
|
| 350 |
background:
|
| 351 |
linear-gradient(
|
| 352 |
135deg,
|
|
|
|
| 354 |
#ffffff 47%,
|
| 355 |
#d01c1f 100%
|
| 356 |
) !important;
|
| 357 |
+
|
| 358 |
+
font-family:
|
| 359 |
+
"Segoe UI",
|
| 360 |
+
Arial,
|
| 361 |
+
sans-serif !important;
|
| 362 |
+
|
| 363 |
+
min-height: 100vh !important;
|
| 364 |
+
|
| 365 |
+
color: #111827 !important;
|
| 366 |
+
|
| 367 |
+
overflow-x: hidden !important;
|
| 368 |
}
|
| 369 |
|
| 370 |
+
|
| 371 |
+
/* ============================================================
|
| 372 |
+
MAIN CARD
|
| 373 |
+
============================================================ */
|
| 374 |
+
|
| 375 |
#main-card {
|
| 376 |
+
|
| 377 |
+
width: calc(100% - 40px);
|
| 378 |
+
|
| 379 |
max-width: 1180px;
|
| 380 |
+
|
| 381 |
margin: 28px auto;
|
| 382 |
+
|
| 383 |
padding: 30px;
|
| 384 |
+
|
| 385 |
+
box-sizing: border-box;
|
| 386 |
+
|
| 387 |
border-radius: 26px;
|
| 388 |
+
|
| 389 |
+
background:
|
| 390 |
+
rgba(
|
| 391 |
+
255,
|
| 392 |
+
255,
|
| 393 |
+
255,
|
| 394 |
+
0.97
|
| 395 |
+
);
|
| 396 |
+
|
| 397 |
+
border:
|
| 398 |
+
3px solid
|
| 399 |
+
#ffc400;
|
| 400 |
+
|
| 401 |
+
box-shadow:
|
| 402 |
+
0 18px 45px
|
| 403 |
+
rgba(
|
| 404 |
+
0,
|
| 405 |
+
0,
|
| 406 |
+
0,
|
| 407 |
+
0.18
|
| 408 |
+
);
|
| 409 |
}
|
| 410 |
|
| 411 |
+
|
| 412 |
+
/* ============================================================
|
| 413 |
+
HEADER
|
| 414 |
+
============================================================ */
|
| 415 |
+
|
| 416 |
#header-box {
|
| 417 |
+
|
| 418 |
text-align: center;
|
| 419 |
+
|
| 420 |
padding: 30px;
|
| 421 |
+
|
| 422 |
border-radius: 22px;
|
| 423 |
+
|
| 424 |
+
background:
|
| 425 |
+
linear-gradient(
|
| 426 |
+
135deg,
|
| 427 |
+
#006233,
|
| 428 |
+
#008f4c
|
| 429 |
+
);
|
| 430 |
+
|
| 431 |
margin-bottom: 24px;
|
| 432 |
+
|
| 433 |
+
border-bottom:
|
| 434 |
+
7px solid
|
| 435 |
+
#ffc400;
|
| 436 |
}
|
| 437 |
|
| 438 |
+
|
| 439 |
#header-box h1 {
|
| 440 |
+
|
| 441 |
margin: 0;
|
| 442 |
+
|
| 443 |
font-size: 34px;
|
| 444 |
+
|
| 445 |
+
line-height: 1.25;
|
| 446 |
+
|
| 447 |
font-weight: 800;
|
| 448 |
+
|
| 449 |
+
color: #ffffff !important;
|
| 450 |
}
|
| 451 |
|
| 452 |
+
|
| 453 |
#header-box p {
|
| 454 |
+
|
| 455 |
margin-top: 10px;
|
| 456 |
+
|
| 457 |
margin-bottom: 0;
|
| 458 |
+
|
| 459 |
font-size: 16px;
|
| 460 |
+
|
| 461 |
+
color: #fff7cc !important;
|
| 462 |
}
|
| 463 |
|
| 464 |
+
|
| 465 |
+
/* ============================================================
|
| 466 |
+
LANGUAGE
|
| 467 |
+
============================================================ */
|
| 468 |
+
|
| 469 |
#language-selector {
|
| 470 |
+
|
| 471 |
margin-bottom: 14px;
|
| 472 |
+
|
| 473 |
+
color: #111827 !important;
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
#language-selector label {
|
| 478 |
+
|
| 479 |
+
color: #111827 !important;
|
| 480 |
}
|
| 481 |
|
| 482 |
+
|
| 483 |
+
/* ============================================================
|
| 484 |
+
INPUT TEXTBOX
|
| 485 |
+
============================================================ */
|
| 486 |
+
|
| 487 |
#input-box textarea {
|
| 488 |
+
|
| 489 |
direction: rtl !important;
|
| 490 |
+
|
| 491 |
text-align: right !important;
|
| 492 |
+
|
| 493 |
font-size: 18px !important;
|
| 494 |
+
|
| 495 |
line-height: 1.8 !important;
|
| 496 |
+
|
| 497 |
+
color: #111827 !important;
|
| 498 |
+
|
| 499 |
+
-webkit-text-fill-color:
|
| 500 |
+
#111827 !important;
|
| 501 |
+
|
| 502 |
+
background:
|
| 503 |
+
#ffffff !important;
|
| 504 |
+
|
| 505 |
+
border:
|
| 506 |
+
2px solid
|
| 507 |
+
#006233 !important;
|
| 508 |
+
|
| 509 |
+
border-radius:
|
| 510 |
+
14px !important;
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
|
| 514 |
+
#input-box textarea::placeholder {
|
| 515 |
+
|
| 516 |
+
color: #6b7280 !important;
|
| 517 |
+
|
| 518 |
+
-webkit-text-fill-color:
|
| 519 |
+
#6b7280 !important;
|
| 520 |
+
|
| 521 |
+
opacity: 1 !important;
|
| 522 |
}
|
| 523 |
|
| 524 |
+
|
| 525 |
+
/* ============================================================
|
| 526 |
+
GRADIO INPUTS
|
| 527 |
+
============================================================ */
|
| 528 |
+
|
| 529 |
+
.gradio-container textarea,
|
| 530 |
+
.gradio-container input {
|
| 531 |
+
|
| 532 |
+
color: #111827 !important;
|
| 533 |
+
|
| 534 |
+
-webkit-text-fill-color:
|
| 535 |
+
#111827 !important;
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
/* ============================================================
|
| 540 |
+
COMPONENT LABELS
|
| 541 |
+
============================================================ */
|
| 542 |
+
|
| 543 |
+
.gradio-container label {
|
| 544 |
+
|
| 545 |
+
color: #111827 !important;
|
| 546 |
+
}
|
| 547 |
+
|
| 548 |
+
|
| 549 |
+
/* ============================================================
|
| 550 |
+
BUTTONS
|
| 551 |
+
============================================================ */
|
| 552 |
+
|
| 553 |
button.primary {
|
| 554 |
+
|
| 555 |
+
background:
|
| 556 |
+
linear-gradient(
|
| 557 |
+
135deg,
|
| 558 |
+
#006233,
|
| 559 |
+
#008f4c
|
| 560 |
+
) !important;
|
| 561 |
+
|
| 562 |
+
color:
|
| 563 |
+
#ffffff !important;
|
| 564 |
+
|
| 565 |
+
border-radius:
|
| 566 |
+
14px !important;
|
| 567 |
+
|
| 568 |
+
border:
|
| 569 |
+
none !important;
|
| 570 |
+
|
| 571 |
+
font-weight:
|
| 572 |
+
800 !important;
|
| 573 |
}
|
| 574 |
|
| 575 |
+
|
| 576 |
button.primary:hover {
|
| 577 |
+
|
| 578 |
+
background:
|
| 579 |
+
linear-gradient(
|
| 580 |
+
135deg,
|
| 581 |
+
#004d28,
|
| 582 |
+
#006233
|
| 583 |
+
) !important;
|
| 584 |
}
|
| 585 |
|
| 586 |
+
|
| 587 |
+
/* Clear button */
|
| 588 |
+
|
| 589 |
+
#clear-button {
|
| 590 |
+
|
| 591 |
+
color:
|
| 592 |
+
#111827 !important;
|
| 593 |
+
|
| 594 |
+
background:
|
| 595 |
+
#ffffff !important;
|
| 596 |
+
|
| 597 |
+
border:
|
| 598 |
+
1px solid
|
| 599 |
+
#d1d5db !important;
|
| 600 |
+
|
| 601 |
+
border-radius:
|
| 602 |
+
14px !important;
|
| 603 |
+
|
| 604 |
+
font-weight:
|
| 605 |
+
700 !important;
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
|
| 609 |
+
/* ============================================================
|
| 610 |
+
RESULT CARD
|
| 611 |
+
============================================================ */
|
| 612 |
+
|
| 613 |
.result-card {
|
| 614 |
+
|
| 615 |
+
width: 100%;
|
| 616 |
+
|
| 617 |
+
box-sizing: border-box;
|
| 618 |
+
|
| 619 |
+
background:
|
| 620 |
+
#ffffff !important;
|
| 621 |
+
|
| 622 |
+
color:
|
| 623 |
+
#111827 !important;
|
| 624 |
+
|
| 625 |
+
border-radius:
|
| 626 |
+
20px;
|
| 627 |
+
|
| 628 |
+
padding:
|
| 629 |
+
24px;
|
| 630 |
+
|
| 631 |
+
border:
|
| 632 |
+
2px solid
|
| 633 |
+
#ffc400;
|
| 634 |
+
|
| 635 |
+
box-shadow:
|
| 636 |
+
0 12px 30px
|
| 637 |
+
rgba(
|
| 638 |
+
0,
|
| 639 |
+
0,
|
| 640 |
+
0,
|
| 641 |
+
0.12
|
| 642 |
+
);
|
| 643 |
+
|
| 644 |
+
min-height:
|
| 645 |
+
290px;
|
| 646 |
}
|
| 647 |
|
| 648 |
+
|
| 649 |
+
/* ============================================================
|
| 650 |
+
FINAL PREDICTION
|
| 651 |
+
============================================================ */
|
| 652 |
+
|
| 653 |
.final-prediction {
|
| 654 |
+
|
| 655 |
+
text-align:
|
| 656 |
+
center;
|
| 657 |
+
|
| 658 |
+
padding:
|
| 659 |
+
20px;
|
| 660 |
+
|
| 661 |
+
border:
|
| 662 |
+
3px solid;
|
| 663 |
+
|
| 664 |
+
border-radius:
|
| 665 |
+
18px;
|
| 666 |
+
|
| 667 |
+
margin-bottom:
|
| 668 |
+
24px;
|
| 669 |
+
|
| 670 |
+
background:
|
| 671 |
+
#f9fafb !important;
|
| 672 |
}
|
| 673 |
|
| 674 |
+
|
| 675 |
.prediction-title {
|
| 676 |
+
|
| 677 |
+
font-size:
|
| 678 |
+
15px;
|
| 679 |
+
|
| 680 |
+
color:
|
| 681 |
+
#374151 !important;
|
| 682 |
+
|
| 683 |
+
font-weight:
|
| 684 |
+
700;
|
| 685 |
+
|
| 686 |
+
margin-bottom:
|
| 687 |
+
8px;
|
| 688 |
}
|
| 689 |
|
| 690 |
+
|
| 691 |
.prediction-label {
|
| 692 |
+
|
| 693 |
+
font-size:
|
| 694 |
+
34px;
|
| 695 |
+
|
| 696 |
+
font-weight:
|
| 697 |
+
900;
|
| 698 |
+
|
| 699 |
+
margin-bottom:
|
| 700 |
+
8px;
|
| 701 |
}
|
| 702 |
|
| 703 |
+
|
| 704 |
.confidence {
|
| 705 |
+
|
| 706 |
+
font-size:
|
| 707 |
+
16px;
|
| 708 |
+
|
| 709 |
+
color:
|
| 710 |
+
#111827 !important;
|
| 711 |
+
|
| 712 |
+
font-weight:
|
| 713 |
+
700;
|
| 714 |
}
|
| 715 |
|
| 716 |
+
|
| 717 |
+
/* ============================================================
|
| 718 |
+
SENTIMENT BARS
|
| 719 |
+
============================================================ */
|
| 720 |
+
|
| 721 |
.bars-container {
|
| 722 |
+
|
| 723 |
+
display:
|
| 724 |
+
flex;
|
| 725 |
+
|
| 726 |
+
flex-direction:
|
| 727 |
+
column;
|
| 728 |
+
|
| 729 |
+
gap:
|
| 730 |
+
16px;
|
| 731 |
}
|
| 732 |
|
| 733 |
+
|
| 734 |
.bar-row {
|
| 735 |
+
|
| 736 |
+
display:
|
| 737 |
+
grid;
|
| 738 |
+
|
| 739 |
+
grid-template-columns:
|
| 740 |
+
110px
|
| 741 |
+
minmax(120px, 1fr)
|
| 742 |
+
80px;
|
| 743 |
+
|
| 744 |
+
gap:
|
| 745 |
+
12px;
|
| 746 |
+
|
| 747 |
+
align-items:
|
| 748 |
+
center;
|
| 749 |
}
|
| 750 |
|
| 751 |
+
|
| 752 |
.bar-label {
|
| 753 |
+
|
| 754 |
+
font-weight:
|
| 755 |
+
800;
|
| 756 |
+
|
| 757 |
+
font-size:
|
| 758 |
+
15px;
|
| 759 |
}
|
| 760 |
|
| 761 |
+
|
| 762 |
.bar-track {
|
| 763 |
+
|
| 764 |
+
width:
|
| 765 |
+
100%;
|
| 766 |
+
|
| 767 |
+
height:
|
| 768 |
+
24px;
|
| 769 |
+
|
| 770 |
+
background:
|
| 771 |
+
#e5e7eb !important;
|
| 772 |
+
|
| 773 |
+
border-radius:
|
| 774 |
+
999px;
|
| 775 |
+
|
| 776 |
+
overflow:
|
| 777 |
+
hidden;
|
| 778 |
}
|
| 779 |
|
| 780 |
+
|
| 781 |
.bar-fill {
|
| 782 |
+
|
| 783 |
+
height:
|
| 784 |
+
100%;
|
| 785 |
+
|
| 786 |
+
border-radius:
|
| 787 |
+
999px;
|
| 788 |
+
|
| 789 |
+
transition:
|
| 790 |
+
width
|
| 791 |
+
0.45s ease;
|
| 792 |
}
|
| 793 |
|
| 794 |
+
|
| 795 |
.bar-value {
|
| 796 |
+
|
| 797 |
+
font-weight:
|
| 798 |
+
800;
|
| 799 |
+
|
| 800 |
+
color:
|
| 801 |
+
#111827 !important;
|
| 802 |
+
|
| 803 |
+
font-size:
|
| 804 |
+
14px;
|
| 805 |
+
|
| 806 |
+
text-align:
|
| 807 |
+
right;
|
| 808 |
}
|
| 809 |
|
| 810 |
+
|
| 811 |
+
/* ============================================================
|
| 812 |
+
NORMALIZED TEXT
|
| 813 |
+
============================================================ */
|
| 814 |
+
|
| 815 |
.normalized-box {
|
| 816 |
+
|
| 817 |
+
margin-top:
|
| 818 |
+
22px;
|
| 819 |
+
|
| 820 |
+
padding:
|
| 821 |
+
14px 16px;
|
| 822 |
+
|
| 823 |
+
border-radius:
|
| 824 |
+
14px;
|
| 825 |
+
|
| 826 |
+
background:
|
| 827 |
+
#f3f4f6 !important;
|
| 828 |
+
|
| 829 |
+
color:
|
| 830 |
+
#374151 !important;
|
| 831 |
+
|
| 832 |
+
font-size:
|
| 833 |
+
13px;
|
| 834 |
+
|
| 835 |
+
overflow-wrap:
|
| 836 |
+
anywhere;
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
|
| 840 |
+
.normalized-box strong {
|
| 841 |
+
|
| 842 |
+
color:
|
| 843 |
+
#374151 !important;
|
| 844 |
}
|
| 845 |
|
| 846 |
+
|
| 847 |
.normalized-box div {
|
| 848 |
+
|
| 849 |
+
margin-top:
|
| 850 |
+
6px;
|
| 851 |
+
|
| 852 |
+
direction:
|
| 853 |
+
rtl;
|
| 854 |
+
|
| 855 |
+
text-align:
|
| 856 |
+
right;
|
| 857 |
+
|
| 858 |
+
font-size:
|
| 859 |
+
15px;
|
| 860 |
+
|
| 861 |
+
color:
|
| 862 |
+
#111827 !important;
|
| 863 |
}
|
| 864 |
|
| 865 |
+
|
| 866 |
+
/* ============================================================
|
| 867 |
+
PLACEHOLDER RESULT
|
| 868 |
+
============================================================ */
|
| 869 |
+
|
| 870 |
.empty-message,
|
| 871 |
.result-placeholder {
|
| 872 |
+
|
| 873 |
+
text-align:
|
| 874 |
+
center;
|
| 875 |
+
|
| 876 |
+
color:
|
| 877 |
+
#006233 !important;
|
| 878 |
+
|
| 879 |
+
padding-top:
|
| 880 |
+
80px;
|
| 881 |
+
}
|
| 882 |
+
|
| 883 |
+
|
| 884 |
+
/* ============================================================
|
| 885 |
+
EXAMPLES
|
| 886 |
+
============================================================ */
|
| 887 |
+
|
| 888 |
+
.gradio-container table {
|
| 889 |
+
|
| 890 |
+
background:
|
| 891 |
+
#ffffff !important;
|
| 892 |
+
|
| 893 |
+
color:
|
| 894 |
+
#111827 !important;
|
| 895 |
+
}
|
| 896 |
+
|
| 897 |
+
|
| 898 |
+
.gradio-container table td,
|
| 899 |
+
.gradio-container table th {
|
| 900 |
+
|
| 901 |
+
color:
|
| 902 |
+
#111827 !important;
|
| 903 |
+
|
| 904 |
+
background:
|
| 905 |
+
#ffffff !important;
|
| 906 |
}
|
| 907 |
|
| 908 |
+
|
| 909 |
+
.gradio-container table td *,
|
| 910 |
+
.gradio-container table th * {
|
| 911 |
+
|
| 912 |
+
color:
|
| 913 |
+
#111827 !important;
|
| 914 |
+
}
|
| 915 |
+
|
| 916 |
+
|
| 917 |
+
.gradio-container table button {
|
| 918 |
+
|
| 919 |
+
color:
|
| 920 |
+
#111827 !important;
|
| 921 |
+
|
| 922 |
+
background:
|
| 923 |
+
#ffffff !important;
|
| 924 |
+
|
| 925 |
+
-webkit-text-fill-color:
|
| 926 |
+
#111827 !important;
|
| 927 |
+
}
|
| 928 |
+
|
| 929 |
+
|
| 930 |
+
/* ============================================================
|
| 931 |
+
FOOTER
|
| 932 |
+
============================================================ */
|
| 933 |
+
|
| 934 |
footer {
|
| 935 |
+
|
| 936 |
+
display:
|
| 937 |
+
none !important;
|
| 938 |
}
|
| 939 |
|
| 940 |
+
|
| 941 |
+
/* ============================================================
|
| 942 |
+
TABLET
|
| 943 |
+
============================================================ */
|
| 944 |
+
|
| 945 |
+
@media (
|
| 946 |
+
min-width: 769px
|
| 947 |
+
)
|
| 948 |
+
and (
|
| 949 |
+
max-width: 1024px
|
| 950 |
+
) {
|
| 951 |
+
|
| 952 |
+
#main-card {
|
| 953 |
+
|
| 954 |
+
width:
|
| 955 |
+
calc(
|
| 956 |
+
100% - 24px
|
| 957 |
+
);
|
| 958 |
+
|
| 959 |
+
margin:
|
| 960 |
+
12px auto;
|
| 961 |
+
|
| 962 |
+
padding:
|
| 963 |
+
20px;
|
| 964 |
+
}
|
| 965 |
+
|
| 966 |
+
}
|
| 967 |
+
|
| 968 |
+
|
| 969 |
+
/* ============================================================
|
| 970 |
+
MOBILE
|
| 971 |
+
============================================================ */
|
| 972 |
+
|
| 973 |
+
@media (
|
| 974 |
+
max-width: 768px
|
| 975 |
+
) {
|
| 976 |
|
| 977 |
.gradio-container {
|
| 978 |
+
|
| 979 |
+
padding:
|
| 980 |
+
0 !important;
|
| 981 |
+
|
| 982 |
+
overflow-x:
|
| 983 |
+
hidden !important;
|
| 984 |
}
|
| 985 |
|
| 986 |
+
|
| 987 |
#main-card {
|
| 988 |
+
|
| 989 |
+
width:
|
| 990 |
+
calc(
|
| 991 |
+
100% - 12px
|
| 992 |
+
) !important;
|
| 993 |
+
|
| 994 |
+
max-width:
|
| 995 |
+
100% !important;
|
| 996 |
+
|
| 997 |
+
margin:
|
| 998 |
+
6px auto !important;
|
| 999 |
+
|
| 1000 |
+
padding:
|
| 1001 |
+
10px !important;
|
| 1002 |
+
|
| 1003 |
+
border-radius:
|
| 1004 |
+
14px !important;
|
| 1005 |
+
|
| 1006 |
+
border-width:
|
| 1007 |
+
2px !important;
|
| 1008 |
}
|
| 1009 |
|
| 1010 |
+
|
| 1011 |
+
/* HEADER */
|
| 1012 |
+
|
| 1013 |
#header-box {
|
| 1014 |
+
|
| 1015 |
+
padding:
|
| 1016 |
+
17px 10px !important;
|
| 1017 |
+
|
| 1018 |
+
border-radius:
|
| 1019 |
+
13px !important;
|
| 1020 |
+
|
| 1021 |
+
margin-bottom:
|
| 1022 |
+
12px !important;
|
| 1023 |
+
|
| 1024 |
+
border-bottom-width:
|
| 1025 |
+
5px !important;
|
| 1026 |
}
|
| 1027 |
|
| 1028 |
+
|
| 1029 |
#header-box h1 {
|
| 1030 |
+
|
| 1031 |
+
font-size:
|
| 1032 |
+
21px !important;
|
| 1033 |
+
|
| 1034 |
+
line-height:
|
| 1035 |
+
1.25 !important;
|
| 1036 |
}
|
| 1037 |
|
| 1038 |
+
|
| 1039 |
#header-box p {
|
| 1040 |
+
|
| 1041 |
+
font-size:
|
| 1042 |
+
12px !important;
|
| 1043 |
+
|
| 1044 |
+
line-height:
|
| 1045 |
+
1.45 !important;
|
| 1046 |
+
|
| 1047 |
+
margin-top:
|
| 1048 |
+
6px !important;
|
| 1049 |
}
|
| 1050 |
|
| 1051 |
+
|
| 1052 |
+
/* LANGUAGE */
|
| 1053 |
+
|
| 1054 |
#language-selector {
|
| 1055 |
+
|
| 1056 |
+
width:
|
| 1057 |
+
100% !important;
|
| 1058 |
}
|
| 1059 |
|
| 1060 |
+
|
| 1061 |
+
/* MAIN INPUT / OUTPUT ROW */
|
| 1062 |
+
|
| 1063 |
+
#main-row {
|
| 1064 |
+
|
| 1065 |
+
flex-direction:
|
| 1066 |
+
column !important;
|
| 1067 |
+
|
| 1068 |
+
flex-wrap:
|
| 1069 |
+
nowrap !important;
|
| 1070 |
+
|
| 1071 |
+
gap:
|
| 1072 |
+
12px !important;
|
| 1073 |
}
|
| 1074 |
|
| 1075 |
+
|
| 1076 |
+
#main-row > div {
|
| 1077 |
+
|
| 1078 |
+
width:
|
| 1079 |
+
100% !important;
|
| 1080 |
+
|
| 1081 |
+
max-width:
|
| 1082 |
+
100% !important;
|
| 1083 |
+
|
| 1084 |
+
min-width:
|
| 1085 |
+
0 !important;
|
| 1086 |
+
|
| 1087 |
+
flex:
|
| 1088 |
+
1 1 100% !important;
|
| 1089 |
}
|
| 1090 |
|
| 1091 |
+
|
| 1092 |
+
/* INPUT */
|
| 1093 |
+
|
| 1094 |
#input-box {
|
| 1095 |
+
|
| 1096 |
+
width:
|
| 1097 |
+
100% !important;
|
| 1098 |
}
|
| 1099 |
|
| 1100 |
+
|
| 1101 |
#input-box textarea {
|
| 1102 |
+
|
| 1103 |
+
width:
|
| 1104 |
+
100% !important;
|
| 1105 |
+
|
| 1106 |
+
min-height:
|
| 1107 |
+
145px !important;
|
| 1108 |
+
|
| 1109 |
+
font-size:
|
| 1110 |
+
16px !important;
|
| 1111 |
+
|
| 1112 |
+
line-height:
|
| 1113 |
+
1.7 !important;
|
| 1114 |
}
|
| 1115 |
|
| 1116 |
+
|
| 1117 |
+
/* BUTTONS */
|
| 1118 |
+
|
| 1119 |
+
#action-row {
|
| 1120 |
+
|
| 1121 |
+
gap:
|
| 1122 |
+
8px !important;
|
| 1123 |
+
|
| 1124 |
+
flex-wrap:
|
| 1125 |
+
wrap !important;
|
| 1126 |
}
|
| 1127 |
|
| 1128 |
+
|
| 1129 |
+
#action-row button {
|
| 1130 |
+
|
| 1131 |
+
min-height:
|
| 1132 |
+
46px !important;
|
| 1133 |
+
|
| 1134 |
+
font-size:
|
| 1135 |
+
13px !important;
|
| 1136 |
+
|
| 1137 |
+
flex:
|
| 1138 |
+
1 1 145px !important;
|
| 1139 |
+
}
|
| 1140 |
+
|
| 1141 |
+
|
| 1142 |
+
/* RESULT */
|
| 1143 |
+
|
| 1144 |
.result-card {
|
| 1145 |
+
|
| 1146 |
+
width:
|
| 1147 |
+
100% !important;
|
| 1148 |
+
|
| 1149 |
+
min-height:
|
| 1150 |
+
auto !important;
|
| 1151 |
+
|
| 1152 |
+
padding:
|
| 1153 |
+
14px !important;
|
| 1154 |
+
|
| 1155 |
+
border-radius:
|
| 1156 |
+
13px !important;
|
| 1157 |
}
|
| 1158 |
|
| 1159 |
+
|
| 1160 |
.final-prediction {
|
| 1161 |
+
|
| 1162 |
+
padding:
|
| 1163 |
+
13px !important;
|
| 1164 |
+
|
| 1165 |
+
margin-bottom:
|
| 1166 |
+
16px !important;
|
| 1167 |
+
|
| 1168 |
+
border-radius:
|
| 1169 |
+
12px !important;
|
| 1170 |
}
|
| 1171 |
|
| 1172 |
+
|
| 1173 |
.prediction-title {
|
| 1174 |
+
|
| 1175 |
+
font-size:
|
| 1176 |
+
13px !important;
|
| 1177 |
}
|
| 1178 |
|
| 1179 |
+
|
| 1180 |
.prediction-label {
|
| 1181 |
+
|
| 1182 |
+
font-size:
|
| 1183 |
+
26px !important;
|
| 1184 |
}
|
| 1185 |
|
| 1186 |
+
|
| 1187 |
.confidence {
|
| 1188 |
+
|
| 1189 |
+
font-size:
|
| 1190 |
+
14px !important;
|
| 1191 |
}
|
| 1192 |
|
| 1193 |
+
|
| 1194 |
+
/* BARS */
|
| 1195 |
+
|
| 1196 |
+
.bars-container {
|
| 1197 |
+
|
| 1198 |
+
gap:
|
| 1199 |
+
12px !important;
|
| 1200 |
+
}
|
| 1201 |
+
|
| 1202 |
+
|
| 1203 |
.bar-row {
|
| 1204 |
+
|
| 1205 |
+
grid-template-columns:
|
| 1206 |
+
68px
|
| 1207 |
+
minmax(0, 1fr)
|
| 1208 |
+
54px !important;
|
| 1209 |
+
|
| 1210 |
+
gap:
|
| 1211 |
+
6px !important;
|
| 1212 |
}
|
| 1213 |
|
| 1214 |
+
|
| 1215 |
.bar-label {
|
| 1216 |
+
|
| 1217 |
+
font-size:
|
| 1218 |
+
12px !important;
|
| 1219 |
+
|
| 1220 |
+
overflow:
|
| 1221 |
+
hidden;
|
| 1222 |
+
|
| 1223 |
+
text-overflow:
|
| 1224 |
+
ellipsis;
|
| 1225 |
}
|
| 1226 |
|
| 1227 |
+
|
| 1228 |
.bar-value {
|
| 1229 |
+
|
| 1230 |
+
font-size:
|
| 1231 |
+
11px !important;
|
| 1232 |
+
|
| 1233 |
+
color:
|
| 1234 |
+
#111827 !important;
|
| 1235 |
}
|
| 1236 |
|
| 1237 |
+
|
| 1238 |
.bar-track {
|
| 1239 |
+
|
| 1240 |
+
height:
|
| 1241 |
+
17px !important;
|
| 1242 |
}
|
| 1243 |
|
| 1244 |
+
|
| 1245 |
+
/* NORMALIZED */
|
| 1246 |
+
|
| 1247 |
.normalized-box {
|
| 1248 |
+
|
| 1249 |
+
padding:
|
| 1250 |
+
11px !important;
|
| 1251 |
+
|
| 1252 |
+
font-size:
|
| 1253 |
+
12px !important;
|
| 1254 |
+
|
| 1255 |
+
margin-top:
|
| 1256 |
+
16px !important;
|
| 1257 |
}
|
| 1258 |
|
| 1259 |
+
|
| 1260 |
.normalized-box div {
|
| 1261 |
+
|
| 1262 |
+
font-size:
|
| 1263 |
+
14px !important;
|
| 1264 |
}
|
|
|
|
| 1265 |
|
|
|
|
|
|
|
|
|
|
| 1266 |
|
| 1267 |
+
.empty-message,
|
| 1268 |
+
.result-placeholder {
|
|
|
|
| 1269 |
|
| 1270 |
+
padding-top:
|
| 1271 |
+
35px !important;
|
| 1272 |
+
}
|
|
|
|
|
|
|
|
|
|
| 1273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1274 |
|
| 1275 |
+
/* EXAMPLES */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1276 |
|
| 1277 |
+
.gradio-container table {
|
|
|
|
|
|
|
|
|
|
| 1278 |
|
| 1279 |
+
width:
|
| 1280 |
+
100% !important;
|
|
|
|
| 1281 |
|
| 1282 |
+
font-size:
|
| 1283 |
+
13px !important;
|
| 1284 |
+
}
|
| 1285 |
+
|
| 1286 |
+
|
| 1287 |
+
.gradio-container table td {
|
| 1288 |
+
|
| 1289 |
+
color:
|
| 1290 |
+
#111827 !important;
|
| 1291 |
+
}
|
| 1292 |
|
|
|
|
|
|
|
|
|
|
| 1293 |
}
|
| 1294 |
|
| 1295 |
+
|
| 1296 |
+
/* ============================================================
|
| 1297 |
+
EXTRA SMALL PHONES
|
| 1298 |
+
============================================================ */
|
| 1299 |
+
|
| 1300 |
+
@media (
|
| 1301 |
+
max-width: 480px
|
| 1302 |
+
) {
|
| 1303 |
+
|
| 1304 |
+
#header-box h1 {
|
| 1305 |
+
|
| 1306 |
+
font-size:
|
| 1307 |
+
19px !important;
|
| 1308 |
+
}
|
| 1309 |
+
|
| 1310 |
+
|
| 1311 |
+
#header-box p {
|
| 1312 |
+
|
| 1313 |
+
font-size:
|
| 1314 |
+
11px !important;
|
| 1315 |
+
}
|
| 1316 |
+
|
| 1317 |
+
|
| 1318 |
+
.bar-row {
|
| 1319 |
+
|
| 1320 |
+
grid-template-columns:
|
| 1321 |
+
62px
|
| 1322 |
+
minmax(0, 1fr)
|
| 1323 |
+
48px !important;
|
| 1324 |
+
}
|
| 1325 |
+
|
| 1326 |
+
|
| 1327 |
+
.bar-label {
|
| 1328 |
+
|
| 1329 |
+
font-size:
|
| 1330 |
+
11px !important;
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
|
| 1334 |
+
.bar-value {
|
| 1335 |
+
|
| 1336 |
+
font-size:
|
| 1337 |
+
10px !important;
|
| 1338 |
+
}
|
| 1339 |
+
|
| 1340 |
+
|
| 1341 |
+
.prediction-label {
|
| 1342 |
+
|
| 1343 |
+
font-size:
|
| 1344 |
+
24px !important;
|
| 1345 |
+
}
|
| 1346 |
+
|
| 1347 |
}
|
| 1348 |
+
|
| 1349 |
"""
|
| 1350 |
|
| 1351 |
|
| 1352 |
+
# ============================================================
|
| 1353 |
# 6) GRADIO INTERFACE
|
| 1354 |
+
# ============================================================
|
| 1355 |
|
| 1356 |
with gr.Blocks(
|
|
|
|
| 1357 |
title="Hassaniya Sentiment Analysis",
|
| 1358 |
) as demo:
|
| 1359 |
|
| 1360 |
+
with gr.Column(
|
| 1361 |
+
elem_id="main-card"
|
| 1362 |
+
):
|
| 1363 |
|
| 1364 |
+
# ----------------------------------------------------
|
| 1365 |
+
# HEADER
|
| 1366 |
+
# ----------------------------------------------------
|
| 1367 |
+
|
| 1368 |
+
gr.HTML(
|
| 1369 |
+
"""
|
| 1370 |
+
<div id="header-box">
|
| 1371 |
+
|
| 1372 |
+
<h1>
|
| 1373 |
+
Hassaniya Sentiment Analysis
|
| 1374 |
+
</h1>
|
| 1375 |
+
|
| 1376 |
+
<p>
|
| 1377 |
+
تحليل المشاعر للنصوص الحسانية باستخدام MARBERT
|
| 1378 |
+
</p>
|
| 1379 |
+
|
| 1380 |
+
<p>
|
| 1381 |
+
Analyse des sentiments · Sentiment Analysis
|
| 1382 |
+
</p>
|
| 1383 |
+
|
| 1384 |
+
</div>
|
| 1385 |
+
"""
|
| 1386 |
+
)
|
| 1387 |
+
|
| 1388 |
+
# ----------------------------------------------------
|
| 1389 |
+
# LANGUAGE
|
| 1390 |
+
# ----------------------------------------------------
|
| 1391 |
|
| 1392 |
language = gr.Radio(
|
| 1393 |
choices=[
|
|
|
|
| 1400 |
elem_id="language-selector",
|
| 1401 |
)
|
| 1402 |
|
| 1403 |
+
# ----------------------------------------------------
|
| 1404 |
+
# INPUT + OUTPUT
|
| 1405 |
+
# ----------------------------------------------------
|
| 1406 |
+
|
| 1407 |
+
with gr.Row(
|
| 1408 |
+
equal_height=True,
|
| 1409 |
+
elem_id="main-row",
|
| 1410 |
+
):
|
| 1411 |
|
| 1412 |
# INPUT
|
| 1413 |
+
with gr.Column(
|
| 1414 |
+
scale=6,
|
| 1415 |
+
min_width=300,
|
| 1416 |
+
):
|
| 1417 |
|
| 1418 |
text_input = gr.Textbox(
|
| 1419 |
lines=10,
|
| 1420 |
placeholder="اكتب نصا بالحسانية هنا...",
|
| 1421 |
+
label=(
|
| 1422 |
+
"Texte Hassaniya / "
|
| 1423 |
+
"النص الحساني / "
|
| 1424 |
+
"Hassaniya Text"
|
| 1425 |
+
),
|
| 1426 |
value="أنا ماشي عجلان يحنين حد",
|
| 1427 |
elem_id="input-box",
|
| 1428 |
)
|
| 1429 |
|
| 1430 |
+
# Buttons
|
| 1431 |
+
with gr.Row(
|
| 1432 |
+
elem_id="action-row"
|
| 1433 |
+
):
|
| 1434 |
+
|
| 1435 |
btn = gr.Button(
|
| 1436 |
"🔍 Analyser / تحليل / Analyze",
|
| 1437 |
variant="primary",
|
|
|
|
| 1439 |
|
| 1440 |
clear_btn = gr.Button(
|
| 1441 |
"🗑️ Clear / Effacer / مسح",
|
| 1442 |
+
elem_id="clear-button",
|
| 1443 |
)
|
| 1444 |
|
| 1445 |
+
|
| 1446 |
# OUTPUT
|
| 1447 |
+
with gr.Column(
|
| 1448 |
+
scale=5,
|
| 1449 |
+
min_width=300,
|
| 1450 |
+
):
|
| 1451 |
|
| 1452 |
output = gr.HTML(
|
| 1453 |
value="""
|
| 1454 |
<div class="result-card">
|
| 1455 |
+
|
| 1456 |
<h3 class="result-placeholder">
|
| 1457 |
Result will appear here
|
| 1458 |
</h3>
|
| 1459 |
+
|
| 1460 |
</div>
|
| 1461 |
"""
|
| 1462 |
)
|
| 1463 |
|
| 1464 |
+
# ----------------------------------------------------
|
| 1465 |
+
# EXAMPLES
|
| 1466 |
+
# ----------------------------------------------------
|
| 1467 |
+
|
| 1468 |
+
# IMPORTANT:
|
| 1469 |
+
# Examples only modify the Hassaniya text.
|
| 1470 |
+
# The currently selected interface language is preserved.
|
| 1471 |
+
|
| 1472 |
gr.Examples(
|
| 1473 |
examples=[
|
| 1474 |
["ذ شغل زينة حته"],
|
| 1475 |
["أنا ماشي عجلان يحنين حد"],
|
| 1476 |
["الموقع عادي كاع ماه اكبر من كدو"],
|
| 1477 |
+
["اشغل ما عجبتني"],
|
| 1478 |
["شكرا بارك الله فيكم"],
|
| 1479 |
],
|
| 1480 |
+
inputs=[text_input],
|
| 1481 |
label="Examples / Exemples / أمثلة",
|
| 1482 |
)
|
| 1483 |
|
| 1484 |
+
# ----------------------------------------------------
|
| 1485 |
+
# EVENTS
|
| 1486 |
+
# ----------------------------------------------------
|
| 1487 |
+
|
| 1488 |
btn.click(
|
| 1489 |
fn=predict_sentiment,
|
| 1490 |
+
inputs=[
|
| 1491 |
+
text_input,
|
| 1492 |
+
language,
|
| 1493 |
+
],
|
| 1494 |
outputs=output,
|
| 1495 |
)
|
| 1496 |
|
| 1497 |
text_input.submit(
|
| 1498 |
fn=predict_sentiment,
|
| 1499 |
+
inputs=[
|
| 1500 |
+
text_input,
|
| 1501 |
+
language,
|
| 1502 |
+
],
|
| 1503 |
outputs=output,
|
| 1504 |
)
|
| 1505 |
|
| 1506 |
clear_btn.click(
|
| 1507 |
fn=clear_fields,
|
| 1508 |
inputs=None,
|
| 1509 |
+
outputs=[
|
| 1510 |
+
text_input,
|
| 1511 |
+
output,
|
| 1512 |
+
],
|
| 1513 |
)
|
| 1514 |
|
| 1515 |
|
| 1516 |
+
# ============================================================
|
| 1517 |
# 7) START APP
|
| 1518 |
+
# ============================================================
|
| 1519 |
|
| 1520 |
if __name__ == "__main__":
|
| 1521 |
+
|
| 1522 |
+
demo.launch(
|
| 1523 |
+
css=custom_css
|
| 1524 |
+
)
|