Spaces:
Build error
Build error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +861 -852
src/streamlit_app.py
CHANGED
|
@@ -1,852 +1,861 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import json
|
| 4 |
-
import
|
| 5 |
-
import
|
| 6 |
-
from
|
| 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 |
-
return
|
| 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 |
-
st.
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
)
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
st.
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
st.
|
| 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 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
st.
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 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 |
-
st.
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
st.
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 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 |
-
with col1:
|
| 617 |
-
st.
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
st.
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
st.
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
st.
|
| 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 |
-
st.
|
| 660 |
-
|
| 661 |
-
st.
|
| 662 |
-
|
| 663 |
-
|
| 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 |
-
|
| 804 |
-
|
| 805 |
-
|
| 806 |
-
|
| 807 |
-
|
| 808 |
-
|
| 809 |
-
|
| 810 |
-
|
| 811 |
-
|
| 812 |
-
|
| 813 |
-
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
|
| 817 |
-
|
| 818 |
-
|
| 819 |
-
|
| 820 |
-
|
| 821 |
-
|
| 822 |
-
|
| 823 |
-
|
| 824 |
-
|
| 825 |
-
|
| 826 |
-
|
| 827 |
-
|
| 828 |
-
|
| 829 |
-
|
| 830 |
-
|
| 831 |
-
|
| 832 |
-
st.
|
| 833 |
-
|
| 834 |
-
|
| 835 |
-
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import json
|
| 4 |
+
import uuid
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
from collections import Counter
|
| 7 |
+
import base64
|
| 8 |
+
|
| 9 |
+
# --- Page Configuration ---
|
| 10 |
+
st.set_page_config(
|
| 11 |
+
page_title="రుచి చూడు (Ruchi Chudu)",
|
| 12 |
+
page_icon="🍲",
|
| 13 |
+
layout="wide"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
# --- In-Memory Storage Functions ---
|
| 17 |
+
def generate_recipe_id():
|
| 18 |
+
"""Generate a unique ID for each recipe"""
|
| 19 |
+
return str(uuid.uuid4())[:8]
|
| 20 |
+
|
| 21 |
+
def save_image_to_memory(image_file, recipe_id):
|
| 22 |
+
"""Save uploaded image to session state as base64"""
|
| 23 |
+
if image_file is not None:
|
| 24 |
+
try:
|
| 25 |
+
# Convert image to base64 for storage in memory
|
| 26 |
+
image_bytes = image_file.getvalue()
|
| 27 |
+
image_b64 = base64.b64encode(image_bytes).decode()
|
| 28 |
+
file_extension = image_file.name.split('.')[-1].lower()
|
| 29 |
+
|
| 30 |
+
# Store in session state
|
| 31 |
+
if 'recipe_images' not in st.session_state:
|
| 32 |
+
st.session_state['recipe_images'] = {}
|
| 33 |
+
|
| 34 |
+
image_key = f"{recipe_id}.{file_extension}"
|
| 35 |
+
st.session_state['recipe_images'][image_key] = {
|
| 36 |
+
'data': image_b64,
|
| 37 |
+
'type': image_file.type
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
return image_key
|
| 41 |
+
except Exception as e:
|
| 42 |
+
st.error(f"Error saving image: {e}")
|
| 43 |
+
return None
|
| 44 |
+
return None
|
| 45 |
+
|
| 46 |
+
def load_image_from_memory(image_filename):
|
| 47 |
+
"""Load image from session state"""
|
| 48 |
+
if image_filename and 'recipe_images' in st.session_state:
|
| 49 |
+
try:
|
| 50 |
+
if image_filename in st.session_state['recipe_images']:
|
| 51 |
+
image_data = st.session_state['recipe_images'][image_filename]
|
| 52 |
+
return base64.b64decode(image_data['data'])
|
| 53 |
+
except Exception as e:
|
| 54 |
+
st.error(f"Error loading image: {e}")
|
| 55 |
+
return None
|
| 56 |
+
|
| 57 |
+
def save_recipe_to_memory(recipe_data):
|
| 58 |
+
"""Save recipe to session state"""
|
| 59 |
+
try:
|
| 60 |
+
if 'recipes' not in st.session_state:
|
| 61 |
+
st.session_state['recipes'] = []
|
| 62 |
+
|
| 63 |
+
# Add to the beginning of the list (newest first)
|
| 64 |
+
st.session_state['recipes'].insert(0, recipe_data)
|
| 65 |
+
return True
|
| 66 |
+
except Exception as e:
|
| 67 |
+
st.error(f"Error saving recipe: {e}")
|
| 68 |
+
return False
|
| 69 |
+
|
| 70 |
+
def load_all_recipes_from_memory():
|
| 71 |
+
"""Load all recipes from session state"""
|
| 72 |
+
if 'recipes' not in st.session_state:
|
| 73 |
+
st.session_state['recipes'] = []
|
| 74 |
+
return st.session_state['recipes']
|
| 75 |
+
|
| 76 |
+
def delete_recipe_from_memory(recipe_id):
|
| 77 |
+
"""Delete a recipe and its associated image from memory"""
|
| 78 |
+
try:
|
| 79 |
+
# Delete recipe
|
| 80 |
+
if 'recipes' in st.session_state:
|
| 81 |
+
st.session_state['recipes'] = [
|
| 82 |
+
r for r in st.session_state['recipes']
|
| 83 |
+
if r.get('id') != recipe_id
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
# Delete associated image
|
| 87 |
+
if 'recipe_images' in st.session_state:
|
| 88 |
+
keys_to_delete = [
|
| 89 |
+
key for key in st.session_state['recipe_images'].keys()
|
| 90 |
+
if key.startswith(recipe_id)
|
| 91 |
+
]
|
| 92 |
+
for key in keys_to_delete:
|
| 93 |
+
del st.session_state['recipe_images'][key]
|
| 94 |
+
|
| 95 |
+
return True
|
| 96 |
+
except Exception as e:
|
| 97 |
+
st.error(f"Error deleting recipe: {e}")
|
| 98 |
+
return False
|
| 99 |
+
|
| 100 |
+
def get_recipe_stats():
|
| 101 |
+
"""Get statistics about stored recipes"""
|
| 102 |
+
try:
|
| 103 |
+
recipes = load_all_recipes_from_memory()
|
| 104 |
+
images = st.session_state.get('recipe_images', {})
|
| 105 |
+
|
| 106 |
+
# Calculate approximate storage size
|
| 107 |
+
storage_size = 0
|
| 108 |
+
for recipe in recipes:
|
| 109 |
+
storage_size += len(json.dumps(recipe, ensure_ascii=False).encode('utf-8'))
|
| 110 |
+
|
| 111 |
+
for image_data in images.values():
|
| 112 |
+
storage_size += len(image_data['data']) * 3 // 4 # Approximate decoded size
|
| 113 |
+
|
| 114 |
+
return {
|
| 115 |
+
'total_recipes': len(recipes),
|
| 116 |
+
'total_images': len(images),
|
| 117 |
+
'storage_size': storage_size
|
| 118 |
+
}
|
| 119 |
+
except:
|
| 120 |
+
return {'total_recipes': 0, 'total_images': 0, 'storage_size': 0}
|
| 121 |
+
|
| 122 |
+
# --- Language and Text ---
|
| 123 |
+
TEXT = {
|
| 124 |
+
"en": {
|
| 125 |
+
"title": "Ruchi Chudu",
|
| 126 |
+
"subtitle": "A Community Cookbook to Preserve Telugu Cuisine",
|
| 127 |
+
"language_select": "Choose Language",
|
| 128 |
+
"sidebar_header": "Contribute Your Recipe!",
|
| 129 |
+
"tab_submit": "📝 Submit Your Recipe",
|
| 130 |
+
"tab_gallery": "🍲 Community Gallery",
|
| 131 |
+
"tab_analytics": "📊 Recipe Analytics",
|
| 132 |
+
"tab_manage": "⚙️ Manage Recipes",
|
| 133 |
+
"form_header": "Tell us about your dish",
|
| 134 |
+
"dish_name": "Dish Name",
|
| 135 |
+
"your_name": "Your Name",
|
| 136 |
+
"district": "Your District",
|
| 137 |
+
"select_district": "--- Select a District ---",
|
| 138 |
+
"recipe_type": "Recipe Type (e.g., Curry, Pickle, Snack)",
|
| 139 |
+
"ingredients": "Ingredients (one per line)",
|
| 140 |
+
"instructions": "Instructions",
|
| 141 |
+
"story": "The Story Behind Your Dish (your memories, family traditions, etc.)",
|
| 142 |
+
"image_upload": "Upload a photo of the dish (optional)",
|
| 143 |
+
"submit_button": "Submit Recipe",
|
| 144 |
+
"success_message": "Thank you! Your recipe has been submitted successfully.",
|
| 145 |
+
"gallery_header": "Explore Recipes from the Community",
|
| 146 |
+
"gallery_empty": "No recipes submitted yet. Be the first to share!",
|
| 147 |
+
"submitted_by": "Submitted by",
|
| 148 |
+
"from_district": "from",
|
| 149 |
+
"submitted_on": "Submitted on",
|
| 150 |
+
"recipe_id": "Recipe ID",
|
| 151 |
+
"story_title": "📖 The Story",
|
| 152 |
+
"ingredients_title": "🌶️ Ingredients",
|
| 153 |
+
"instructions_title": "✍️ Instructions",
|
| 154 |
+
"tags_title": "AI-Generated Tags",
|
| 155 |
+
"error_dish_name": "Please enter a dish name before submitting.",
|
| 156 |
+
"search_placeholder": "Search recipes...",
|
| 157 |
+
"filter_by_district": "Filter by District",
|
| 158 |
+
"filter_by_type": "Filter by Recipe Type",
|
| 159 |
+
"all_districts": "All Districts",
|
| 160 |
+
"all_types": "All Recipe Types",
|
| 161 |
+
"total_recipes": "Total Recipes",
|
| 162 |
+
"total_images": "Total Images",
|
| 163 |
+
"storage_size": "Storage Used",
|
| 164 |
+
"top_districts": "Top Contributing Districts",
|
| 165 |
+
"popular_types": "Popular Recipe Types",
|
| 166 |
+
"recent_recipes": "Recent Submissions",
|
| 167 |
+
"clear_filters": "Clear All Filters",
|
| 168 |
+
"export_recipes": "Export All Recipes",
|
| 169 |
+
"manage_header": "Recipe Management",
|
| 170 |
+
"delete_recipe": "Delete Recipe",
|
| 171 |
+
"confirm_delete": "Are you sure you want to delete this recipe?",
|
| 172 |
+
"recipe_deleted": "Recipe deleted successfully!",
|
| 173 |
+
"backup_data": "Download All Data",
|
| 174 |
+
"backup_created": "Data downloaded successfully!",
|
| 175 |
+
"memory_storage_note": "Note: Data is stored in memory and will be lost when the session ends."
|
| 176 |
+
},
|
| 177 |
+
"te": {
|
| 178 |
+
"title": "రుచి చూడు",
|
| 179 |
+
"subtitle": "మన తెలుగు వంటల సంస్కృతిని కాపాడుదాం",
|
| 180 |
+
"language_select": "భాషను ఎంచుకోండి",
|
| 181 |
+
"sidebar_header": "మీ వంటకాన్ని పంపండి!",
|
| 182 |
+
"tab_submit": "📝 మీ వంటకాన్ని పంపండి",
|
| 183 |
+
"tab_gallery": "🍲 కమ్యూనిటీ గ్యాలరీ",
|
| 184 |
+
"tab_analytics": "📊 వంటకాల విశ్లేషణ",
|
| 185 |
+
"tab_manage": "⚙️ వంటకాలను నిర్వహించండి",
|
| 186 |
+
"form_header": "మీ వంటకం గురించి చెప్పండి",
|
| 187 |
+
"dish_name": "వంటకం పేరు",
|
| 188 |
+
"your_name": "మీ పేరు",
|
| 189 |
+
"district": "మీ జిల్లా",
|
| 190 |
+
"select_district": "--- జిల్లాను ఎంచుకోండి ---",
|
| 191 |
+
"recipe_type": "వంటకం రకం (ఉదా. కూర, పచ్చడి, స్నాక్)",
|
| 192 |
+
"ingredients": "కావలసినవి (ఒకదానికి ఒకటి)",
|
| 193 |
+
"instructions": "తయారీ విధానం",
|
| 194 |
+
"story": "ఈ వంటతో మీ కథ (మీ జ్ఞాపకాలు, కుటుంబ సంప్రదాయాలు మొదలైనవి)",
|
| 195 |
+
"image_upload": "వంటకం ఫోటోను అప్లోడ్ చేయండి (ఐచ్ఛికం)",
|
| 196 |
+
"submit_button": "వంటకాన్ని పంపండి",
|
| 197 |
+
"success_message": "ధన్యవాదాలు! మీ వంటకం విజయవంతంగా సమర్పించబడింది.",
|
| 198 |
+
"gallery_header": "కమ్యూనిటీ నుండి వంటకాలను అన్వేషించండి",
|
| 199 |
+
"gallery_empty": "ఇంకా వంటకాలు సమర్పించబడలేదు. పంచుకున్న మొదటి వ్యక్తి మీరే అవ్వండి!",
|
| 200 |
+
"submitted_by": "సమర్పించిన వారు",
|
| 201 |
+
"from_district": "నుండి",
|
| 202 |
+
"submitted_on": "సమర్పించిన తేదీ",
|
| 203 |
+
"recipe_id": "వంటకం ID",
|
| 204 |
+
"story_title": "📖 కథ",
|
| 205 |
+
"ingredients_title": "🌶️ కావలసినవి",
|
| 206 |
+
"instructions_title": "✍️ తయారీ విధానం",
|
| 207 |
+
"tags_title": "AI ద్వారా రూపొందించబడిన ట్యాగ్లు",
|
| 208 |
+
"error_dish_name": "సమర్పించే ముందు దయచేసి వంటకం పేరును నమోదు చేయండి.",
|
| 209 |
+
"search_placeholder": "వంటకాలను వెతకండి...",
|
| 210 |
+
"filter_by_district": "జిల్లా ద్వారా ఫిల్టర్ చేయండి",
|
| 211 |
+
"filter_by_type": "వంటకం రకం ద్వారా ఫిల్టర్ చేయండి",
|
| 212 |
+
"all_districts": "అన్ని జిల్లాలు",
|
| 213 |
+
"all_types": "అన్ని వంటకాల రకాలు",
|
| 214 |
+
"total_recipes": "మొత్తం వంటకాలు",
|
| 215 |
+
"total_images": "మొత్తం చిత్రాలు",
|
| 216 |
+
"storage_size": "వాడిన స్టోరేజ్",
|
| 217 |
+
"top_districts": "అధిక సహకారం అందించిన జిల్లాలు",
|
| 218 |
+
"popular_types": "ప్రాచుర్యం పొందిన వంటకాల రకాలు",
|
| 219 |
+
"recent_recipes": "ఇటీవలి సమర్పణలు",
|
| 220 |
+
"clear_filters": "అన్ని ఫిల్టర్లను క్లియర్ చేయండి",
|
| 221 |
+
"export_recipes": "అన్ని వంటకాలను ఎగుమతి చేయండి",
|
| 222 |
+
"manage_header": "వంటకాల నిర్వహణ",
|
| 223 |
+
"delete_recipe": "వంటకాన్ని తొలగించండి",
|
| 224 |
+
"confirm_delete": "మీరు ఖచ్చితంగా ఈ వంటకాన్ని తొలగించాలనుకుంటున్నారా?",
|
| 225 |
+
"recipe_deleted": "వంటకం విజయవంతంగా తొలగించబడింది!",
|
| 226 |
+
"backup_data": "అన్ని డేటాను డౌన్లోడ్ చేయండి",
|
| 227 |
+
"backup_created": "డేటా విజయవంతంగా డౌన్లోడ్ చేయబడింది!",
|
| 228 |
+
"memory_storage_note": "గమనిక: డేటా మెమరీలో నిల్వ చేయబడుతుంది మరియు సెషన్ ముగిసినప్పుడు పోతుంది."
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
# --- Data for Dropdowns ---
|
| 233 |
+
DISTRICTS = [
|
| 234 |
+
"Adilabad", "Bhadradri Kothagudem", "Hanumakonda", "Hyderabad", "Jagtial", "Jangaon",
|
| 235 |
+
"Jayashankar Bhupalpally", "Jogulamba Gadwal", "Kamareddy", "Karimnagar", "Khammam",
|
| 236 |
+
"Komaram Bheem", "Mahabubabad", "Mahbubnagar", "Mancherial", "Medak", "Medchal-Malkajgiri",
|
| 237 |
+
"Mulugu", "Nagarkurnool", "Nalgonda", "Narayanpet", "Nirmal", "Nizamabad", "Peddapalli",
|
| 238 |
+
"Rajanna Sircilla", "Ranga Reddy", "Sangareddy", "Siddipet", "Suryapet", "Vikarabad",
|
| 239 |
+
"Wanaparthy", "Warangal", "Yadadri Bhuvanagiri", "Alluri Sitharama Raju", "Anakapalli",
|
| 240 |
+
"Anantapur", "Annamayya", "Bapatla", "Chittoor", "East Godavari", "Eluru", "Guntur",
|
| 241 |
+
"Kakinada", "Konaseema", "Krishna", "Kurnool", "Nandyal", "NTR", "Palnadu", "Parvathipuram Manyam",
|
| 242 |
+
"Prakasam", "Sri Potti Sriramulu Nellore", "Sri Sathya Sai", "Srikakulam", "Tirupati",
|
| 243 |
+
"Visakhapatnam", "Vizianagaram", "West Godavari", "YSR Kadapa"
|
| 244 |
+
]
|
| 245 |
+
DISTRICTS.sort()
|
| 246 |
+
|
| 247 |
+
RECIPE_TYPES = ["Curry (కూర)", "Fry (వేపుడు)", "Pickle (పచ్చడి)", "Chutney (చట్నీ)", "Pulusu (పులుసు)", "Snack (చిరుతిండి)", "Sweet (తీపి)", "Breakfast (అల్పాహారం)", "Rice Dish (అన్నం రకం)", "Other (ఇతర)"]
|
| 248 |
+
|
| 249 |
+
# --- Session State Initialization ---
|
| 250 |
+
if 'language' not in st.session_state:
|
| 251 |
+
st.session_state['language'] = 'en'
|
| 252 |
+
if 'recipes' not in st.session_state:
|
| 253 |
+
st.session_state['recipes'] = []
|
| 254 |
+
if 'recipe_images' not in st.session_state:
|
| 255 |
+
st.session_state['recipe_images'] = {}
|
| 256 |
+
|
| 257 |
+
# --- Helper Functions ---
|
| 258 |
+
def get_text(key):
|
| 259 |
+
"""Fetches text from the dictionary based on the selected language."""
|
| 260 |
+
return TEXT[st.session_state['language']][key]
|
| 261 |
+
|
| 262 |
+
def simulate_ai_tagging(story, ingredients):
|
| 263 |
+
"""Simulate AI tagging based on content analysis"""
|
| 264 |
+
tags = set()
|
| 265 |
+
text_to_scan = (story + " " + ingredients).lower()
|
| 266 |
+
|
| 267 |
+
keyword_map = {
|
| 268 |
+
"festival": ["sankranti", "ugadi", "dasara", "diwali", "vinayaka chaviti"],
|
| 269 |
+
"spicy": ["chilli", "karam", "mirapa", "pepper", "guntur"],
|
| 270 |
+
"healthy": ["millet", "ragi", "jowar", "vegetable", "leafy", "greens"],
|
| 271 |
+
"quick": ["15 min", "20 min", "quick", "easy", "tvaraga"],
|
| 272 |
+
"traditional": ["grandma", "ammamma", "nanamma", "traditional", "sampradayam"],
|
| 273 |
+
"summer": ["mango", "summer", "cool", "curd", "perugu"],
|
| 274 |
+
"winter": ["winter", "warm", "hot", "sheeta"],
|
| 275 |
+
"vegetarian": ["vegetable", "veg", "sabzi", "kura"],
|
| 276 |
+
"non-vegetarian": ["chicken", "mutton", "fish", "egg", "kodi", "meka"]
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
for tag, keywords in keyword_map.items():
|
| 280 |
+
if any(keyword in text_to_scan for keyword in keywords):
|
| 281 |
+
tags.add(tag.capitalize())
|
| 282 |
+
|
| 283 |
+
if not tags:
|
| 284 |
+
tags.add("Community Recipe")
|
| 285 |
+
|
| 286 |
+
return list(tags)
|
| 287 |
+
|
| 288 |
+
def filter_recipes(recipes, search_term="", district_filter="", type_filter=""):
|
| 289 |
+
"""Filter recipes based on search and filter criteria"""
|
| 290 |
+
filtered = recipes
|
| 291 |
+
|
| 292 |
+
if search_term:
|
| 293 |
+
filtered = [r for r in filtered if
|
| 294 |
+
search_term.lower() in r['dish_name'].lower() or
|
| 295 |
+
search_term.lower() in r.get('your_name', '').lower() or
|
| 296 |
+
search_term.lower() in r.get('ingredients', '').lower()]
|
| 297 |
+
|
| 298 |
+
if district_filter and district_filter != get_text('all_districts'):
|
| 299 |
+
filtered = [r for r in filtered if r.get('district') == district_filter]
|
| 300 |
+
|
| 301 |
+
if type_filter and type_filter != get_text('all_types'):
|
| 302 |
+
filtered = [r for r in filtered if r.get('recipe_type') == type_filter]
|
| 303 |
+
|
| 304 |
+
return filtered
|
| 305 |
+
|
| 306 |
+
def export_recipes_to_csv(recipes):
|
| 307 |
+
"""Export recipes to CSV format"""
|
| 308 |
+
if not recipes:
|
| 309 |
+
return None
|
| 310 |
+
|
| 311 |
+
export_data = []
|
| 312 |
+
for recipe in recipes:
|
| 313 |
+
export_data.append({
|
| 314 |
+
'Recipe ID': recipe.get('id', ''),
|
| 315 |
+
'Dish Name': recipe['dish_name'],
|
| 316 |
+
'Submitted By': recipe.get('your_name', ''),
|
| 317 |
+
'District': recipe.get('district', ''),
|
| 318 |
+
'Recipe Type': recipe.get('recipe_type', ''),
|
| 319 |
+
'Ingredients': recipe.get('ingredients', ''),
|
| 320 |
+
'Instructions': recipe.get('instructions', ''),
|
| 321 |
+
'Story': recipe.get('story', ''),
|
| 322 |
+
'Tags': ', '.join(recipe.get('tags', [])),
|
| 323 |
+
'Submitted Date': recipe.get('submitted_date', ''),
|
| 324 |
+
'Has Image': 'Yes' if recipe.get('image_filename') else 'No'
|
| 325 |
+
})
|
| 326 |
+
|
| 327 |
+
return pd.DataFrame(export_data)
|
| 328 |
+
|
| 329 |
+
def format_storage_size(size_bytes):
|
| 330 |
+
"""Convert bytes to human readable format"""
|
| 331 |
+
for unit in ['B', 'KB', 'MB', 'GB']:
|
| 332 |
+
if size_bytes < 1024.0:
|
| 333 |
+
return f"{size_bytes:.1f} {unit}"
|
| 334 |
+
size_bytes /= 1024.0
|
| 335 |
+
return f"{size_bytes:.1f} TB"
|
| 336 |
+
|
| 337 |
+
# --- Sidebar ---
|
| 338 |
+
with st.sidebar:
|
| 339 |
+
st.title(f"🍲 {get_text('title')}")
|
| 340 |
+
st.markdown(get_text('subtitle'))
|
| 341 |
+
st.markdown("---")
|
| 342 |
+
|
| 343 |
+
# Language selector
|
| 344 |
+
lang_choice = st.radio(
|
| 345 |
+
get_text('language_select'),
|
| 346 |
+
('English', 'తెలుగు'),
|
| 347 |
+
horizontal=True,
|
| 348 |
+
key='lang_radio'
|
| 349 |
+
)
|
| 350 |
+
st.session_state['language'] = 'te' if lang_choice == 'తెలుగు' else 'en'
|
| 351 |
+
|
| 352 |
+
st.info(get_text('sidebar_header'))
|
| 353 |
+
|
| 354 |
+
# Storage stats
|
| 355 |
+
stats = get_recipe_stats()
|
| 356 |
+
st.metric(get_text('total_recipes'), stats['total_recipes'])
|
| 357 |
+
st.metric(get_text('total_images'), stats['total_images'])
|
| 358 |
+
st.metric(get_text('storage_size'), format_storage_size(stats['storage_size']))
|
| 359 |
+
|
| 360 |
+
# Memory storage note
|
| 361 |
+
st.warning(get_text('memory_storage_note'))
|
| 362 |
+
|
| 363 |
+
# --- Main App Layout ---
|
| 364 |
+
st.title(get_text('title'))
|
| 365 |
+
|
| 366 |
+
tab_submit, tab_gallery, tab_analytics, tab_manage = st.tabs([
|
| 367 |
+
get_text('tab_submit'),
|
| 368 |
+
get_text('tab_gallery'),
|
| 369 |
+
get_text('tab_analytics'),
|
| 370 |
+
get_text('tab_manage')
|
| 371 |
+
])
|
| 372 |
+
|
| 373 |
+
# --- Submission Form Tab ---
|
| 374 |
+
with tab_submit:
|
| 375 |
+
st.header(get_text('form_header'))
|
| 376 |
+
|
| 377 |
+
with st.form(key="recipe_form"):
|
| 378 |
+
col1, col2 = st.columns(2)
|
| 379 |
+
|
| 380 |
+
with col1:
|
| 381 |
+
dish_name = st.text_input(label=get_text('dish_name'))
|
| 382 |
+
your_name = st.text_input(label=get_text('your_name'))
|
| 383 |
+
image_file = st.file_uploader(get_text('image_upload'), type=['jpg', 'jpeg', 'png'])
|
| 384 |
+
|
| 385 |
+
with col2:
|
| 386 |
+
recipe_type = st.selectbox(label=get_text('recipe_type'), options=RECIPE_TYPES)
|
| 387 |
+
district = st.selectbox(
|
| 388 |
+
label=get_text('district'),
|
| 389 |
+
options=[get_text('select_district')] + DISTRICTS
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
ingredients = st.text_area(label=get_text('ingredients'), height=150)
|
| 393 |
+
instructions = st.text_area(label=get_text('instructions'), height=200)
|
| 394 |
+
story = st.text_area(label=get_text('story'), height=150)
|
| 395 |
+
|
| 396 |
+
submitted = st.form_submit_button(get_text('submit_button'))
|
| 397 |
+
|
| 398 |
+
if submitted:
|
| 399 |
+
if not dish_name:
|
| 400 |
+
st.error(get_text('error_dish_name'))
|
| 401 |
+
else:
|
| 402 |
+
# Generate unique ID for this recipe
|
| 403 |
+
recipe_id = generate_recipe_id()
|
| 404 |
+
|
| 405 |
+
# Save image if provided
|
| 406 |
+
image_filename = save_image_to_memory(image_file, recipe_id)
|
| 407 |
+
|
| 408 |
+
# Generate AI tags
|
| 409 |
+
ai_tags = simulate_ai_tagging(story, ingredients)
|
| 410 |
+
|
| 411 |
+
# Create new recipe with unique ID
|
| 412 |
+
new_recipe = {
|
| 413 |
+
"id": recipe_id,
|
| 414 |
+
"dish_name": dish_name,
|
| 415 |
+
"your_name": your_name,
|
| 416 |
+
"district": district if district != get_text('select_district') else '',
|
| 417 |
+
"recipe_type": recipe_type,
|
| 418 |
+
"ingredients": ingredients,
|
| 419 |
+
"instructions": instructions,
|
| 420 |
+
"story": story,
|
| 421 |
+
"image_filename": image_filename,
|
| 422 |
+
"tags": ai_tags,
|
| 423 |
+
"submitted_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
# Save recipe to memory
|
| 427 |
+
if save_recipe_to_memory(new_recipe):
|
| 428 |
+
st.success(f"{get_text('success_message')} (ID: {recipe_id})")
|
| 429 |
+
st.balloons()
|
| 430 |
+
|
| 431 |
+
# Show recipe details
|
| 432 |
+
with st.expander("Recipe Details", expanded=True):
|
| 433 |
+
st.write(f"**{get_text('recipe_id')}:** `{recipe_id}`")
|
| 434 |
+
st.write(f"**Storage:** In-memory (session-based)")
|
| 435 |
+
if image_filename:
|
| 436 |
+
st.write(f"**Image:** Stored as {image_filename}")
|
| 437 |
+
else:
|
| 438 |
+
st.error("Failed to save recipe. Please try again.")
|
| 439 |
+
|
| 440 |
+
# --- Community Gallery Tab ---
|
| 441 |
+
with tab_gallery:
|
| 442 |
+
st.header(get_text('gallery_header'))
|
| 443 |
+
|
| 444 |
+
# Filters and search
|
| 445 |
+
col1, col2, col3, col4 = st.columns([2, 1, 1, 1])
|
| 446 |
+
|
| 447 |
+
with col1:
|
| 448 |
+
search_term = st.text_input(
|
| 449 |
+
label="",
|
| 450 |
+
placeholder=get_text('search_placeholder'),
|
| 451 |
+
key="search_recipes"
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
with col2:
|
| 455 |
+
district_options = [get_text('all_districts')] + DISTRICTS
|
| 456 |
+
district_filter = st.selectbox(
|
| 457 |
+
get_text('filter_by_district'),
|
| 458 |
+
district_options,
|
| 459 |
+
key="district_filter"
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
with col3:
|
| 463 |
+
type_options = [get_text('all_types')] + RECIPE_TYPES
|
| 464 |
+
type_filter = st.selectbox(
|
| 465 |
+
get_text('filter_by_type'),
|
| 466 |
+
type_options,
|
| 467 |
+
key="type_filter"
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
with col4:
|
| 471 |
+
if st.button(get_text('clear_filters')):
|
| 472 |
+
st.session_state.search_recipes = ""
|
| 473 |
+
st.session_state.district_filter = get_text('all_districts')
|
| 474 |
+
st.session_state.type_filter = get_text('all_types')
|
| 475 |
+
st.rerun()
|
| 476 |
+
|
| 477 |
+
st.markdown("---")
|
| 478 |
+
|
| 479 |
+
# Filter recipes
|
| 480 |
+
recipes = load_all_recipes_from_memory()
|
| 481 |
+
filtered_recipes = filter_recipes(
|
| 482 |
+
recipes,
|
| 483 |
+
search_term,
|
| 484 |
+
district_filter,
|
| 485 |
+
type_filter
|
| 486 |
+
)
|
| 487 |
+
|
| 488 |
+
if not filtered_recipes:
|
| 489 |
+
if not recipes:
|
| 490 |
+
st.info(get_text('gallery_empty'))
|
| 491 |
+
else:
|
| 492 |
+
st.info("No recipes match your search criteria. Try adjusting your filters.")
|
| 493 |
+
else:
|
| 494 |
+
st.write(f"**{len(filtered_recipes)}** recipes found")
|
| 495 |
+
|
| 496 |
+
# Display recipes
|
| 497 |
+
for recipe in filtered_recipes:
|
| 498 |
+
with st.container():
|
| 499 |
+
st.markdown("""
|
| 500 |
+
<style>
|
| 501 |
+
.recipe-card {
|
| 502 |
+
background-color: #f8f9fa;
|
| 503 |
+
border-radius: 15px;
|
| 504 |
+
padding: 25px;
|
| 505 |
+
margin-bottom: 25px;
|
| 506 |
+
border-left: 5px solid #ff6b6b;
|
| 507 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 508 |
+
}
|
| 509 |
+
</style>
|
| 510 |
+
""", unsafe_allow_html=True)
|
| 511 |
+
|
| 512 |
+
with st.container():
|
| 513 |
+
st.markdown('<div class="recipe-card">', unsafe_allow_html=True)
|
| 514 |
+
|
| 515 |
+
# Header with recipe ID
|
| 516 |
+
col_header1, col_header2, col_header3 = st.columns([2, 1, 1])
|
| 517 |
+
with col_header1:
|
| 518 |
+
st.subheader(f"🍽️ {recipe['dish_name']}")
|
| 519 |
+
st.code(f"ID: {recipe.get('id', 'N/A')}", language=None)
|
| 520 |
+
|
| 521 |
+
with col_header2:
|
| 522 |
+
if recipe.get('recipe_type'):
|
| 523 |
+
st.info(recipe['recipe_type'])
|
| 524 |
+
|
| 525 |
+
with col_header3:
|
| 526 |
+
if recipe.get('submitted_date'):
|
| 527 |
+
st.caption(f"{get_text('submitted_on')}: {recipe['submitted_date'][:10]}")
|
| 528 |
+
|
| 529 |
+
# Metadata
|
| 530 |
+
metadata_parts = []
|
| 531 |
+
if recipe.get('your_name'):
|
| 532 |
+
metadata_parts.append(f"**{recipe['your_name']}**")
|
| 533 |
+
if recipe.get('district'):
|
| 534 |
+
metadata_parts.append(f"{get_text('from_district')} **{recipe['district']}**")
|
| 535 |
+
|
| 536 |
+
if metadata_parts:
|
| 537 |
+
st.caption(f"{get_text('submitted_by')} " + " • ".join(metadata_parts))
|
| 538 |
+
|
| 539 |
+
# Tags
|
| 540 |
+
if recipe.get('tags'):
|
| 541 |
+
tag_display = " ".join([f"`{tag}`" for tag in recipe['tags']])
|
| 542 |
+
st.markdown(tag_display)
|
| 543 |
+
|
| 544 |
+
# Content
|
| 545 |
+
left_col, right_col = st.columns([1, 1.2])
|
| 546 |
+
|
| 547 |
+
with left_col:
|
| 548 |
+
if recipe.get('image_filename'):
|
| 549 |
+
try:
|
| 550 |
+
image_data = load_image_from_memory(recipe['image_filename'])
|
| 551 |
+
if image_data:
|
| 552 |
+
st.image(image_data, caption=recipe['dish_name'], use_column_width=True)
|
| 553 |
+
else:
|
| 554 |
+
st.image("https://placehold.co/400x300/E8F4FD/31343C?text=Image+Not+Found")
|
| 555 |
+
except:
|
| 556 |
+
st.image("https://placehold.co/400x300/E8F4FD/31343C?text=Error+Loading+Image")
|
| 557 |
+
else:
|
| 558 |
+
st.image("https://placehold.co/400x300/E8F4FD/31343C?text=No+Image+Available")
|
| 559 |
+
|
| 560 |
+
with right_col:
|
| 561 |
+
if recipe.get('story'):
|
| 562 |
+
with st.expander(get_text('story_title')):
|
| 563 |
+
st.write(recipe['story'])
|
| 564 |
+
|
| 565 |
+
with st.expander(get_text('ingredients_title')):
|
| 566 |
+
if recipe.get('ingredients'):
|
| 567 |
+
ingredients_list = recipe['ingredients'].split('\n')
|
| 568 |
+
for ingredient in ingredients_list:
|
| 569 |
+
if ingredient.strip():
|
| 570 |
+
st.write(f"• {ingredient.strip()}")
|
| 571 |
+
else:
|
| 572 |
+
st.write("No ingredients listed.")
|
| 573 |
+
|
| 574 |
+
with st.expander(get_text('instructions_title'), expanded=True):
|
| 575 |
+
st.write(recipe.get('instructions', 'No instructions provided.'))
|
| 576 |
+
|
| 577 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 578 |
+
|
| 579 |
+
st.markdown("---")
|
| 580 |
+
|
| 581 |
+
# --- Analytics Tab ---
|
| 582 |
+
with tab_analytics:
|
| 583 |
+
st.header("📊 Recipe Analytics")
|
| 584 |
+
|
| 585 |
+
recipes = load_all_recipes_from_memory()
|
| 586 |
+
|
| 587 |
+
if not recipes:
|
| 588 |
+
st.info("No data available yet. Submit some recipes to see analytics!")
|
| 589 |
+
else:
|
| 590 |
+
# Overview metrics
|
| 591 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 592 |
+
|
| 593 |
+
stats = get_recipe_stats()
|
| 594 |
+
|
| 595 |
+
with col1:
|
| 596 |
+
st.metric(get_text('total_recipes'), len(recipes))
|
| 597 |
+
|
| 598 |
+
with col2:
|
| 599 |
+
unique_contributors = len(set(r.get('your_name', 'Anonymous') for r in recipes if r.get('your_name')))
|
| 600 |
+
st.metric("Contributors", unique_contributors)
|
| 601 |
+
|
| 602 |
+
with col3:
|
| 603 |
+
unique_districts = len(set(r.get('district', '') for r in recipes if r.get('district')))
|
| 604 |
+
st.metric("Districts Represented", unique_districts)
|
| 605 |
+
|
| 606 |
+
with col4:
|
| 607 |
+
recipes_with_images = len([r for r in recipes if r.get('image_filename')])
|
| 608 |
+
st.metric("Recipes with Photos", recipes_with_images)
|
| 609 |
+
|
| 610 |
+
st.markdown("---")
|
| 611 |
+
|
| 612 |
+
# Storage information
|
| 613 |
+
st.subheader("💾 Memory Storage Information")
|
| 614 |
+
col1, col2, col3 = st.columns(3)
|
| 615 |
+
|
| 616 |
+
with col1:
|
| 617 |
+
st.info(f"**Recipe Data:** {stats['total_recipes']} items")
|
| 618 |
+
st.caption("Stored in session state")
|
| 619 |
+
|
| 620 |
+
with col2:
|
| 621 |
+
st.info(f"**Image Data:** {stats['total_images']} items")
|
| 622 |
+
st.caption("Stored as base64 in memory")
|
| 623 |
+
|
| 624 |
+
with col3:
|
| 625 |
+
st.info(f"**Memory Usage:** {format_storage_size(stats['storage_size'])}")
|
| 626 |
+
st.caption("Approximate size in memory")
|
| 627 |
+
|
| 628 |
+
st.markdown("---")
|
| 629 |
+
|
| 630 |
+
# Charts
|
| 631 |
+
col1, col2 = st.columns(2)
|
| 632 |
+
|
| 633 |
+
with col1:
|
| 634 |
+
st.subheader(get_text('top_districts'))
|
| 635 |
+
district_counts = Counter(r.get('district', 'Unknown') for r in recipes if r.get('district'))
|
| 636 |
+
if district_counts:
|
| 637 |
+
district_df = pd.DataFrame(list(district_counts.items()), columns=['District', 'Count'])
|
| 638 |
+
district_df = district_df.sort_values('Count', ascending=True).tail(10)
|
| 639 |
+
st.bar_chart(district_df.set_index('District'))
|
| 640 |
+
else:
|
| 641 |
+
st.info("No district data available")
|
| 642 |
+
|
| 643 |
+
with col2:
|
| 644 |
+
st.subheader(get_text('popular_types'))
|
| 645 |
+
type_counts = Counter(r.get('recipe_type', 'Unknown') for r in recipes)
|
| 646 |
+
if type_counts:
|
| 647 |
+
type_df = pd.DataFrame(list(type_counts.items()), columns=['Type', 'Count'])
|
| 648 |
+
st.bar_chart(type_df.set_index('Type'))
|
| 649 |
+
|
| 650 |
+
# Recent activity
|
| 651 |
+
st.subheader(get_text('recent_recipes'))
|
| 652 |
+
recent_recipes = sorted(recipes,
|
| 653 |
+
key=lambda x: x.get('submitted_date', ''),
|
| 654 |
+
reverse=True)[:10]
|
| 655 |
+
|
| 656 |
+
for recipe in recent_recipes:
|
| 657 |
+
col1, col2, col3, col4 = st.columns([2, 1, 1, 1])
|
| 658 |
+
with col1:
|
| 659 |
+
st.write(f"**{recipe['dish_name']}**")
|
| 660 |
+
with col2:
|
| 661 |
+
st.write(recipe.get('your_name', 'Anonymous'))
|
| 662 |
+
with col3:
|
| 663 |
+
st.write(recipe.get('submitted_date', 'Unknown')[:10] if recipe.get('submitted_date') else 'Unknown')
|
| 664 |
+
with col4:
|
| 665 |
+
st.code(recipe.get('id', 'N/A'), language=None)
|
| 666 |
+
|
| 667 |
+
# Export functionality
|
| 668 |
+
st.markdown("---")
|
| 669 |
+
col1, col2 = st.columns(2)
|
| 670 |
+
|
| 671 |
+
with col1:
|
| 672 |
+
if st.button(get_text('export_recipes')):
|
| 673 |
+
csv_data = export_recipes_to_csv(recipes)
|
| 674 |
+
if csv_data is not None:
|
| 675 |
+
csv_string = csv_data.to_csv(index=False)
|
| 676 |
+
st.download_button(
|
| 677 |
+
label="Download CSV",
|
| 678 |
+
data=csv_string,
|
| 679 |
+
file_name=f"ruchi_chudu_recipes_{datetime.now().strftime('%Y%m%d')}.csv",
|
| 680 |
+
mime="text/csv"
|
| 681 |
+
)
|
| 682 |
+
else:
|
| 683 |
+
st.error("No recipes to export")
|
| 684 |
+
|
| 685 |
+
with col2:
|
| 686 |
+
if st.button(get_text('backup_data')):
|
| 687 |
+
try:
|
| 688 |
+
# Create a comprehensive JSON backup
|
| 689 |
+
backup_data = {
|
| 690 |
+
"recipes": recipes,
|
| 691 |
+
"images": st.session_state.get('recipe_images', {}),
|
| 692 |
+
"exported_date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
| 693 |
+
"total_recipes": len(recipes),
|
| 694 |
+
"total_images": len(st.session_state.get('recipe_images', {}))
|
| 695 |
+
}
|
| 696 |
+
|
| 697 |
+
backup_json = json.dumps(backup_data, ensure_ascii=False, indent=2)
|
| 698 |
+
|
| 699 |
+
st.download_button(
|
| 700 |
+
label="Download JSON Backup",
|
| 701 |
+
data=backup_json,
|
| 702 |
+
file_name=f"ruchi_chudu_backup_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json",
|
| 703 |
+
mime="application/json"
|
| 704 |
+
)
|
| 705 |
+
st.success(get_text('backup_created'))
|
| 706 |
+
except Exception as e:
|
| 707 |
+
st.error(f"Error creating backup: {e}")
|
| 708 |
+
|
| 709 |
+
# --- Management Tab ---
|
| 710 |
+
with tab_manage:
|
| 711 |
+
st.header(get_text('manage_header'))
|
| 712 |
+
|
| 713 |
+
recipes = load_all_recipes_from_memory()
|
| 714 |
+
|
| 715 |
+
if not recipes:
|
| 716 |
+
st.info("No recipes to manage yet.")
|
| 717 |
+
else:
|
| 718 |
+
st.write(f"Managing **{len(recipes)}** recipes")
|
| 719 |
+
|
| 720 |
+
# Search for specific recipe to manage
|
| 721 |
+
search_manage = st.text_input("Search for recipe to manage", placeholder="Enter recipe name or ID...")
|
| 722 |
+
|
| 723 |
+
# Filter recipes for management
|
| 724 |
+
manage_recipes = recipes
|
| 725 |
+
if search_manage:
|
| 726 |
+
manage_recipes = [r for r in recipes if
|
| 727 |
+
search_manage.lower() in r['dish_name'].lower() or
|
| 728 |
+
search_manage.lower() in r.get('id', '').lower()]
|
| 729 |
+
|
| 730 |
+
if not manage_recipes and search_manage:
|
| 731 |
+
st.warning("No recipes found matching your search.")
|
| 732 |
+
|
| 733 |
+
# Display recipes for management
|
| 734 |
+
for recipe in manage_recipes[:20]: # Limit to 20 for performance
|
| 735 |
+
with st.expander(f"🍽️ {recipe['dish_name']} (ID: {recipe.get('id', 'N/A')})"):
|
| 736 |
+
col1, col2, col3 = st.columns([2, 1, 1])
|
| 737 |
+
|
| 738 |
+
with col1:
|
| 739 |
+
st.write(f"**Submitted by:** {recipe.get('your_name', 'Anonymous')}")
|
| 740 |
+
st.write(f"**District:** {recipe.get('district', 'Not specified')}")
|
| 741 |
+
st.write(f"**Type:** {recipe.get('recipe_type', 'Not specified')}")
|
| 742 |
+
st.write(f"**Submitted:** {recipe.get('submitted_date', 'Unknown')}")
|
| 743 |
+
|
| 744 |
+
with col2:
|
| 745 |
+
st.write(f"**Storage Location:**")
|
| 746 |
+
st.code("Session Memory")
|
| 747 |
+
|
| 748 |
+
if recipe.get('image_filename'):
|
| 749 |
+
st.write(f"**Image:**")
|
| 750 |
+
st.code(f"Memory: {recipe['image_filename']}")
|
| 751 |
+
|
| 752 |
+
# Show approximate size
|
| 753 |
+
recipe_size = len(json.dumps(recipe, ensure_ascii=False).encode('utf-8'))
|
| 754 |
+
st.caption(f"Size: {format_storage_size(recipe_size)}")
|
| 755 |
+
|
| 756 |
+
with col3:
|
| 757 |
+
# Delete button with confirmation
|
| 758 |
+
delete_key = f"delete_{recipe.get('id', 'unknown')}"
|
| 759 |
+
confirm_key = f"confirm_delete_{recipe.get('id')}"
|
| 760 |
+
|
| 761 |
+
if st.button(f"🗑️ {get_text('delete_recipe')}", key=delete_key):
|
| 762 |
+
if st.session_state.get(confirm_key, False):
|
| 763 |
+
if delete_recipe_from_memory(recipe.get('id')):
|
| 764 |
+
st.success(get_text('recipe_deleted'))
|
| 765 |
+
st.rerun()
|
| 766 |
+
else:
|
| 767 |
+
st.error("Failed to delete recipe.")
|
| 768 |
+
else:
|
| 769 |
+
st.session_state[confirm_key] = True
|
| 770 |
+
st.warning(get_text('confirm_delete'))
|
| 771 |
+
|
| 772 |
+
if st.session_state.get(confirm_key, False):
|
| 773 |
+
if st.button(f"✅ Confirm Delete", key=f"confirm_{recipe.get('id')}"):
|
| 774 |
+
if delete_recipe_from_memory(recipe.get('id')):
|
| 775 |
+
st.success(get_text('recipe_deleted'))
|
| 776 |
+
# Clear the confirmation state
|
| 777 |
+
st.session_state[confirm_key] = False
|
| 778 |
+
st.rerun()
|
| 779 |
+
else:
|
| 780 |
+
st.error("Failed to delete recipe.")
|
| 781 |
+
|
| 782 |
+
if len(manage_recipes) > 20:
|
| 783 |
+
st.info(f"Showing first 20 recipes. Use search to find specific recipes. Total: {len(manage_recipes)}")
|
| 784 |
+
|
| 785 |
+
# Bulk operations
|
| 786 |
+
st.markdown("---")
|
| 787 |
+
st.subheader("🔧 Memory Management")
|
| 788 |
+
|
| 789 |
+
col1, col2, col3 = st.columns(3)
|
| 790 |
+
|
| 791 |
+
with col1:
|
| 792 |
+
if st.button("📊 Refresh Stats"):
|
| 793 |
+
stats = get_recipe_stats()
|
| 794 |
+
st.success("Stats refreshed!")
|
| 795 |
+
st.write(f"Total recipes: {stats['total_recipes']}")
|
| 796 |
+
st.write(f"Total images: {stats['total_images']}")
|
| 797 |
+
st.write(f"Memory usage: {format_storage_size(stats['storage_size'])}")
|
| 798 |
+
|
| 799 |
+
with col2:
|
| 800 |
+
if st.button("🔄 Reload Data"):
|
| 801 |
+
st.success("Data reloaded from session state!")
|
| 802 |
+
st.rerun()
|
| 803 |
+
|
| 804 |
+
with col3:
|
| 805 |
+
if st.button("🧹 Clear All Data", type="secondary"):
|
| 806 |
+
if st.button("⚠️ Confirm Clear All", type="secondary"):
|
| 807 |
+
st.session_state['recipes'] = []
|
| 808 |
+
st.session_state['recipe_images'] = {}
|
| 809 |
+
st.success("All data cleared!")
|
| 810 |
+
st.rerun()
|
| 811 |
+
|
| 812 |
+
# Session info
|
| 813 |
+
st.markdown("---")
|
| 814 |
+
st.subheader("📋 Session Information")
|
| 815 |
+
|
| 816 |
+
col1, col2 = st.columns(2)
|
| 817 |
+
|
| 818 |
+
with col1:
|
| 819 |
+
st.info("**Storage Type:** Session Memory")
|
| 820 |
+
st.caption("Data persists only during this browser session")
|
| 821 |
+
|
| 822 |
+
st.info("**Data Persistence:** Temporary")
|
| 823 |
+
st.caption("Data will be lost when you close the browser or refresh")
|
| 824 |
+
|
| 825 |
+
with col2:
|
| 826 |
+
st.info("**Session State Keys:**")
|
| 827 |
+
session_keys = [key for key in st.session_state.keys() if key in ['recipes', 'recipe_images']]
|
| 828 |
+
for key in session_keys:
|
| 829 |
+
if key == 'recipes':
|
| 830 |
+
st.caption(f"• {key}: {len(st.session_state[key])} items")
|
| 831 |
+
elif key == 'recipe_images':
|
| 832 |
+
st.caption(f"• {key}: {len(st.session_state[key])} items")
|
| 833 |
+
|
| 834 |
+
# --- Footer Information ---
|
| 835 |
+
st.markdown("---")
|
| 836 |
+
st.markdown("""
|
| 837 |
+
### 💡 Important Notes for Hugging Face Spaces:
|
| 838 |
+
|
| 839 |
+
- **Data Storage**: All recipes and images are stored in memory (session state) only
|
| 840 |
+
- **Persistence**: Data will be lost when the browser session ends or the space restarts
|
| 841 |
+
- **File System**: Hugging Face Spaces has read-only file system, so we use in-memory storage
|
| 842 |
+
- **Images**: Uploaded images are converted to base64 and stored in memory
|
| 843 |
+
- **Export**: Use the export/backup features to save your data locally
|
| 844 |
+
- **Session Sharing**: Each user has their own independent session and data
|
| 845 |
+
|
| 846 |
+
**For Production Use**: Consider integrating with a database service or cloud storage for persistent data storage.
|
| 847 |
+
""")
|
| 848 |
+
|
| 849 |
+
# --- Debug Information (Optional) ---
|
| 850 |
+
if st.sidebar.checkbox("Show Debug Info"):
|
| 851 |
+
st.sidebar.markdown("---")
|
| 852 |
+
st.sidebar.subheader("🔧 Debug Info")
|
| 853 |
+
st.sidebar.write(f"Session recipes: {len(st.session_state.get('recipes', []))}")
|
| 854 |
+
st.sidebar.write(f"Session images: {len(st.session_state.get('recipe_images', {}))}")
|
| 855 |
+
st.sidebar.write(f"Current language: {st.session_state.get('language', 'en')}")
|
| 856 |
+
|
| 857 |
+
# Show session state keys
|
| 858 |
+
if st.sidebar.checkbox("Show all session keys"):
|
| 859 |
+
st.sidebar.write("Session state keys:")
|
| 860 |
+
for key in st.session_state.keys():
|
| 861 |
+
st.sidebar.caption(f"• {key}")
|