Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,803 +1,971 @@
|
|
| 1 |
-
import os
|
| 2 |
-
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
| 3 |
-
import glob
|
| 4 |
-
import json
|
| 5 |
-
import sqlite3
|
| 6 |
-
from datetime import datetime, timedelta
|
| 7 |
-
from typing import Dict, List, Optional, Tuple
|
| 8 |
-
from dataclasses import dataclass, asdict
|
| 9 |
-
from collections import defaultdict
|
| 10 |
-
import re
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
from
|
| 18 |
-
from
|
| 19 |
-
from
|
| 20 |
-
from
|
| 21 |
-
from
|
| 22 |
-
from
|
| 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 |
-
cursor.
|
| 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 |
-
conn.
|
| 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 |
-
conn.
|
| 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 |
-
self.
|
| 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 |
-
return
|
| 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 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
if
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
return
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
"
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
"
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
return {
|
| 663 |
-
"success":
|
| 664 |
-
"
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
|
| 685 |
-
|
| 686 |
-
|
| 687 |
-
|
| 688 |
-
|
| 689 |
-
)
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
)
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
| 790 |
-
|
| 791 |
-
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
-
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 803 |
demo.launch()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"
|
| 3 |
+
import glob
|
| 4 |
+
import json
|
| 5 |
+
import sqlite3
|
| 6 |
+
from datetime import datetime, timedelta
|
| 7 |
+
from typing import Dict, List, Optional, Tuple
|
| 8 |
+
from dataclasses import dataclass, asdict
|
| 9 |
+
from collections import defaultdict
|
| 10 |
+
import re
|
| 11 |
+
import uuid
|
| 12 |
+
import hashlib
|
| 13 |
+
|
| 14 |
+
from dotenv import load_dotenv
|
| 15 |
+
import gradio as gr
|
| 16 |
+
|
| 17 |
+
from langchain_community.document_loaders import DirectoryLoader, TextLoader
|
| 18 |
+
from langchain.text_splitter import CharacterTextSplitter
|
| 19 |
+
from langchain.schema import Document
|
| 20 |
+
from langchain_chroma import Chroma
|
| 21 |
+
from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
|
| 22 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 23 |
+
from langchain.memory import ConversationBufferMemory
|
| 24 |
+
from langchain.chains import ConversationalRetrievalChain
|
| 25 |
+
import numpy as np
|
| 26 |
+
|
| 27 |
+
@dataclass
|
| 28 |
+
class LearningSession:
|
| 29 |
+
session_id: str
|
| 30 |
+
user_id: str
|
| 31 |
+
start_time: datetime
|
| 32 |
+
end_time: Optional[datetime] = None
|
| 33 |
+
words_learned: int = 0
|
| 34 |
+
idioms_learned: int = 0
|
| 35 |
+
questions_asked: int = 0
|
| 36 |
+
|
| 37 |
+
@dataclass
|
| 38 |
+
class WordProgress:
|
| 39 |
+
word: str
|
| 40 |
+
definition: str
|
| 41 |
+
category: str
|
| 42 |
+
first_encountered: datetime
|
| 43 |
+
last_reviewed: datetime
|
| 44 |
+
encounter_count: int
|
| 45 |
+
mastery_level: int
|
| 46 |
+
correct_answers: int
|
| 47 |
+
total_questions: int
|
| 48 |
+
|
| 49 |
+
class PersonalizedLearningTracker:
|
| 50 |
+
def __init__(self, db_path: str = "learning_progress.db"):
|
| 51 |
+
self.db_path = db_path
|
| 52 |
+
self.init_database()
|
| 53 |
+
|
| 54 |
+
def init_database(self):
|
| 55 |
+
"""Initialize SQLite database for tracking learning progress"""
|
| 56 |
+
conn = sqlite3.connect(self.db_path)
|
| 57 |
+
cursor = conn.cursor()
|
| 58 |
+
|
| 59 |
+
cursor.execute('''
|
| 60 |
+
CREATE TABLE IF NOT EXISTS learning_sessions (
|
| 61 |
+
session_id TEXT PRIMARY KEY,
|
| 62 |
+
user_id TEXT NOT NULL,
|
| 63 |
+
start_time TEXT NOT NULL,
|
| 64 |
+
end_time TEXT,
|
| 65 |
+
words_learned INTEGER DEFAULT 0,
|
| 66 |
+
idioms_learned INTEGER DEFAULT 0,
|
| 67 |
+
questions_asked INTEGER DEFAULT 0
|
| 68 |
+
)
|
| 69 |
+
''')
|
| 70 |
+
|
| 71 |
+
cursor.execute('''
|
| 72 |
+
CREATE TABLE IF NOT EXISTS word_progress (
|
| 73 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 74 |
+
user_id TEXT NOT NULL,
|
| 75 |
+
word TEXT NOT NULL,
|
| 76 |
+
definition TEXT NOT NULL,
|
| 77 |
+
category TEXT NOT NULL,
|
| 78 |
+
first_encountered TEXT NOT NULL,
|
| 79 |
+
last_reviewed TEXT NOT NULL,
|
| 80 |
+
encounter_count INTEGER DEFAULT 1,
|
| 81 |
+
mastery_level INTEGER DEFAULT 0,
|
| 82 |
+
correct_answers INTEGER DEFAULT 0,
|
| 83 |
+
total_questions INTEGER DEFAULT 0,
|
| 84 |
+
UNIQUE(user_id, word, category)
|
| 85 |
+
)
|
| 86 |
+
''')
|
| 87 |
+
|
| 88 |
+
cursor.execute('''
|
| 89 |
+
CREATE TABLE IF NOT EXISTS learning_analytics (
|
| 90 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 91 |
+
user_id TEXT NOT NULL,
|
| 92 |
+
date TEXT NOT NULL,
|
| 93 |
+
metric_name TEXT NOT NULL,
|
| 94 |
+
metric_value REAL NOT NULL
|
| 95 |
+
)
|
| 96 |
+
''')
|
| 97 |
+
|
| 98 |
+
cursor.execute('''
|
| 99 |
+
CREATE TABLE IF NOT EXISTS user_sessions (
|
| 100 |
+
user_id TEXT NOT NULL,
|
| 101 |
+
session_token TEXT NOT NULL,
|
| 102 |
+
created_at TEXT NOT NULL,
|
| 103 |
+
last_activity TEXT NOT NULL,
|
| 104 |
+
is_active BOOLEAN DEFAULT 1,
|
| 105 |
+
PRIMARY KEY (user_id, session_token)
|
| 106 |
+
)
|
| 107 |
+
''')
|
| 108 |
+
|
| 109 |
+
conn.commit()
|
| 110 |
+
conn.close()
|
| 111 |
+
|
| 112 |
+
def create_user_session(self, user_id: str) -> str:
|
| 113 |
+
"""Create a new session token for a user"""
|
| 114 |
+
session_token = str(uuid.uuid4())
|
| 115 |
+
now = datetime.now().isoformat()
|
| 116 |
+
|
| 117 |
+
conn = sqlite3.connect(self.db_path)
|
| 118 |
+
cursor = conn.cursor()
|
| 119 |
+
|
| 120 |
+
cursor.execute('''
|
| 121 |
+
UPDATE user_sessions
|
| 122 |
+
SET is_active = 0
|
| 123 |
+
WHERE user_id = ?
|
| 124 |
+
''', (user_id,))
|
| 125 |
+
|
| 126 |
+
cursor.execute('''
|
| 127 |
+
INSERT INTO user_sessions (user_id, session_token, created_at, last_activity)
|
| 128 |
+
VALUES (?, ?, ?, ?)
|
| 129 |
+
''', (user_id, session_token, now, now))
|
| 130 |
+
|
| 131 |
+
conn.commit()
|
| 132 |
+
conn.close()
|
| 133 |
+
|
| 134 |
+
return session_token
|
| 135 |
+
|
| 136 |
+
def validate_session(self, user_id: str, session_token: str) -> bool:
|
| 137 |
+
"""Validate if a session is active and belongs to the user"""
|
| 138 |
+
conn = sqlite3.connect(self.db_path)
|
| 139 |
+
cursor = conn.cursor()
|
| 140 |
+
|
| 141 |
+
cursor.execute('''
|
| 142 |
+
SELECT is_active FROM user_sessions
|
| 143 |
+
WHERE user_id = ? AND session_token = ?
|
| 144 |
+
''', (user_id, session_token))
|
| 145 |
+
|
| 146 |
+
result = cursor.fetchone()
|
| 147 |
+
conn.close()
|
| 148 |
+
|
| 149 |
+
return result is not None and result[0] == 1
|
| 150 |
+
|
| 151 |
+
def update_session_activity(self, user_id: str, session_token: str):
|
| 152 |
+
"""Update last activity time for a session"""
|
| 153 |
+
conn = sqlite3.connect(self.db_path)
|
| 154 |
+
cursor = conn.cursor()
|
| 155 |
+
|
| 156 |
+
cursor.execute('''
|
| 157 |
+
UPDATE user_sessions
|
| 158 |
+
SET last_activity = ?
|
| 159 |
+
WHERE user_id = ? AND session_token = ?
|
| 160 |
+
''', (datetime.now().isoformat(), user_id, session_token))
|
| 161 |
+
|
| 162 |
+
conn.commit()
|
| 163 |
+
conn.close()
|
| 164 |
+
|
| 165 |
+
def start_session(self, user_id: str) -> str:
|
| 166 |
+
"""Start a new learning session"""
|
| 167 |
+
session_id = f"{user_id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
| 168 |
+
session = LearningSession(
|
| 169 |
+
session_id=session_id,
|
| 170 |
+
user_id=user_id,
|
| 171 |
+
start_time=datetime.now()
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
conn = sqlite3.connect(self.db_path)
|
| 175 |
+
cursor = conn.cursor()
|
| 176 |
+
cursor.execute('''
|
| 177 |
+
INSERT INTO learning_sessions (session_id, user_id, start_time)
|
| 178 |
+
VALUES (?, ?, ?)
|
| 179 |
+
''', (session.session_id, session.user_id, session.start_time.isoformat()))
|
| 180 |
+
conn.commit()
|
| 181 |
+
conn.close()
|
| 182 |
+
|
| 183 |
+
return session_id
|
| 184 |
+
|
| 185 |
+
def end_session(self, session_id: str):
|
| 186 |
+
"""End a learning session"""
|
| 187 |
+
conn = sqlite3.connect(self.db_path)
|
| 188 |
+
cursor = conn.cursor()
|
| 189 |
+
cursor.execute('''
|
| 190 |
+
UPDATE learning_sessions
|
| 191 |
+
SET end_time = ?
|
| 192 |
+
WHERE session_id = ?
|
| 193 |
+
''', (datetime.now().isoformat(), session_id))
|
| 194 |
+
conn.commit()
|
| 195 |
+
conn.close()
|
| 196 |
+
|
| 197 |
+
def track_word_encounter(self, user_id: str, word: str, definition: str, category: str):
|
| 198 |
+
"""Track when a user encounters a word or idiom"""
|
| 199 |
+
conn = sqlite3.connect(self.db_path)
|
| 200 |
+
cursor = conn.cursor()
|
| 201 |
+
|
| 202 |
+
cursor.execute('''
|
| 203 |
+
SELECT * FROM word_progress
|
| 204 |
+
WHERE user_id = ? AND word = ? AND category = ?
|
| 205 |
+
''', (user_id, word, category))
|
| 206 |
+
|
| 207 |
+
existing = cursor.fetchone()
|
| 208 |
+
now = datetime.now().isoformat()
|
| 209 |
+
|
| 210 |
+
if existing:
|
| 211 |
+
cursor.execute('''
|
| 212 |
+
UPDATE word_progress
|
| 213 |
+
SET last_reviewed = ?, encounter_count = encounter_count + 1
|
| 214 |
+
WHERE user_id = ? AND word = ? AND category = ?
|
| 215 |
+
''', (now, user_id, word, category))
|
| 216 |
+
else:
|
| 217 |
+
cursor.execute('''
|
| 218 |
+
INSERT INTO word_progress
|
| 219 |
+
(user_id, word, definition, category, first_encountered, last_reviewed)
|
| 220 |
+
VALUES (?, ?, ?, ?, ?, ?)
|
| 221 |
+
''', (user_id, word, definition, category, now, now))
|
| 222 |
+
|
| 223 |
+
conn.commit()
|
| 224 |
+
conn.close()
|
| 225 |
+
|
| 226 |
+
def update_mastery_level(self, user_id: str, word: str, category: str, correct: bool):
|
| 227 |
+
"""Update mastery level based on user performance"""
|
| 228 |
+
conn = sqlite3.connect(self.db_path)
|
| 229 |
+
cursor = conn.cursor()
|
| 230 |
+
|
| 231 |
+
cursor.execute('''
|
| 232 |
+
SELECT mastery_level, correct_answers, total_questions
|
| 233 |
+
FROM word_progress
|
| 234 |
+
WHERE user_id = ? AND word = ? AND category = ?
|
| 235 |
+
''', (user_id, word, category))
|
| 236 |
+
|
| 237 |
+
result = cursor.fetchone()
|
| 238 |
+
if result:
|
| 239 |
+
current_mastery, correct_answers, total_questions = result
|
| 240 |
+
new_correct = correct_answers + (1 if correct else 0)
|
| 241 |
+
new_total = total_questions + 1
|
| 242 |
+
|
| 243 |
+
accuracy = new_correct / new_total if new_total > 0 else 0
|
| 244 |
+
new_mastery = min(5, int(accuracy * 5) + (1 if new_total >= 3 else 0))
|
| 245 |
+
|
| 246 |
+
cursor.execute('''
|
| 247 |
+
UPDATE word_progress
|
| 248 |
+
SET mastery_level = ?, correct_answers = ?, total_questions = ?
|
| 249 |
+
WHERE user_id = ? AND word = ? AND category = ?
|
| 250 |
+
''', (new_mastery, new_correct, new_total, user_id, word, category))
|
| 251 |
+
|
| 252 |
+
conn.commit()
|
| 253 |
+
conn.close()
|
| 254 |
+
|
| 255 |
+
def get_user_progress(self, user_id: str) -> Dict:
|
| 256 |
+
"""Get comprehensive user progress statistics"""
|
| 257 |
+
conn = sqlite3.connect(self.db_path)
|
| 258 |
+
cursor = conn.cursor()
|
| 259 |
+
|
| 260 |
+
cursor.execute('''
|
| 261 |
+
SELECT category, COUNT(*), AVG(mastery_level)
|
| 262 |
+
FROM word_progress
|
| 263 |
+
WHERE user_id = ?
|
| 264 |
+
GROUP BY category
|
| 265 |
+
''', (user_id,))
|
| 266 |
+
|
| 267 |
+
category_stats = {}
|
| 268 |
+
for category, count, avg_mastery in cursor.fetchall():
|
| 269 |
+
category_stats[category] = {
|
| 270 |
+
'count': count,
|
| 271 |
+
'average_mastery': round(avg_mastery or 0, 2)
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
week_ago = (datetime.now() - timedelta(days=7)).isoformat()
|
| 275 |
+
cursor.execute('''
|
| 276 |
+
SELECT COUNT(*) FROM word_progress
|
| 277 |
+
WHERE user_id = ? AND last_reviewed >= ?
|
| 278 |
+
''', (user_id, week_ago))
|
| 279 |
+
recent_activity = cursor.fetchone()[0]
|
| 280 |
+
|
| 281 |
+
cursor.execute('''
|
| 282 |
+
SELECT DATE(last_reviewed) as date, COUNT(*) as daily_count
|
| 283 |
+
FROM word_progress
|
| 284 |
+
WHERE user_id = ?
|
| 285 |
+
GROUP BY DATE(last_reviewed)
|
| 286 |
+
ORDER BY date DESC
|
| 287 |
+
LIMIT 30
|
| 288 |
+
''', (user_id,))
|
| 289 |
+
|
| 290 |
+
daily_activity = cursor.fetchall()
|
| 291 |
+
|
| 292 |
+
conn.close()
|
| 293 |
+
|
| 294 |
+
return {
|
| 295 |
+
'category_stats': category_stats,
|
| 296 |
+
'recent_activity': recent_activity,
|
| 297 |
+
'daily_activity': daily_activity,
|
| 298 |
+
'total_words': sum(stats['count'] for stats in category_stats.values())
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
def get_words_to_review(self, user_id: str, limit: int = 10) -> List[Dict]:
|
| 302 |
+
"""Get words that need review based on spaced repetition"""
|
| 303 |
+
conn = sqlite3.connect(self.db_path)
|
| 304 |
+
cursor = conn.cursor()
|
| 305 |
+
|
| 306 |
+
cursor.execute('''
|
| 307 |
+
SELECT word, definition, category, mastery_level, last_reviewed
|
| 308 |
+
FROM word_progress
|
| 309 |
+
WHERE user_id = ? AND (
|
| 310 |
+
mastery_level < 3 OR
|
| 311 |
+
last_reviewed < datetime('now', '-2 days')
|
| 312 |
+
)
|
| 313 |
+
ORDER BY mastery_level ASC, last_reviewed ASC
|
| 314 |
+
LIMIT ?
|
| 315 |
+
''', (user_id, limit))
|
| 316 |
+
|
| 317 |
+
words = []
|
| 318 |
+
for word, definition, category, mastery, last_reviewed in cursor.fetchall():
|
| 319 |
+
words.append({
|
| 320 |
+
'word': word,
|
| 321 |
+
'definition': definition,
|
| 322 |
+
'category': category,
|
| 323 |
+
'mastery_level': mastery,
|
| 324 |
+
'last_reviewed': last_reviewed
|
| 325 |
+
})
|
| 326 |
+
|
| 327 |
+
conn.close()
|
| 328 |
+
return words
|
| 329 |
+
|
| 330 |
+
def get_learning_recommendations(self, user_id: str) -> List[str]:
|
| 331 |
+
"""Get personalized learning recommendations"""
|
| 332 |
+
progress = self.get_user_progress(user_id)
|
| 333 |
+
recommendations = []
|
| 334 |
+
|
| 335 |
+
if progress['total_words'] < 10:
|
| 336 |
+
recommendations.append("Start with basic vocabulary - try asking about common Kazakh words!")
|
| 337 |
+
|
| 338 |
+
if 'idiom' not in progress['category_stats'] or progress['category_stats'].get('idiom', {}).get('count', 0) < 5:
|
| 339 |
+
recommendations.append("Explore Kazakh idioms to improve your cultural understanding!")
|
| 340 |
+
|
| 341 |
+
words_to_review = self.get_words_to_review(user_id, 5)
|
| 342 |
+
if words_to_review:
|
| 343 |
+
recommendations.append(f"Review these words: {', '.join([w['word'] for w in words_to_review[:3]])}")
|
| 344 |
+
|
| 345 |
+
if progress['recent_activity'] == 0:
|
| 346 |
+
recommendations.append("You haven't practiced recently - consistency is key to language learning!")
|
| 347 |
+
|
| 348 |
+
return recommendations
|
| 349 |
+
|
| 350 |
+
class PersonalizedKazakhAssistant:
|
| 351 |
+
def __init__(self):
|
| 352 |
+
self.setup_environment()
|
| 353 |
+
self.setup_vectorstore()
|
| 354 |
+
self.setup_llm()
|
| 355 |
+
self.tracker = PersonalizedLearningTracker()
|
| 356 |
+
self.user_sessions = {}
|
| 357 |
+
self.user_memories = {}
|
| 358 |
+
|
| 359 |
+
def setup_environment(self):
|
| 360 |
+
"""Setup environment and configuration"""
|
| 361 |
+
|
| 362 |
+
self.google_api_key = os.getenv("GOOGLE_API_KEY")
|
| 363 |
+
self.MODEL = "gemini-1.5-flash"
|
| 364 |
+
self.db_name = "vector_db"
|
| 365 |
+
|
| 366 |
+
def setup_vectorstore(self):
|
| 367 |
+
"""Setup document loading and vector store"""
|
| 368 |
+
folders = glob.glob("knowledge-base/*")
|
| 369 |
+
text_loader_kwargs = {'encoding': 'utf-8'}
|
| 370 |
+
documents = []
|
| 371 |
+
|
| 372 |
+
for folder in folders:
|
| 373 |
+
doc_type = os.path.basename(folder)
|
| 374 |
+
loader = DirectoryLoader(
|
| 375 |
+
folder,
|
| 376 |
+
glob="**/*.txt",
|
| 377 |
+
loader_cls=TextLoader,
|
| 378 |
+
loader_kwargs=text_loader_kwargs
|
| 379 |
+
)
|
| 380 |
+
folder_docs = loader.load()
|
| 381 |
+
for doc in folder_docs:
|
| 382 |
+
doc.metadata["doc_type"] = doc_type
|
| 383 |
+
documents.append(doc)
|
| 384 |
+
|
| 385 |
+
text_splitter = CharacterTextSplitter(separator=r'\n', chunk_size=2000, chunk_overlap=0)
|
| 386 |
+
chunks = text_splitter.split_documents(documents)
|
| 387 |
+
|
| 388 |
+
print(f"Total chunks: {len(chunks)}")
|
| 389 |
+
|
| 390 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/distiluse-base-multilingual-cased-v1")
|
| 391 |
+
|
| 392 |
+
if os.path.exists(self.db_name):
|
| 393 |
+
Chroma(persist_directory=self.db_name, embedding_function=embeddings).delete_collection()
|
| 394 |
+
|
| 395 |
+
self.vectorstore = Chroma.from_documents(documents=chunks, embedding=embeddings, persist_directory=self.db_name)
|
| 396 |
+
print(f"Vectorstore created with {self.vectorstore._collection.count()} documents")
|
| 397 |
+
|
| 398 |
+
def setup_llm(self):
|
| 399 |
+
"""Setup LLM with enhanced system prompt"""
|
| 400 |
+
system_prompt = """
|
| 401 |
+
You are a personalized Kazakh language learning assistant with access to a comprehensive knowledge base and user learning history. Your role is to help users learn Kazakh words and idioms while tracking their progress and providing personalized recommendations.
|
| 402 |
+
|
| 403 |
+
Key capabilities:
|
| 404 |
+
1. **Answer Queries**: Provide accurate definitions and examples for Kazakh words and idioms from your knowledge base
|
| 405 |
+
2. **Track Learning Progress**: Identify and track when users learn new words or idioms
|
| 406 |
+
3. **Personalized Responses**: Adapt responses based on user's learning history and progress
|
| 407 |
+
4. **Progress Reporting**: Provide detailed progress reports when asked
|
| 408 |
+
5. **Learning Recommendations**: Suggest words/idioms to review or learn next
|
| 409 |
+
|
| 410 |
+
Response Guidelines:
|
| 411 |
+
- For word/idiom queries: Provide definition, usage examples, and related information
|
| 412 |
+
- Always identify the main Kazakh word/idiom being discussed for progress tracking
|
| 413 |
+
- Be encouraging and supportive of the user's learning journey
|
| 414 |
+
- Use simple, clear explanations appropriate for language learners
|
| 415 |
+
- When discussing progress, be specific and motivating
|
| 416 |
+
|
| 417 |
+
Format responses naturally in conversational style, not JSON unless specifically requested.
|
| 418 |
+
"""
|
| 419 |
+
|
| 420 |
+
self.llm = ChatGoogleGenerativeAI(
|
| 421 |
+
model="models/gemini-1.5-flash",
|
| 422 |
+
temperature=0.7,
|
| 423 |
+
system_instruction=system_prompt
|
| 424 |
+
)
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def get_user_memory(self, user_id: str):
|
| 428 |
+
"""Get or create conversation memory for a specific user"""
|
| 429 |
+
if user_id not in self.user_memories:
|
| 430 |
+
self.user_memories[user_id] = ConversationBufferMemory(
|
| 431 |
+
memory_key='chat_history',
|
| 432 |
+
return_messages=True,
|
| 433 |
+
max_token_limit=10000
|
| 434 |
+
)
|
| 435 |
+
return self.user_memories[user_id]
|
| 436 |
+
|
| 437 |
+
def get_user_chain(self, user_id: str):
|
| 438 |
+
"""Get or create conversation chain for a specific user"""
|
| 439 |
+
memory = self.get_user_memory(user_id)
|
| 440 |
+
retriever = self.vectorstore.as_retriever()
|
| 441 |
+
return ConversationalRetrievalChain.from_llm(
|
| 442 |
+
llm=self.llm,
|
| 443 |
+
retriever=retriever,
|
| 444 |
+
memory=memory
|
| 445 |
+
)
|
| 446 |
+
|
| 447 |
+
def extract_kazakh_terms(self, message: str, response: str) -> List[Tuple[str, str, str]]:
|
| 448 |
+
"""Extract meaningful Kazakh terms using document metadata to determine category"""
|
| 449 |
+
terms = []
|
| 450 |
+
|
| 451 |
+
try:
|
| 452 |
+
retrieved_docs = self.vectorstore.similarity_search(message, k=5)
|
| 453 |
+
|
| 454 |
+
kazakh_words = re.findall(r'[А-Яа-яӘәҒғҚқҢңӨөҰұҮүҺһІі]+(?:\s+[А-Яа-яӘәҒғҚқҢңӨөҰұҮүҺһІі]+)*', response)
|
| 455 |
+
|
| 456 |
+
for word in kazakh_words:
|
| 457 |
+
word = word.strip()
|
| 458 |
+
|
| 459 |
+
if len(word) <= 2 or len(word) > 50:
|
| 460 |
+
continue
|
| 461 |
+
|
| 462 |
+
skip_words = ['деген', 'деп', 'берілген', 'мәтінде', 'мағынасы', 'дегеннің',
|
| 463 |
+
'түсіндірілген', 'келтірілген', 'болып', 'табылады', 'ауруы',
|
| 464 |
+
'мынадай', 'тақырыбына', 'тіркестер', 'арналған', 'байланысты']
|
| 465 |
+
|
| 466 |
+
if any(skip in word.lower() for skip in skip_words):
|
| 467 |
+
continue
|
| 468 |
+
|
| 469 |
+
category = "word"
|
| 470 |
+
definition = ""
|
| 471 |
+
|
| 472 |
+
for doc in retrieved_docs:
|
| 473 |
+
if word.lower() in doc.page_content.lower():
|
| 474 |
+
doc_type = doc.metadata.get('doc_type', '').lower()
|
| 475 |
+
if 'idiom' in doc_type or 'тіркес' in doc_type:
|
| 476 |
+
category = "idiom"
|
| 477 |
+
else:
|
| 478 |
+
category = "word"
|
| 479 |
+
|
| 480 |
+
definition = self.extract_clean_definition(word, doc.page_content, response)
|
| 481 |
+
break
|
| 482 |
+
|
| 483 |
+
if definition and len(word.split()) <= 4:
|
| 484 |
+
if not any(phrase in word.lower() for phrase in ['қалай', 'қандай', 'қайда', 'неше', 'қашан']):
|
| 485 |
+
terms.append((word, category, definition))
|
| 486 |
+
|
| 487 |
+
except Exception as e:
|
| 488 |
+
print(f"Error extracting terms: {e}")
|
| 489 |
+
|
| 490 |
+
return terms
|
| 491 |
+
|
| 492 |
+
def extract_clean_definition(self, term: str, doc_content: str, response: str) -> str:
|
| 493 |
+
"""Extract clean definition for a term"""
|
| 494 |
+
sentences = response.split('.')
|
| 495 |
+
for sentence in sentences:
|
| 496 |
+
if term.lower() in sentence.lower():
|
| 497 |
+
clean_sentence = sentence.strip()
|
| 498 |
+
if len(clean_sentence) > 10 and len(clean_sentence) < 150:
|
| 499 |
+
if not any(word in clean_sentence.lower() for word in ['деген не', 'қалай аталады', 'нені білдіреді']):
|
| 500 |
+
return clean_sentence
|
| 501 |
+
|
| 502 |
+
doc_sentences = doc_content.split('.')
|
| 503 |
+
for sentence in doc_sentences:
|
| 504 |
+
if term.lower() in sentence.lower():
|
| 505 |
+
clean_sentence = sentence.strip()
|
| 506 |
+
if len(clean_sentence) > 10 and len(clean_sentence) < 150:
|
| 507 |
+
return clean_sentence
|
| 508 |
+
|
| 509 |
+
return f"Definition for {term}"
|
| 510 |
+
|
| 511 |
+
def process_message(self, message: str, user_id: str = "default_user", session_token: str = None) -> str:
|
| 512 |
+
"""Process user message with proper user session management"""
|
| 513 |
+
|
| 514 |
+
if session_token and not self.tracker.validate_session(user_id, session_token):
|
| 515 |
+
return "Session expired. Please login again."
|
| 516 |
+
|
| 517 |
+
if session_token:
|
| 518 |
+
self.tracker.update_session_activity(user_id, session_token)
|
| 519 |
+
|
| 520 |
+
if user_id not in self.user_sessions:
|
| 521 |
+
self.user_sessions[user_id] = self.tracker.start_session(user_id)
|
| 522 |
+
|
| 523 |
+
if message.lower().startswith('/progress'):
|
| 524 |
+
return self.get_progress_report(user_id)
|
| 525 |
+
elif message.lower().startswith('/recommendations'):
|
| 526 |
+
return self.get_recommendations(user_id)
|
| 527 |
+
elif message.lower().startswith('/review'):
|
| 528 |
+
return self.get_review_words(user_id)
|
| 529 |
+
elif message.lower().startswith('/help'):
|
| 530 |
+
return self.get_help_message()
|
| 531 |
+
|
| 532 |
+
conversation_chain = self.get_user_chain(user_id)
|
| 533 |
+
result = conversation_chain.invoke({"question": message})
|
| 534 |
+
response = result["answer"]
|
| 535 |
+
|
| 536 |
+
extracted_terms = self.extract_kazakh_terms(message, response)
|
| 537 |
+
|
| 538 |
+
for term, category, definition in extracted_terms:
|
| 539 |
+
if definition and term:
|
| 540 |
+
self.tracker.track_word_encounter(
|
| 541 |
+
user_id,
|
| 542 |
+
term,
|
| 543 |
+
definition,
|
| 544 |
+
category
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
return response
|
| 548 |
+
|
| 549 |
+
def get_progress_report(self, user_id: str) -> str:
|
| 550 |
+
"""Generate a comprehensive progress report for specific user"""
|
| 551 |
+
progress = self.tracker.get_user_progress(user_id)
|
| 552 |
+
|
| 553 |
+
if progress['total_words'] == 0:
|
| 554 |
+
return "Сіз әлі үйренуді бастамадыңыз! Маған кез келген қазақ сөзі немесе тіркес туралы сұраңыз. 🌟\n\nYou haven't started learning yet! Ask me about any Kazakh word or idiom to begin your journey. 🌟"
|
| 555 |
+
|
| 556 |
+
report = "📊 **Сіздің үйрену прогресіңіз / Your Learning Progress Report**\n\n"
|
| 557 |
+
|
| 558 |
+
report += f"🎯 **Үйренген терминдер саны / Total Terms Learned**: {progress['total_words']}\n"
|
| 559 |
+
|
| 560 |
+
for category, stats in progress['category_stats'].items():
|
| 561 |
+
emoji = "📝" if category == "word" else "🎭"
|
| 562 |
+
category_name = "Сөздер / Words" if category == "word" else "Тіркестер / Idioms"
|
| 563 |
+
report += f"{emoji} **{category_name}**: {stats['count']} (Орташа меңгеру / Average mastery: {stats['average_mastery']}/5)\n"
|
| 564 |
+
|
| 565 |
+
report += f"\n⚡ **Соңғы белсенділік / Recent Activity**: {progress['recent_activity']} терминдер соңғы 7 күнде қаралды / terms reviewed in the last 7 days\n"
|
| 566 |
+
|
| 567 |
+
if progress['daily_activity']:
|
| 568 |
+
recent_days = len(progress['daily_activity'])
|
| 569 |
+
report += f"🔥 **Үйрену ырғағы / Learning Streak**: {recent_days} күн белсенді болдыңыз / Active on {recent_days} days recently\n"
|
| 570 |
+
|
| 571 |
+
recommendations = self.tracker.get_learning_recommendations(user_id)
|
| 572 |
+
if recommendations:
|
| 573 |
+
report += f"\n💡 **Ұсыныстар / Recommendations**:\n"
|
| 574 |
+
for i, rec in enumerate(recommendations, 1):
|
| 575 |
+
report += f"{i}. {rec}\n"
|
| 576 |
+
|
| 577 |
+
return report
|
| 578 |
+
|
| 579 |
+
def get_recommendations(self, user_id: str) -> str:
|
| 580 |
+
"""Get personalized learning recommendations for specific user"""
|
| 581 |
+
recommendations = self.tracker.get_learning_recommendations(user_id)
|
| 582 |
+
|
| 583 |
+
if not recommendations:
|
| 584 |
+
return "Керемет! Сіз өте жақсы прогресс жасап жатырсыз. Үнемі жаттығуды жалғастырыңыз! 🎉\n\nGreat job! You're making excellent progress. Keep practicing regularly! 🎉"
|
| 585 |
+
|
| 586 |
+
response = "💡 **Жеке ұсыныстар / Personalized Learning Recommendations**:\n\n"
|
| 587 |
+
for i, rec in enumerate(recommendations, 1):
|
| 588 |
+
response += f"{i}. {rec}\n"
|
| 589 |
+
|
| 590 |
+
return response
|
| 591 |
+
|
| 592 |
+
def get_review_words(self, user_id: str) -> str:
|
| 593 |
+
"""Get words that need review for specific user"""
|
| 594 |
+
words_to_review = self.tracker.get_words_to_review(user_id, 10)
|
| 595 |
+
|
| 596 |
+
if not words_to_review:
|
| 597 |
+
return "Тамаша! Сізде қазір қайталау қажет сөздер жоқ. Жаңа терминдерді үйренуге тырысыңыз! ✨\n\nExcellent! You don't have any words that need review right now. Try learning some new terms! ✨"
|
| 598 |
+
|
| 599 |
+
response = "📚 **Қайталауға арналған сөздер / Words to Review**:\n\n"
|
| 600 |
+
for word_info in words_to_review:
|
| 601 |
+
emoji = "📝" if word_info['category'] == "word" else "🎭"
|
| 602 |
+
mastery_stars = "⭐" * word_info['mastery_level'] + "☆" * (5 - word_info['mastery_level'])
|
| 603 |
+
response += f"{emoji} **{word_info['word']}** - {mastery_stars}\n"
|
| 604 |
+
|
| 605 |
+
definition_preview = word_info['definition'][:80] + "..." if len(word_info['definition']) > 80 else word_info['definition']
|
| 606 |
+
response += f" {definition_preview}\n\n"
|
| 607 |
+
|
| 608 |
+
return response
|
| 609 |
+
|
| 610 |
+
def get_help_message(self) -> str:
|
| 611 |
+
"""Get help message with available commands"""
|
| 612 |
+
return """
|
| 613 |
+
🎓 **Kazakh Learning Assistant Help**
|
| 614 |
+
|
| 615 |
+
**Available Commands**:
|
| 616 |
+
- `/progress` - View your detailed learning progress
|
| 617 |
+
- `/recommendations` - Get personalized learning suggestions
|
| 618 |
+
- `/review` - See words that need review
|
| 619 |
+
- `/help` - Show this help message
|
| 620 |
+
|
| 621 |
+
**How to Use**:
|
| 622 |
+
- Ask about any Kazakh word or idiom for definitions and examples
|
| 623 |
+
- Your progress is automatically tracked as you learn
|
| 624 |
+
- Regular practice improves your mastery levels
|
| 625 |
+
- Use commands to monitor your learning journey
|
| 626 |
+
|
| 627 |
+
**Examples**:
|
| 628 |
+
- "What does 'сәлем' mean?"
|
| 629 |
+
- "Tell me about Kazakh idioms"
|
| 630 |
+
- "How do you say 'thank you' in Kazakh?"
|
| 631 |
+
|
| 632 |
+
Start learning by asking about any Kazakh term! 🌟
|
| 633 |
+
"""
|
| 634 |
+
|
| 635 |
+
def login_user(self, user_id: str) -> str:
|
| 636 |
+
"""Create a session token for user authentication"""
|
| 637 |
+
session_token = self.tracker.create_user_session(user_id)
|
| 638 |
+
return session_token
|
| 639 |
+
|
| 640 |
+
assistant = PersonalizedKazakhAssistant()
|
| 641 |
+
|
| 642 |
+
def chat_interface(message, history):
|
| 643 |
+
"""Chat interface for Gradio - uses default user for web interface"""
|
| 644 |
+
try:
|
| 645 |
+
web_user_id = "web_user_" + str(hash(str(history)) % 10000)
|
| 646 |
+
response = assistant.process_message(message, web_user_id)
|
| 647 |
+
return response
|
| 648 |
+
except Exception as e:
|
| 649 |
+
return f"Sorry, I encountered an error: {str(e)}. Please try again."
|
| 650 |
+
|
| 651 |
+
def api_login(user_id: str) -> dict:
|
| 652 |
+
"""API endpoint for user login/session creation"""
|
| 653 |
+
try:
|
| 654 |
+
session_token = assistant.login_user(user_id)
|
| 655 |
+
return {
|
| 656 |
+
"success": True,
|
| 657 |
+
"session_token": session_token,
|
| 658 |
+
"user_id": user_id,
|
| 659 |
+
"message": "Login successful"
|
| 660 |
+
}
|
| 661 |
+
except Exception as e:
|
| 662 |
+
return {
|
| 663 |
+
"success": False,
|
| 664 |
+
"error": str(e)
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
def api_chat(message: str, user_id: str, session_token: str = None) -> dict:
|
| 668 |
+
"""API endpoint for chat functionality with proper user session"""
|
| 669 |
+
try:
|
| 670 |
+
response = assistant.process_message(message, user_id, session_token)
|
| 671 |
+
return {
|
| 672 |
+
"success": True,
|
| 673 |
+
"response": response,
|
| 674 |
+
"user_id": user_id
|
| 675 |
+
}
|
| 676 |
+
except Exception as e:
|
| 677 |
+
return {
|
| 678 |
+
"success": False,
|
| 679 |
+
"error": str(e),
|
| 680 |
+
"response": "Кешіріңіз, қате орын алды. Қайталап көріңіз."
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
def api_progress(user_id: str, session_token: str = None) -> dict:
|
| 684 |
+
"""API endpoint for user progress with session validation"""
|
| 685 |
+
try:
|
| 686 |
+
if session_token and not assistant.tracker.validate_session(user_id, session_token):
|
| 687 |
+
return {"success": False, "error": "Invalid session"}
|
| 688 |
+
|
| 689 |
+
progress_text = assistant.get_progress_report(user_id)
|
| 690 |
+
progress_data = assistant.tracker.get_user_progress(user_id)
|
| 691 |
+
|
| 692 |
+
return {
|
| 693 |
+
"success": True,
|
| 694 |
+
"progress_text": progress_text,
|
| 695 |
+
"progress_data": progress_data,
|
| 696 |
+
"user_id": user_id
|
| 697 |
+
}
|
| 698 |
+
except Exception as e:
|
| 699 |
+
return {
|
| 700 |
+
"success": False,
|
| 701 |
+
"error": str(e)
|
| 702 |
+
}
|
| 703 |
+
|
| 704 |
+
def api_recommendations(user_id: str, session_token: str = None) -> dict:
|
| 705 |
+
"""API endpoint for learning recommendations with session validation"""
|
| 706 |
+
try:
|
| 707 |
+
if session_token and not assistant.tracker.validate_session(user_id, session_token):
|
| 708 |
+
return {"success": False, "error": "Invalid session"}
|
| 709 |
+
|
| 710 |
+
recommendations_text = assistant.get_recommendations(user_id)
|
| 711 |
+
recommendations_list = assistant.tracker.get_learning_recommendations(user_id)
|
| 712 |
+
|
| 713 |
+
return {
|
| 714 |
+
"success": True,
|
| 715 |
+
"recommendations_text": recommendations_text,
|
| 716 |
+
"recommendations_list": recommendations_list,
|
| 717 |
+
"user_id": user_id
|
| 718 |
+
}
|
| 719 |
+
except Exception as e:
|
| 720 |
+
return {
|
| 721 |
+
"success": False,
|
| 722 |
+
"error": str(e)
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
def api_review_words(user_id: str, session_token: str = None) -> dict:
|
| 726 |
+
"""API endpoint for words to review with session validation"""
|
| 727 |
+
try:
|
| 728 |
+
if session_token and not assistant.tracker.validate_session(user_id, session_token):
|
| 729 |
+
return {"success": False, "error": "Invalid session"}
|
| 730 |
+
|
| 731 |
+
review_text = assistant.get_review_words(user_id)
|
| 732 |
+
review_data = assistant.tracker.get_words_to_review(user_id, 10)
|
| 733 |
+
|
| 734 |
+
return {
|
| 735 |
+
"success": True,
|
| 736 |
+
"review_text": review_text,
|
| 737 |
+
"review_data": review_data,
|
| 738 |
+
"user_id": user_id
|
| 739 |
+
}
|
| 740 |
+
except Exception as e:
|
| 741 |
+
return {
|
| 742 |
+
"success": False,
|
| 743 |
+
"error": str(e)
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
# Gradio Interface with API Testing
|
| 747 |
+
with gr.Blocks(title="🇰🇿 Kazakh Learning API") as demo:
|
| 748 |
+
gr.Markdown("# 🇰🇿 Personalized Kazakh Learning Assistant")
|
| 749 |
+
gr.Markdown("### Multi-User Chat Interface + API Endpoints for Mobile Integration")
|
| 750 |
+
|
| 751 |
+
with gr.Tab("💬 Chat Interface"):
|
| 752 |
+
chat_interface = gr.ChatInterface(
|
| 753 |
+
chat_interface,
|
| 754 |
+
type="messages",
|
| 755 |
+
examples=[
|
| 756 |
+
"сәлем деген не?",
|
| 757 |
+
"күләпара не үшін керек?",
|
| 758 |
+
"/progress",
|
| 759 |
+
"/recommendations",
|
| 760 |
+
"/review"
|
| 761 |
+
]
|
| 762 |
+
)
|
| 763 |
+
|
| 764 |
+
with gr.Tab("🔌 API Testing"):
|
| 765 |
+
gr.Markdown("## Test API Endpoints")
|
| 766 |
+
|
| 767 |
+
with gr.Row():
|
| 768 |
+
with gr.Column():
|
| 769 |
+
user_id_input = gr.Textbox(label="User ID", value="test_user", placeholder="Enter unique user ID")
|
| 770 |
+
session_token_input = gr.Textbox(label="Session Token", placeholder="Session token (get from login)")
|
| 771 |
+
message_input = gr.Textbox(label="Message", placeholder="Enter your message in Kazakh or English")
|
| 772 |
+
|
| 773 |
+
with gr.Row():
|
| 774 |
+
login_btn = gr.Button("🔑 Test Login API")
|
| 775 |
+
chat_btn = gr.Button("💬 Test Chat API")
|
| 776 |
+
progress_btn = gr.Button("📊 Test Progress API")
|
| 777 |
+
recommendations_btn = gr.Button("💡 Test Recommendations API")
|
| 778 |
+
review_btn = gr.Button("📚 Test Review API")
|
| 779 |
+
|
| 780 |
+
api_output = gr.JSON(label="API Response")
|
| 781 |
+
|
| 782 |
+
login_btn.click(
|
| 783 |
+
fn=lambda uid: api_login(uid),
|
| 784 |
+
inputs=user_id_input,
|
| 785 |
+
outputs=api_output
|
| 786 |
+
)
|
| 787 |
+
|
| 788 |
+
chat_btn.click(
|
| 789 |
+
fn=lambda msg, uid, token: api_chat(msg, uid, token),
|
| 790 |
+
inputs=[message_input, user_id_input, session_token_input],
|
| 791 |
+
outputs=api_output
|
| 792 |
+
)
|
| 793 |
+
|
| 794 |
+
progress_btn.click(
|
| 795 |
+
fn=lambda uid, token: api_progress(uid, token),
|
| 796 |
+
inputs=[user_id_input, session_token_input],
|
| 797 |
+
outputs=api_output
|
| 798 |
+
)
|
| 799 |
+
|
| 800 |
+
recommendations_btn.click(
|
| 801 |
+
fn=lambda uid, token: api_recommendations(uid, token),
|
| 802 |
+
inputs=[user_id_input, session_token_input],
|
| 803 |
+
outputs=api_output
|
| 804 |
+
)
|
| 805 |
+
|
| 806 |
+
review_btn.click(
|
| 807 |
+
fn=lambda uid, token: api_review_words(uid, token),
|
| 808 |
+
inputs=[user_id_input, session_token_input],
|
| 809 |
+
outputs=api_output
|
| 810 |
+
)
|
| 811 |
+
|
| 812 |
+
with gr.Tab("📖 API Documentation"):
|
| 813 |
+
gr.Markdown("""
|
| 814 |
+
## API Endpoints for Flutter Integration
|
| 815 |
+
|
| 816 |
+
### Base URL: `https://huggingface.co/spaces/GuestUser33/kazakh-learning-api`
|
| 817 |
+
|
| 818 |
+
### Authentication Flow:
|
| 819 |
+
1. **Login** to get session token
|
| 820 |
+
2. **Use session token** for subsequent API calls
|
| 821 |
+
3. **Session tokens expire** after inactivity
|
| 822 |
+
|
| 823 |
+
### Available Endpoints:
|
| 824 |
+
|
| 825 |
+
#### 1. Login API
|
| 826 |
+
```
|
| 827 |
+
POST /api/predict
|
| 828 |
+
Content-Type: application/json
|
| 829 |
+
|
| 830 |
+
{
|
| 831 |
+
"data": ["user_id"],
|
| 832 |
+
"fn_index": 0
|
| 833 |
+
}
|
| 834 |
+
```
|
| 835 |
+
**Response**: `{"success": true, "session_token": "uuid", "user_id": "user_id"}`
|
| 836 |
+
|
| 837 |
+
#### 2. Chat API
|
| 838 |
+
```
|
| 839 |
+
POST /api/predict
|
| 840 |
+
Content-Type: application/json
|
| 841 |
+
|
| 842 |
+
{
|
| 843 |
+
"data": ["message", "user_id", "session_token"],
|
| 844 |
+
"fn_index": 1
|
| 845 |
+
}
|
| 846 |
+
```
|
| 847 |
+
|
| 848 |
+
#### 3. Progress API
|
| 849 |
+
```
|
| 850 |
+
POST /api/predict
|
| 851 |
+
Content-Type: application/json
|
| 852 |
+
|
| 853 |
+
{
|
| 854 |
+
"data": ["user_id", "session_token"],
|
| 855 |
+
"fn_index": 2
|
| 856 |
+
}
|
| 857 |
+
```
|
| 858 |
+
|
| 859 |
+
#### 4. Recommendations API
|
| 860 |
+
```
|
| 861 |
+
POST /api/predict
|
| 862 |
+
Content-Type: application/json
|
| 863 |
+
|
| 864 |
+
{
|
| 865 |
+
"data": ["user_id", "session_token"],
|
| 866 |
+
"fn_index": 3
|
| 867 |
+
}
|
| 868 |
+
```
|
| 869 |
+
|
| 870 |
+
#### 5. Review Words API
|
| 871 |
+
```
|
| 872 |
+
POST /api/predict
|
| 873 |
+
Content-Type: application/json
|
| 874 |
+
|
| 875 |
+
{
|
| 876 |
+
"data": ["user_id", "session_token"],
|
| 877 |
+
"fn_index": 4
|
| 878 |
+
}
|
| 879 |
+
```
|
| 880 |
+
|
| 881 |
+
### Flutter Integration Example:
|
| 882 |
+
```dart
|
| 883 |
+
class KazakhLearningAPI {
|
| 884 |
+
static const String baseUrl = 'https://huggingface.co/spaces/GuestUser33/kazakh-learning-api';
|
| 885 |
+
String? sessionToken;
|
| 886 |
+
String? userId;
|
| 887 |
+
|
| 888 |
+
// Login and get session token
|
| 889 |
+
Future<bool> login(String userId) async {
|
| 890 |
+
final response = await http.post(
|
| 891 |
+
Uri.parse('$baseUrl/api/predict'),
|
| 892 |
+
headers: {'Content-Type': 'application/json'},
|
| 893 |
+
body: jsonEncode({
|
| 894 |
+
'data': [userId],
|
| 895 |
+
'fn_index': 0
|
| 896 |
+
}),
|
| 897 |
+
);
|
| 898 |
+
|
| 899 |
+
if (response.statusCode == 200) {
|
| 900 |
+
final result = jsonDecode(response.body);
|
| 901 |
+
if (result['data'][0]['success']) {
|
| 902 |
+
this.userId = userId;
|
| 903 |
+
this.sessionToken = result['data'][0]['session_token'];
|
| 904 |
+
return true;
|
| 905 |
+
}
|
| 906 |
+
}
|
| 907 |
+
return false;
|
| 908 |
+
}
|
| 909 |
+
|
| 910 |
+
// Send chat message
|
| 911 |
+
Future<String?> sendMessage(String message) async {
|
| 912 |
+
if (sessionToken == null) return null;
|
| 913 |
+
|
| 914 |
+
final response = await http.post(
|
| 915 |
+
Uri.parse('$baseUrl/api/predict'),
|
| 916 |
+
headers: {'Content-Type': 'application/json'},
|
| 917 |
+
body: jsonEncode({
|
| 918 |
+
'data': [message, userId, sessionToken],
|
| 919 |
+
'fn_index': 1
|
| 920 |
+
}),
|
| 921 |
+
);
|
| 922 |
+
|
| 923 |
+
if (response.statusCode == 200) {
|
| 924 |
+
final result = jsonDecode(response.body);
|
| 925 |
+
if (result['data'][0]['success']) {
|
| 926 |
+
return result['data'][0]['response'];
|
| 927 |
+
}
|
| 928 |
+
}
|
| 929 |
+
return null;
|
| 930 |
+
}
|
| 931 |
+
|
| 932 |
+
// Get user progress
|
| 933 |
+
Future<Map<String, dynamic>?> getProgress() async {
|
| 934 |
+
if (sessionToken == null) return null;
|
| 935 |
+
|
| 936 |
+
final response = await http.post(
|
| 937 |
+
Uri.parse('$baseUrl/api/predict'),
|
| 938 |
+
headers: {'Content-Type': 'application/json'},
|
| 939 |
+
body: jsonEncode({
|
| 940 |
+
'data': [userId, sessionToken],
|
| 941 |
+
'fn_index': 2
|
| 942 |
+
}),
|
| 943 |
+
);
|
| 944 |
+
|
| 945 |
+
if (response.statusCode == 200) {
|
| 946 |
+
final result = jsonDecode(response.body);
|
| 947 |
+
if (result['data'][0]['success']) {
|
| 948 |
+
return result['data'][0]['progress_data'];
|
| 949 |
+
}
|
| 950 |
+
}
|
| 951 |
+
return null;
|
| 952 |
+
}
|
| 953 |
+
}
|
| 954 |
+
```
|
| 955 |
+
|
| 956 |
+
### Key Features:
|
| 957 |
+
- ✅ **Multi-User Support**: Each user has separate learning progress
|
| 958 |
+
- ✅ **Session Management**: Secure session tokens for authentication
|
| 959 |
+
- ✅ **Personalized Tracking**: Individual progress tracking per user
|
| 960 |
+
- ✅ **API Ready**: All endpoints ready for mobile app integration
|
| 961 |
+
- ✅ **Session Validation**: Automatic session validation and expiry
|
| 962 |
+
|
| 963 |
+
### Usage Notes:
|
| 964 |
+
- Always call **login** first to get a session token
|
| 965 |
+
- Include **session_token** in all subsequent API calls
|
| 966 |
+
- Handle **session expiry** by re-logging in
|
| 967 |
+
- Use **unique user_id** for each user (could be email, username, etc.)
|
| 968 |
+
""")
|
| 969 |
+
|
| 970 |
+
if __name__ == "__main__":
|
| 971 |
demo.launch()
|