Spaces:
Sleeping
Sleeping
File size: 19,083 Bytes
6812eef 80fe507 6812eef 564b80e 80fe507 f8fab2a 80fe507 f8fab2a 8d5cec2 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 6812eef f8fab2a 6812eef 80fe507 c196fe9 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 109bbda f8fab2a 80fe507 f8fab2a 6669042 f8fab2a 80fe507 6812eef 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 80fe507 f8fab2a 109bbda f8fab2a 80fe507 6812eef 80fe507 6812eef f8fab2a 6812eef 80fe507 6812eef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 |
"""
Hebrew Intent Classification Demo - Debug Version
"""
import gradio as gr
import sys
import traceback
def test_model_loading():
"""Test if model can be loaded"""
try:
print("๐ Testing model loading...")
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_name = "humy65/hebrew-intent-classifier"
print(f"๐ก Attempting to load: {model_name}")
tokenizer = AutoTokenizer.from_pretrained(model_name)
print("โ
Tokenizer loaded")
model = AutoModelForSequenceClassification.from_pretrained(model_name)
print("โ
Model loaded")
print(f"๐ Labels: {model.config.id2label}")
return True, "Model loaded successfully!", model, tokenizer
except Exception as e:
error_msg = f"โ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
print(error_msg)
return False, error_msg, None, None
def classify_text(text):
"""Classification function with lazy loading"""
if not text or not text.strip():
return "โ ๏ธ Please enter Hebrew text", {}
try:
# Try to load model on demand
success, message, model, tokenizer = test_model_loading()
if not success:
return f"Model Loading Failed:\n{message}", {}
# Perform classification
import torch
inputs = tokenizer(text, return_tensors="pt",
padding=True, truncation=True, max_length=128)
with torch.no_grad():
outputs = model(**inputs)
logits = outputs.logits
probabilities = torch.softmax(logits, dim=-1)
# Get results
predicted_id = torch.argmax(logits, dim=-1).item()
predicted_label = model.config.id2label[predicted_id]
confidence = probabilities[0][predicted_id].item()
# Create confidence scores for all labels
all_scores = {}
for i, prob in enumerate(probabilities[0]):
intent_name = model.config.id2label[i]
all_scores[intent_name] = float(prob)
result = f"""
๐ฏ Predicted Intent: {predicted_label}
๐ฒ Confidence: {confidence:.1%}
๐ All Predictions:
"""
# Sort and display
sorted_scores = sorted(
all_scores.items(), key=lambda x: x[1], reverse=True)
for intent, score in sorted_scores:
bar = "โ" * max(1, int(score * 20))
result += f"\n{intent}: {score:.1%} {bar}"
return result, all_scores
except Exception as e:
error_msg = f"Classification Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
print(error_msg)
return error_msg, {}
def test_connection():
"""Test Hugging Face connection"""
try:
from huggingface_hub import HfApi
api = HfApi()
info = api.model_info("humy65/hebrew-intent-classifier")
return f"โ
Model repository accessible\nModel ID: {info.modelId}\nLast Modified: {info.lastModified}"
except Exception as e:
return f"โ Repository access failed: {str(e)}"
def get_training_data():
"""Display the training data used for the model"""
training_data = [
("ืฉืืืชื ืืช ืืกืืกืื ืฉืื", "ืฉืืืช ืกืืกืื"),
("ืืื ืื ื ืืืื ืืช ืืื ืื?", "ืืืืื ืื ืื"),
("ืื ืืืืืจ ืฉื ืืชืืื ืืช?", "ืฉืืื ืืืืืช"),
("ืืืชืจ ืื ืขืืื ืื", "ืชืืืื ืืื ืืช"),
("ืื ื ืื ืืฆืืื ืืืชืืืจ", "ืชืืืื ืืื ืืช"),
("ืืื ืื ื ืืฉื ื ืืช ืืชืืืช ืืืืืืื?", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืฉืืจื ืืช ืืชืืื ืืช ืฉืื", "ืฉืืื ืืืืืช"),
("ืืืฉืืื ืฉืื ื ื ืขื", "ืชืืืื ืืื ืืช"),
("ืื ื ืื ืืงืื ืืืืืื", "ืชืืืื ืืื ืืช"),
("ืืื ืื ื ืจืืื ืืช ืืืฉืืื ืืช ืฉืื?", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืฉืืืชื ืืช ืคืจืื ืืืชืืืจืืช", "ืฉืืืช ืกืืกืื"),
("ืืืืืชื ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืื ืืืืจ ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืื ืขืืืืช", "ืฉืืืช ืกืืกืื"),
("ืื ืืฆืืื ืืืืื ืก ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืฆืจืื ืืืคืก ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืขืื ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืฉืื ืื ื ืืื ื", "ืฉืืืช ืกืืกืื"),
("ืฉืืืชื ืื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืื ืื ื ืืฉืืืจ ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืจืืฆื ืืฉื ืืช ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืื ืืชืงืืืช", "ืฉืืืช ืกืืกืื"),
("ืืขืืืช ืืชืืืจืืช - ืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืฆืจืื ืขืืจื ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืื ืืืืข ืื ืืกืืกืื ืฉืื", "ืฉืืืช ืกืืกืื"),
("ืจืืฆื ืืืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืืื ืืคืกืืงืื ืืช ืืื ืื", "ืืืืื ืื ืื"),
("ืจืืฆื ืืืคืกืืง ืืช ืืชืฉืืื", "ืืืืื ืื ืื"),
("ืืื ืืืฆืืื ืืืื ืื", "ืืืืื ืื ืื"),
("ืืงืฉื ืืืืืื ืื ืื", "ืืืืื ืื ืื"),
("ืื ืจืืฆื ืืืชืจ ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืืื ืืืืืื ืืช ืืืฉืืื", "ืืืืื ืื ืื"),
("ืจืืฆื ืืกืืืจ ืืช ืืืฉืืื", "ืืืืื ืื ืื"),
("ืขืืจื ืืืืืื ืื ืื", "ืืืืื ืื ืื"),
("ืืืื ืืืืื ืืื ืื", "ืืืืื ืื ืื"),
("ืืขืื ืืื ืืืื", "ืืืืื ืื ืื"),
("ืืื ืืคืกืืงืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืจืืฆื ืืืคืกืืง ืืช ืืืจืฉืื", "ืืืืื ืื ืื"),
("ืืงืฉื ืืืคืกืงืช ืฉืืจืืช", "ืืืืื ืื ืื"),
("ืื ืืืื ืืฉืืจืืช", "ืฉืืื ืืืืืช"),
("ืืืื ืชืืื ืืืช ืืฉ ืืื", "ืฉืืื ืืืืืช"),
("ืืื ืขืืื ืืืืืื", "ืฉืืื ืืืืืช"),
("ืื ืืืืื ืืื ืืชืืื ืืืช", "ืฉืืื ืืืืืช"),
("ืืื ืื ื ืืฉื ื ืืช ืืคืจืืื ืฉืื", "ืฉืืื ืืืืืช"),
("ืืื ืืคืฉืจ ืืฉืืจื", "ืฉืืื ืืืืืช"),
("ืื ืืืคืฉืจืืืืช ืฉืืื", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืขืืื ืคืจืืื", "ืฉืืื ืืืืืช"),
("ืืื ืจืืืื ืืช ืืืืกืืืจืื", "ืฉืืื ืืืืืช"),
("ืืืคืืืงืฆืื ืงืืจืกืช", "ืชืืืื ืืื ืืช"),
("ืืฉ ืืื ืืืชืจ", "ืชืืืื ืืื ืืช"),
("ืืืฃ ืื ื ืืขื", "ืชืืืื ืืื ืืช"),
("ืฉืืืื ืืืขืจืืช", "ืชืืืื ืืื ืืช"),
("ืืืืขื ืื ืขืืื", "ืชืืืื ืืื ืืช"),
("ืืขืื ืืื ืืช", "ืชืืืื ืืื ืืช"),
("ืืืขืจืืช ืื ืืืืื", "ืชืืืื ืืื ืืช"),
("ืฉืืืืช ืืืืืจ", "ืชืืืื ืืื ืืช"),
("ืืืคืชืืจ ืื ืขืืื", "ืชืืืื ืืื ืืช"),
("ืืชืืื ืืช ืื ื ืืขื ืืช", "ืชืืืื ืืื ืืช"),
("ืืืืืืื ืื ืืชื ืื", "ืชืืืื ืืื ืืช"),
("ืืืืืืช ืืืชืจ", "ืชืืืื ืืื ืืช")
]
# Count examples per category
category_counts = {}
for _, label in training_data:
category_counts[label] = category_counts.get(label, 0) + 1
result = f"""
๐ **Training Data Summary**
Total Examples: {len(training_data)}
๐ **Examples per Category:**
"""
# Add category statistics
for category, count in sorted(category_counts.items()):
percentage = (count / len(training_data)) * 100
result += f"\nโข {category}: {count} examples ({percentage:.1f}%)"
result += f"""
๐ **Sample Training Examples:**
๐ **ืฉืืืช ืกืืกืื (Password Reset):**
โข ืฉืืืชื ืืช ืืกืืกืื ืฉืื
โข ืื ืืืืจ ืืช ืืกืืกืื
โข ืืกืืกืื ืื ืขืืืืช
โข ืฆืจืื ืืืคืก ืืช ืืกืืกืื
โข ืืื ืื ื ืืฉืืืจ ืืช ืืกืืกืื
โ **ืืืืื ืื ืื (Cancel Subscription):**
โข ืืื ืื ื ืืืื ืืช ืืื ืื?
โข ืจืืฆื ืืืคืกืืง ืืช ืืชืฉืืื
โข ืื ืจืืฆื ืืืชืจ ืืช ืืฉืืจืืช
โข ืืื ืืืืืื ืืช ืืืฉืืื
โข ืืงืฉื ืืืืืื ืื ืื
โ **ืฉืืื ืืืืืช (General Question):**
โข ืื ืืืืืจ ืฉื ืืชืืื ืืช?
โข ืืื ืขืืื ืืืืืื
โข ืืืื ืชืืื ืืืช ืืฉ ืืื
โข ืืื ืื ื ืืฉื ื ืืช ืืคืจืืื ืฉืื
โข ืื ืืืื ืืฉืืจืืช
๐ง **ืชืืืื ืืื ืืช (Technical Support):**
โข ืืืชืจ ืื ืขืืื ืื
โข ืืืคืืืงืฆืื ืงืืจืกืช
โข ืืฉ ืืื ืืืชืจ
โข ืืืฃ ืื ื ืืขื
โข ืฉืืืื ืืืขืจืืช
---
๐ก **Model was trained with data augmentation techniques:**
โข Synonym replacement
โข Paraphrasing
โข Context variation
โข Original 12 examples โ Enhanced to {len(training_data)} examples
"""
return result
def get_training_data():
"""Display the training data used for the model"""
training_data = [
("ืฉืืืชื ืืช ืืกืืกืื ืฉืื", "ืฉืืืช ืกืืกืื"),
("ืืื ืื ื ืืืื ืืช ืืื ืื?", "ืืืืื ืื ืื"),
("ืื ืืืืืจ ืฉื ืืชืืื ืืช?", "ืฉืืื ืืืืืช"),
("ืืืชืจ ืื ืขืืื ืื", "ืชืืืื ืืื ืืช"),
("ืื ื ืื ืืฆืืื ืืืชืืืจ", "ืชืืืื ืืื ืืช"),
("ืืื ืื ื ืืฉื ื ืืช ืืชืืืช ืืืืืืื?", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืฉืืจื ืืช ืืชืืื ืืช ืฉืื", "ืฉืืื ืืืืืช"),
("ืืืฉืืื ืฉืื ื ื ืขื", "ืชืืืื ืืื ืืช"),
("ืื ื ืื ืืงืื ืืืืืื", "ืชืืืื ืืื ืืช"),
("ืืื ืื ื ืจืืื ืืช ืืืฉืืื ืืช ืฉืื?", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืฉืืืชื ืืช ืคืจืื ืืืชืืืจืืช", "ืฉืืืช ืกืืกืื"),
("ืืืืืชื ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืื ืืืืจ ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืื ืขืืืืช", "ืฉืืืช ืกืืกืื"),
("ืื ืืฆืืื ืืืืื ืก ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืฆืจืื ืืืคืก ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืขืื ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืฉืื ืื ื ืืื ื", "ืฉืืืช ืกืืกืื"),
("ืฉืืืชื ืื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืื ืื ื ืืฉืืืจ ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืจืืฆื ืืฉื ืืช ืืช ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืืกืืกืื ืื ืืชืงืืืช", "ืฉืืืช ืกืืกืื"),
("ืืขืืืช ืืชืืืจืืช - ืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืฆืจืื ืขืืจื ืขื ืืกืืกืื", "ืฉืืืช ืกืืกืื"),
("ืื ืืืืข ืื ืืกืืกืื ืฉืื", "ืฉืืืช ืกืืกืื"),
("ืจืืฆื ืืืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืืื ืืคืกืืงืื ืืช ืืื ืื", "ืืืืื ืื ืื"),
("ืจืืฆื ืืืคืกืืง ืืช ืืชืฉืืื", "ืืืืื ืื ืื"),
("ืืื ืืืฆืืื ืืืื ืื", "ืืืืื ืื ืื"),
("ืืงืฉื ืืืืืื ืื ืื", "ืืืืื ืื ืื"),
("ืื ืจืืฆื ืืืชืจ ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืืื ืืืืืื ืืช ืืืฉืืื", "ืืืืื ืื ืื"),
("ืจืืฆื ืืกืืืจ ืืช ืืืฉืืื", "ืืืืื ืื ืื"),
("ืขืืจื ืืืืืื ืื ืื", "ืืืืื ืื ืื"),
("ืืืื ืืืืื ืืื ืื", "ืืืืื ืื ืื"),
("ืืขืื ืืื ืืืื", "ืืืืื ืื ืื"),
("ืืื ืืคืกืืงืื ืืช ืืฉืืจืืช", "ืืืืื ืื ืื"),
("ืจืืฆื ืืืคืกืืง ืืช ืืืจืฉืื", "ืืืืื ืื ืื"),
("ืืงืฉื ืืืคืกืงืช ืฉืืจืืช", "ืืืืื ืื ืื"),
("ืื ืืืื ืืฉืืจืืช", "ืฉืืื ืืืืืช"),
("ืืืื ืชืืื ืืืช ืืฉ ืืื", "ืฉืืื ืืืืืช"),
("ืืื ืขืืื ืืืืืื", "ืฉืืื ืืืืืช"),
("ืื ืืืืื ืืื ืืชืืื ืืืช", "ืฉืืื ืืืืืช"),
("ืืื ืื ื ืืฉื ื ืืช ืืคืจืืื ืฉืื", "ืฉืืื ืืืืืช"),
("ืืื ืืคืฉืจ ืืฉืืจื", "ืฉืืื ืืืืืช"),
("ืื ืืืคืฉืจืืืืช ืฉืืื", "ืฉืืื ืืืืืช"),
("ืื ื ืจืืฆื ืืขืืื ืคืจืืื", "ืฉืืื ืืืืืช"),
("ืืื ืจืืืื ืืช ืืืืกืืืจืื", "ืฉืืื ืืืืืช"),
("ืืืคืืืงืฆืื ืงืืจืกืช", "ืชืืืื ืืื ืืช"),
("ืืฉ ืืื ืืืชืจ", "ืชืืืื ืืื ืืช"),
("ืืืฃ ืื ื ืืขื", "ืชืืืื ืืื ืืช"),
("ืฉืืืื ืืืขืจืืช", "ืชืืืื ืืื ืืช"),
("ืืืืขื ืื ืขืืื", "ืชืืืื ืืื ืืช"),
("ืืขืื ืืื ืืช", "ืชืืืื ืืื ืืช"),
("ืืืขืจืืช ืื ืืืืื", "ืชืืืื ืืื ืืช"),
("ืฉืืืืช ืืืืืจ", "ืชืืืื ืืื ืืช"),
("ืืืคืชืืจ ืื ืขืืื", "ืชืืืื ืืื ืืช"),
("ืืชืืื ืืช ืื ื ืืขื ืืช", "ืชืืืื ืืื ืืช"),
("ืืืืืืื ืื ืืชื ืื", "ืชืืืื ืืื ืืช"),
("ืืืืืืช ืืืชืจ", "ืชืืืื ืืื ืืช")
]
# Count examples per category
category_counts = {}
for _, label in training_data:
category_counts[label] = category_counts.get(label, 0) + 1
result = f"""
๐ **Training Data Summary**
Total Examples: {len(training_data)}
๐ **Examples per Category:**
"""
# Add category statistics
for category, count in sorted(category_counts.items()):
percentage = (count / len(training_data)) * 100
result += f"\nโข {category}: {count} examples ({percentage:.1f}%)"
result += f"""
๐ **Sample Training Examples:**
๐ **ืฉืืืช ืกืืกืื (Password Reset):**
โข ืฉืืืชื ืืช ืืกืืกืื ืฉืื
โข ืื ืืืืจ ืืช ืืกืืกืื
โข ืืกืืกืื ืื ืขืืืืช
โข ืฆืจืื ืืืคืก ืืช ืืกืืกืื
โข ืืื ืื ื ืืฉืืืจ ืืช ืืกืืกืื
โ **ืืืืื ืื ืื (Cancel Subscription):**
โข ืืื ืื ื ืืืื ืืช ืืื ืื?
โข ืจืืฆื ืืืคืกืืง ืืช ืืชืฉืืื
โข ืื ืจืืฆื ืืืชืจ ืืช ืืฉืืจืืช
โข ืืื ืืืืืื ืืช ืืืฉืืื
โข ืืงืฉื ืืืืืื ืื ืื
โ **ืฉืืื ืืืืืช (General Question):**
โข ืื ืืืืืจ ืฉื ืืชืืื ืืช?
โข ืืื ืขืืื ืืืืืื
โข ืืืื ืชืืื ืืืช ืืฉ ืืื
โข ืืื ืื ื ืืฉื ื ืืช ืืคืจืืื ืฉืื
โข ืื ืืืื ืืฉืืจืืช
๐ง **ืชืืืื ืืื ืืช (Technical Support):**
โข ืืืชืจ ืื ืขืืื ืื
โข ืืืคืืืงืฆืื ืงืืจืกืช
โข ืืฉ ืืื ืืืชืจ
โข ืืืฃ ืื ื ืืขื
โข ืฉืืืื ืืืขืจืืช
---
๐ก **Model was trained with data augmentation techniques:**
โข Synonym replacement
โข Paraphrasing
โข Context variation
โข Original 12 examples โ Enhanced to {len(training_data)} examples
"""
return result
# Create interface
with gr.Blocks(title="Hebrew Intent Classification - Debug") as demo:
gr.Markdown("# ๐ฎ๐ฑ Hebrew Intent Classification - Debug Version 2.1 ๐")
gr.Markdown("### ๐ข Version 2.1 - Training Data Display Added (Aug 12, 2025) โ
")
with gr.Tab("Classification"):
with gr.Row():
with gr.Column():
text_input = gr.Textbox(
label="Hebrew Text:",
placeholder="ืฉืืืชื ืืช ืืกืืกืื ืฉืื",
lines=3
)
classify_btn = gr.Button("Classify", variant="primary")
# Quick examples
gr.Markdown("### Examples:")
examples = [
"ืฉืืืชื ืืช ืืกืืกืื ืฉืื",
"ืจืืฆื ืืืื ืืช ืืื ืื",
"ืืื ืขืืื ืืืืืื",
"ืืืชืจ ืื ืขืืื"
]
for example in examples:
gr.Button(example, size="sm").click(
lambda x=example: x, outputs=text_input
)
with gr.Column():
result_output = gr.Textbox(
label="Result:",
lines=12,
interactive=False
)
confidence_output = gr.Label(
label="Confidence Scores",
num_top_classes=4
)
with gr.Tab("Debug"):
gr.Markdown("### Debug Information")
with gr.Row():
with gr.Column():
test_btn = gr.Button("Test Model Loading")
debug_output = gr.Textbox(
label="Debug Output:",
lines=15,
interactive=False
)
test_btn.click(
lambda: test_model_loading()[1],
outputs=debug_output
)
conn_btn = gr.Button("Test Repository Connection")
conn_output = gr.Textbox(
label="Connection Test:",
lines=5,
interactive=False
)
conn_btn.click(
test_connection,
outputs=conn_output
)
with gr.Column():
data_btn = gr.Button("Show Training Data")
training_output = gr.Textbox(
label="Training Data:",
lines=20,
interactive=False
)
data_btn.click(
get_training_data,
outputs=training_output
)
# Connect classification
classify_btn.click(
classify_text,
inputs=[text_input],
outputs=[result_output, confidence_output]
)
text_input.submit(
classify_text,
inputs=[text_input],
outputs=[result_output, confidence_output]
)
if __name__ == "__main__":
demo.launch(
share=True,
server_name="0.0.0.0",
server_port=7860
)
# Connect classification
classify_btn.click(
classify_text,
inputs=[text_input],
outputs=[result_output, confidence_output]
)
text_input.submit(
classify_text,
inputs=[text_input],
outputs=[result_output, confidence_output]
)
if __name__ == "__main__":
demo.launch(
share=True,
server_name="0.0.0.0",
server_port=7860
)
|