Spaces:
Running
Running
Update app/services/extraction.py
Browse files- app/services/extraction.py +66 -242
app/services/extraction.py
CHANGED
|
@@ -269,6 +269,7 @@ From the given text, identify:
|
|
| 269 |
- **category**: The main name or type of the recipe (like "chicken", "ice cream").
|
| 270 |
- **calories**: Number of calories, if mentioned.
|
| 271 |
- **time**: Time to cook, in minutes.
|
|
|
|
| 272 |
- **keywords**: Important words related to the recipe. If the category is not common (like "noodles" or "biryani"), include relevant characteristics (e.g., "asian", "main course", "stir fry", "quick meal", "wheat based", "high protein", etc).
|
| 273 |
- **keywords_name**: List of individual words from the category/name. For uncommon categories, include descriptive terms and related categories (e.g., for "noodles": ["asian", "pasta", "wheat", "main dish"]).
|
| 274 |
|
|
@@ -279,6 +280,7 @@ Output: {{
|
|
| 279 |
"category": "",
|
| 280 |
"calories": "",
|
| 281 |
"time": "",
|
|
|
|
| 282 |
"keywords": ["asian", "stir fry", "wheat based", "quick meal", "main course", "pasta", "noodles"],
|
| 283 |
"keywords_name": ["asian", "pasta", "main dish", "wheat"]
|
| 284 |
}}
|
|
@@ -289,248 +291,42 @@ Output: {{
|
|
| 289 |
"category": "",
|
| 290 |
"calories": "",
|
| 291 |
"time": "",
|
|
|
|
| 292 |
"keywords": ["rice", "indian", "spicy", "main course", "one dish meal", "biryani"],
|
| 293 |
"keywords_name": ["rice", "indian", "spicy"]
|
| 294 |
}}
|
| 295 |
|
| 296 |
-
---
|
| 297 |
-
Input: "sushi"
|
| 298 |
-
Output: {{
|
| 299 |
-
"category": "",
|
| 300 |
-
"calories": "",
|
| 301 |
-
"time": "",
|
| 302 |
-
"keywords": ["japanese", "rice", "seafood", "whitefish", "snack", "main course", "sushi"],
|
| 303 |
-
"keywords_name": ["japanese", "seafood", "rice"]
|
| 304 |
-
}}
|
| 305 |
-
|
| 306 |
-
---
|
| 307 |
-
Input: "vegetable curry"
|
| 308 |
-
Output: {{
|
| 309 |
-
"category": "",
|
| 310 |
-
"calories": "",
|
| 311 |
-
"time": "",
|
| 312 |
-
"keywords": ["vegan", "vegetarian", "spicy", "main course", "curry", "indian"],
|
| 313 |
-
"keywords_name": ["indian", "vegetarian", "spicy"]
|
| 314 |
-
}}
|
| 315 |
-
|
| 316 |
-
---
|
| 317 |
-
Input: "quinoa salad"
|
| 318 |
-
Output: {{
|
| 319 |
-
"category": "salad dressings",
|
| 320 |
-
"calories": "",
|
| 321 |
-
"time": "",
|
| 322 |
-
"keywords": ["healthy", "salad", "gluten-free", "fiber", "low calorie", "vegan"],
|
| 323 |
-
"keywords_name": ["healthy", "salad", "vegan"]
|
| 324 |
-
}}
|
| 325 |
-
|
| 326 |
-
---
|
| 327 |
-
Input: "beef tacos"
|
| 328 |
-
Output: {{
|
| 329 |
-
"category": "beef organ meats",
|
| 330 |
-
"calories": "",
|
| 331 |
-
"time": "",
|
| 332 |
-
"keywords": ["mexican", "beef", "spicy", "snack", "tortilla", "street food"],
|
| 333 |
-
"keywords_name": ["mexican", "beef", "snack"]
|
| 334 |
-
}}
|
| 335 |
-
|
| 336 |
-
---
|
| 337 |
-
Input: "caesar salad"
|
| 338 |
-
Output: {{
|
| 339 |
-
"category": "salad dressings",
|
| 340 |
-
"calories": "",
|
| 341 |
-
"time": "",
|
| 342 |
-
"keywords": ["salad", "appetizer", "healthy", "vegetables", "parmesan", "croutons"],
|
| 343 |
-
"keywords_name": ["salad", "appetizer", "healthy"]
|
| 344 |
-
}}
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
---
|
| 348 |
-
Input: "smoothie bowl"
|
| 349 |
-
Output: {{
|
| 350 |
-
"category": "smoothies",
|
| 351 |
-
"calories": "",
|
| 352 |
-
"time": "",
|
| 353 |
-
"keywords": ["breakfast", "healthy", "fruits", "smoothies", "vegan", "fiber"],
|
| 354 |
-
"keywords_name": ["breakfast", "healthy", "fruits"]
|
| 355 |
-
}}
|
| 356 |
-
|
| 357 |
-
Input: "spaghetti bolognese"
|
| 358 |
-
Output: {{
|
| 359 |
-
"category": "spaghetti",
|
| 360 |
-
"calories": "",
|
| 361 |
-
"time": "",
|
| 362 |
-
"keywords": ["italian", "pasta", "meat", "tomato", "main course", "hearty"],
|
| 363 |
-
"keywords_name": ["italian", "pasta", "meat"]
|
| 364 |
-
}}
|
| 365 |
-
|
| 366 |
---
|
| 367 |
Input: "I wish to cook chicken soup which contains around 200 calories within 30 mins"
|
| 368 |
Output: {{
|
| 369 |
"category": "chicken",
|
| 370 |
"calories": "200",
|
| 371 |
"time": "30",
|
|
|
|
| 372 |
"keywords": ["chicken", "soup", "200 calories", "30 mins"],
|
| 373 |
"keywords_name": ["chicken", "soup"]
|
| 374 |
}}
|
| 375 |
|
| 376 |
---
|
| 377 |
-
Input: "
|
| 378 |
-
Output: {{
|
| 379 |
-
"category": "pasta shells",
|
| 380 |
-
"calories": "500",
|
| 381 |
-
"time": "20",
|
| 382 |
-
"keywords": ["pasta shells", "500 calories", "20 mins"],
|
| 383 |
-
"keywords_name": ["pasta shells"]
|
| 384 |
-
}}
|
| 385 |
-
|
| 386 |
-
---
|
| 387 |
-
Input: "uh i wish to cook something which contains protein"
|
| 388 |
-
Output: {{
|
| 389 |
-
"category": "low protein",
|
| 390 |
-
"calories": "",
|
| 391 |
-
"time": "",
|
| 392 |
-
"keywords": ["low protein", "high protein", "protein"],
|
| 393 |
-
"keywords_name": ["low protein"]
|
| 394 |
-
}}
|
| 395 |
-
|
| 396 |
-
---
|
| 397 |
-
Input: "can you suggest something with low calories"
|
| 398 |
-
Output: {{
|
| 399 |
-
"category": "",
|
| 400 |
-
"calories": "",
|
| 401 |
-
"time": "",
|
| 402 |
-
"keywords": ["low calories"],
|
| 403 |
-
"keywords_name": ["low", "calories"]
|
| 404 |
-
}}
|
| 405 |
-
|
| 406 |
-
---
|
| 407 |
-
Input: "looking for a vegetarian recipe"
|
| 408 |
-
Output: {{
|
| 409 |
-
"category": "",
|
| 410 |
-
"calories": "",
|
| 411 |
-
"time": "",
|
| 412 |
-
"keywords": ["vegetarian", "vegan"],
|
| 413 |
-
"keywords_name": ["vegetarian"]
|
| 414 |
-
}}
|
| 415 |
-
|
| 416 |
-
---
|
| 417 |
-
Input: "need something gluten free"
|
| 418 |
-
Output: {{
|
| 419 |
-
"category": "",
|
| 420 |
-
"calories": "",
|
| 421 |
-
"time": "",
|
| 422 |
-
"keywords": ["gluten free"],
|
| 423 |
-
"keywords_name": ["gluten", "free"]
|
| 424 |
-
}}
|
| 425 |
-
|
| 426 |
-
---
|
| 427 |
-
Input: "want to make something dairy free"
|
| 428 |
-
Output: {{
|
| 429 |
-
"category": "",
|
| 430 |
-
"calories": "",
|
| 431 |
-
"time": "",
|
| 432 |
-
"keywords": ["dairy free", "vegan"],
|
| 433 |
-
"keywords_name": ["dairy", "free"]
|
| 434 |
-
}}
|
| 435 |
-
|
| 436 |
-
---
|
| 437 |
-
Input: "what can i cook for dinner"
|
| 438 |
-
Output: {{
|
| 439 |
-
"category": "",
|
| 440 |
-
"calories": "",
|
| 441 |
-
"time": "",
|
| 442 |
-
"keywords": ["dinner", "vegan"],
|
| 443 |
-
"keywords_name": [""]
|
| 444 |
-
}}
|
| 445 |
-
|
| 446 |
-
---
|
| 447 |
-
Input: "what can i cook for breakfast"
|
| 448 |
-
Output: {{
|
| 449 |
-
"category": "",
|
| 450 |
-
"calories": "",
|
| 451 |
-
"time": "",
|
| 452 |
-
"keywords": ["breakfast", "vegan"],
|
| 453 |
-
"keywords_name": [""]
|
| 454 |
-
}}
|
| 455 |
-
|
| 456 |
-
---
|
| 457 |
-
Input: "what can i cook for lunch"
|
| 458 |
-
Output: {{
|
| 459 |
-
"category": "",
|
| 460 |
-
"calories": "",
|
| 461 |
-
"time": "",
|
| 462 |
-
"keywords": ["lunch", "quick meal", "vegan"],
|
| 463 |
-
"keywords_name": [""]
|
| 464 |
-
}}
|
| 465 |
-
|
| 466 |
-
---
|
| 467 |
-
Input: "something with low carbs"
|
| 468 |
-
Output: {{
|
| 469 |
-
"category": "very low carbs",
|
| 470 |
-
"calories": "",
|
| 471 |
-
"time": "",
|
| 472 |
-
"keywords": ["very low carbs", "low carbs", "carbs"],
|
| 473 |
-
"keywords_name": ["low", "carbs"]
|
| 474 |
-
}}
|
| 475 |
-
|
| 476 |
-
---
|
| 477 |
-
Input: "i wish to cook something in 30 minutes"
|
| 478 |
-
Output: {{
|
| 479 |
-
"category": "",
|
| 480 |
-
"calories": "",
|
| 481 |
-
"time": "30",
|
| 482 |
-
"keywords": ["30 minutes", "quick meal"],
|
| 483 |
-
"keywords_name": [""]
|
| 484 |
-
}}
|
| 485 |
-
|
| 486 |
-
---
|
| 487 |
-
Input: "I wish to make fish and stew"
|
| 488 |
-
Output: {{
|
| 489 |
-
"category": "stew",
|
| 490 |
-
"calories": "",
|
| 491 |
-
"time": "",
|
| 492 |
-
"keywords": ["fish", "stew", "high protein"],
|
| 493 |
-
"keywords_name": ["fish", "stew"]
|
| 494 |
-
}}
|
| 495 |
-
|
| 496 |
-
---
|
| 497 |
-
Input: "I wish to make fish and stew"
|
| 498 |
Output: {{
|
| 499 |
-
"category": "
|
| 500 |
"calories": "",
|
| 501 |
"time": "",
|
| 502 |
-
"
|
| 503 |
-
"
|
|
|
|
| 504 |
}}
|
| 505 |
|
| 506 |
---
|
| 507 |
-
Input: "
|
| 508 |
Output: {{
|
| 509 |
-
"category": "
|
| 510 |
"calories": "",
|
| 511 |
"time": "",
|
| 512 |
-
"
|
| 513 |
-
"
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
---
|
| 517 |
-
Input: "I wish to make fish and stew"
|
| 518 |
-
Output: {{
|
| 519 |
-
"category": "crawfish",
|
| 520 |
-
"calories": "",
|
| 521 |
-
"time": "",
|
| 522 |
-
"keywords": ["fish", "stew", "high protein"],
|
| 523 |
-
"keywords_name": ["fish", "stew"]
|
| 524 |
-
}}
|
| 525 |
-
|
| 526 |
-
---
|
| 527 |
-
Input: "give some recipes involving almonds or dry fruits"
|
| 528 |
-
Output: {{
|
| 529 |
-
"category": "",
|
| 530 |
-
"calories": "",
|
| 531 |
-
"time": "",
|
| 532 |
-
"keywords": ["almonds", "dry fruits"],
|
| 533 |
-
"keywords_name": ["almonds", "dry fruits"]
|
| 534 |
}}
|
| 535 |
|
| 536 |
---
|
|
@@ -539,30 +335,22 @@ Output: {{
|
|
| 539 |
"category": "",
|
| 540 |
"calories": "",
|
| 541 |
"time": "",
|
|
|
|
| 542 |
"keywords": ["milk", "sugar", "water", "beverages"],
|
| 543 |
"keywords_name": [""]
|
| 544 |
}}
|
| 545 |
|
| 546 |
---
|
| 547 |
-
Input: "
|
| 548 |
Output: {{
|
| 549 |
"category": "",
|
| 550 |
"calories": "",
|
| 551 |
-
"time": "",
|
| 552 |
-
"
|
| 553 |
-
"
|
|
|
|
| 554 |
}}
|
| 555 |
|
| 556 |
-
---
|
| 557 |
-
Input: "something involving nuts"
|
| 558 |
-
Output: {{
|
| 559 |
-
"category": "nuts",
|
| 560 |
-
"calories": "",
|
| 561 |
-
"time": "",
|
| 562 |
-
"keywords": ["nuts", "snack", "healthy", "protein", "fiber"],
|
| 563 |
-
"keywords_name": ["nuts", "snack", "healthy"]
|
| 564 |
-
}}
|
| 565 |
-
|
| 566 |
---
|
| 567 |
Now process this input:
|
| 568 |
Input: "{text}"
|
|
@@ -591,74 +379,107 @@ Output:
|
|
| 591 |
matched_category = find_closest_category(original_category)
|
| 592 |
|
| 593 |
if matched_category:
|
| 594 |
-
# If we found a match (exact or close), update category and keywords_name
|
| 595 |
result["category"] = matched_category
|
| 596 |
if original_category != matched_category:
|
| 597 |
result["keywords_name"] = matched_category.split()
|
| 598 |
else:
|
| 599 |
result["category"] = ""
|
| 600 |
-
# Add additional context-based keywords if category is empty
|
| 601 |
if "coffee" in text.lower() or "latte" in text.lower():
|
| 602 |
result["keywords"] = result.get("keywords", []) + ["coffee", "beverages", "caffeinated", "hot drink"]
|
| 603 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "caffeinated", "coffee"]
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "espresso"]
|
| 607 |
elif "smoothie bowl" in text.lower():
|
| 608 |
result["keywords"] = result.get("keywords", []) + ["beverages", "healthy", "smoothie bowl"]
|
| 609 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "smoothie bowl"]
|
|
|
|
|
|
|
| 610 |
elif "kombucha" in text.lower():
|
| 611 |
result["keywords"] = result.get("keywords", []) + ["beverage", "fermented", "kombucha"]
|
| 612 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "kombucha"]
|
|
|
|
|
|
|
| 613 |
elif "herbal tea" in text.lower():
|
| 614 |
result["keywords"] = result.get("keywords", []) + ["beverages", "caffeine-free", "herbal tea"]
|
| 615 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "herbal tea"]
|
|
|
|
|
|
|
| 616 |
elif "seaweed" in text.lower():
|
| 617 |
result["keywords"] = result.get("keywords", []) + ["ingredient", "seafood", "seaweed"]
|
| 618 |
result["keywords_name"] = result.get("keywords_name", []) + ["seaweed"]
|
|
|
|
|
|
|
| 619 |
elif "vegan cheese" in text.lower():
|
| 620 |
result["keywords"] = result.get("keywords", []) + ["dairy-free", "vegan", "cheese"]
|
| 621 |
result["keywords_name"] = result.get("keywords_name", []) + ["vegan cheese"]
|
|
|
|
|
|
|
| 622 |
elif "air fryer" in text.lower():
|
| 623 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "air fryer", "healthy"]
|
| 624 |
result["keywords_name"] = result.get("keywords_name", []) + ["air fryer"]
|
|
|
|
|
|
|
| 625 |
elif "instant pot" in text.lower():
|
| 626 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "instant pot", "pressure cooker"]
|
| 627 |
result["keywords_name"] = result.get("keywords_name", []) + ["instant pot"]
|
|
|
|
|
|
|
| 628 |
elif "sous vide" in text.lower():
|
| 629 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "sous vide", "precision cooking"]
|
| 630 |
result["keywords_name"] = result.get("keywords_name", []) + ["sous vide"]
|
|
|
|
|
|
|
| 631 |
elif "paleo" in text.lower():
|
| 632 |
result["keywords"] = result.get("keywords", []) + ["diet", "paleo", "low-carb"]
|
| 633 |
result["keywords_name"] = result.get("keywords_name", []) + ["paleo"]
|
|
|
|
|
|
|
| 634 |
elif "fodmap" in text.lower():
|
| 635 |
result["keywords"] = result.get("keywords", []) + ["diet", "fodmap", "digestive health"]
|
| 636 |
result["keywords_name"] = result.get("keywords_name", []) + ["fodmap"]
|
|
|
|
|
|
|
| 637 |
elif "cold brew" in text.lower():
|
| 638 |
result["keywords"] = result.get("keywords", []) + ["beverages", "caffeinated", "cold coffee"]
|
| 639 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "cold brew"]
|
|
|
|
|
|
|
| 640 |
elif "matcha" in text.lower():
|
| 641 |
result["keywords"] = result.get("keywords", []) + ["beverages", "green tea", "matcha"]
|
| 642 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "matcha"]
|
|
|
|
|
|
|
| 643 |
elif "smoothie" in text.lower():
|
| 644 |
result["keywords"] = result.get("keywords", []) + ["beverages", "healthy", "smoothie"]
|
| 645 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "smoothie"]
|
|
|
|
|
|
|
| 646 |
elif "protein shake" in text.lower():
|
| 647 |
result["keywords"] = result.get("keywords", []) + ["beverages", "high protein", "shake"]
|
| 648 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "protein shake"]
|
|
|
|
|
|
|
| 649 |
elif "oat milk" in text.lower() or "almond milk" in text.lower():
|
| 650 |
result["keywords"] = result.get("keywords", []) + ["dairy-free", "vegan", "plant-based milk"]
|
| 651 |
result["keywords_name"] = result.get("keywords_name", []) + ["oat milk" if "oat" in text.lower() else "almond milk"]
|
|
|
|
|
|
|
| 652 |
elif "zoodles" in text.lower():
|
| 653 |
result["keywords"] = result.get("keywords", []) + ["low carb", "gluten-free", "vegetable noodles", "noodles"]
|
| 654 |
result["keywords_name"] = result.get("keywords_name", []) + ["zoodles", "noodles"]
|
|
|
|
|
|
|
| 655 |
elif "avocado toast" in text.lower():
|
| 656 |
result["keywords"] = result.get("keywords", []) + ["breakfast", "healthy", "avocado"]
|
| 657 |
result["keywords_name"] = result.get("keywords_name", []) + ["avocado toast"]
|
|
|
|
|
|
|
| 658 |
elif "golden milk" in text.lower():
|
| 659 |
result["keywords"] = result.get("keywords", []) + ["beverage", "turmeric", "anti-inflammatory"]
|
| 660 |
result["keywords_name"] = result.get("keywords_name", []) + ["golden milk"]
|
| 661 |
-
|
|
|
|
| 662 |
|
| 663 |
except json.JSONDecodeError:
|
| 664 |
result = {"error": "Failed to parse JSON", "output": output_text}
|
|
@@ -668,7 +489,12 @@ Output:
|
|
| 668 |
# Example usage:
|
| 669 |
if __name__ == '__main__':
|
| 670 |
test_cases = [
|
| 671 |
-
# "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 672 |
# "need a pasta recipe",
|
| 673 |
# "looking for a chicken dish",
|
| 674 |
# "want to make something with rice",
|
|
@@ -691,11 +517,9 @@ if __name__ == '__main__':
|
|
| 691 |
# "chocolate, brownie, cake, brown sugar",
|
| 692 |
# "avocado smoothie, avocado, milk, ice",
|
| 693 |
# "momo, momo, sauce",
|
| 694 |
-
# "I have basil, tomato and clove what can i make in 30 minutes",
|
| 695 |
-
"basil"
|
| 696 |
]
|
| 697 |
|
| 698 |
for test_input in test_cases:
|
| 699 |
print(f"\nTesting: {test_input}")
|
| 700 |
result = extract_recipe_attributes(test_input)
|
| 701 |
-
print(json.dumps(result, indent=2))
|
|
|
|
| 269 |
- **category**: The main name or type of the recipe (like "chicken", "ice cream").
|
| 270 |
- **calories**: Number of calories, if mentioned.
|
| 271 |
- **time**: Time to cook, in minutes.
|
| 272 |
+
- **ingredients**: List of ingredients mentioned in the text. Include basic cooking ingredients even if not explicitly mentioned (e.g., if it's a cake, include "flour", "sugar" as basic ingredients).
|
| 273 |
- **keywords**: Important words related to the recipe. If the category is not common (like "noodles" or "biryani"), include relevant characteristics (e.g., "asian", "main course", "stir fry", "quick meal", "wheat based", "high protein", etc).
|
| 274 |
- **keywords_name**: List of individual words from the category/name. For uncommon categories, include descriptive terms and related categories (e.g., for "noodles": ["asian", "pasta", "wheat", "main dish"]).
|
| 275 |
|
|
|
|
| 280 |
"category": "",
|
| 281 |
"calories": "",
|
| 282 |
"time": "",
|
| 283 |
+
"ingredients": ["noodles", "oil", "salt"],
|
| 284 |
"keywords": ["asian", "stir fry", "wheat based", "quick meal", "main course", "pasta", "noodles"],
|
| 285 |
"keywords_name": ["asian", "pasta", "main dish", "wheat"]
|
| 286 |
}}
|
|
|
|
| 291 |
"category": "",
|
| 292 |
"calories": "",
|
| 293 |
"time": "",
|
| 294 |
+
"ingredients": ["rice", "spices", "oil", "onions", "garlic"],
|
| 295 |
"keywords": ["rice", "indian", "spicy", "main course", "one dish meal", "biryani"],
|
| 296 |
"keywords_name": ["rice", "indian", "spicy"]
|
| 297 |
}}
|
| 298 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
---
|
| 300 |
Input: "I wish to cook chicken soup which contains around 200 calories within 30 mins"
|
| 301 |
Output: {{
|
| 302 |
"category": "chicken",
|
| 303 |
"calories": "200",
|
| 304 |
"time": "30",
|
| 305 |
+
"ingredients": ["chicken", "water", "vegetables", "salt", "pepper"],
|
| 306 |
"keywords": ["chicken", "soup", "200 calories", "30 mins"],
|
| 307 |
"keywords_name": ["chicken", "soup"]
|
| 308 |
}}
|
| 309 |
|
| 310 |
---
|
| 311 |
+
Input: "beef tacos"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
Output: {{
|
| 313 |
+
"category": "beef organ meats",
|
| 314 |
"calories": "",
|
| 315 |
"time": "",
|
| 316 |
+
"ingredients": ["beef", "tortillas", "lettuce", "tomatoes", "cheese", "onions"],
|
| 317 |
+
"keywords": ["mexican", "beef", "spicy", "snack", "tortilla", "street food"],
|
| 318 |
+
"keywords_name": ["mexican", "beef", "snack"]
|
| 319 |
}}
|
| 320 |
|
| 321 |
---
|
| 322 |
+
Input: "chocolate cake with milk and sugar"
|
| 323 |
Output: {{
|
| 324 |
+
"category": "dessert",
|
| 325 |
"calories": "",
|
| 326 |
"time": "",
|
| 327 |
+
"ingredients": ["chocolate", "milk", "sugar", "flour", "eggs", "butter"],
|
| 328 |
+
"keywords": ["dessert", "baking", "sweet", "cake"],
|
| 329 |
+
"keywords_name": ["dessert", "cake", "chocolate"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 330 |
}}
|
| 331 |
|
| 332 |
---
|
|
|
|
| 335 |
"category": "",
|
| 336 |
"calories": "",
|
| 337 |
"time": "",
|
| 338 |
+
"ingredients": ["tea", "milk", "sugar", "water"],
|
| 339 |
"keywords": ["milk", "sugar", "water", "beverages"],
|
| 340 |
"keywords_name": [""]
|
| 341 |
}}
|
| 342 |
|
| 343 |
---
|
| 344 |
+
Input: "I have basil, tomato and clove what can i make in 30 minutes"
|
| 345 |
Output: {{
|
| 346 |
"category": "",
|
| 347 |
"calories": "",
|
| 348 |
+
"time": "30",
|
| 349 |
+
"ingredients": ["basil", "tomato", "clove"],
|
| 350 |
+
"keywords": ["quick meal", "30 minutes", "italian"],
|
| 351 |
+
"keywords_name": [""]
|
| 352 |
}}
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
---
|
| 355 |
Now process this input:
|
| 356 |
Input: "{text}"
|
|
|
|
| 379 |
matched_category = find_closest_category(original_category)
|
| 380 |
|
| 381 |
if matched_category:
|
|
|
|
| 382 |
result["category"] = matched_category
|
| 383 |
if original_category != matched_category:
|
| 384 |
result["keywords_name"] = matched_category.split()
|
| 385 |
else:
|
| 386 |
result["category"] = ""
|
| 387 |
+
# Add additional context-based keywords and ingredients if category is empty
|
| 388 |
if "coffee" in text.lower() or "latte" in text.lower():
|
| 389 |
result["keywords"] = result.get("keywords", []) + ["coffee", "beverages", "caffeinated", "hot drink"]
|
| 390 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "caffeinated", "coffee"]
|
| 391 |
+
result["ingredients"] = result.get("ingredients", []) + ["coffee beans", "water"]
|
| 392 |
+
|
|
|
|
| 393 |
elif "smoothie bowl" in text.lower():
|
| 394 |
result["keywords"] = result.get("keywords", []) + ["beverages", "healthy", "smoothie bowl"]
|
| 395 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "smoothie bowl"]
|
| 396 |
+
result["ingredients"] = result.get("ingredients", []) + ["fruits", "yogurt", "granola"]
|
| 397 |
+
|
| 398 |
elif "kombucha" in text.lower():
|
| 399 |
result["keywords"] = result.get("keywords", []) + ["beverage", "fermented", "kombucha"]
|
| 400 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "kombucha"]
|
| 401 |
+
result["ingredients"] = result.get("ingredients", []) + ["tea", "sugar", "SCOBY"]
|
| 402 |
+
|
| 403 |
elif "herbal tea" in text.lower():
|
| 404 |
result["keywords"] = result.get("keywords", []) + ["beverages", "caffeine-free", "herbal tea"]
|
| 405 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "herbal tea"]
|
| 406 |
+
result["ingredients"] = result.get("ingredients", []) + ["herbs", "water"]
|
| 407 |
+
|
| 408 |
elif "seaweed" in text.lower():
|
| 409 |
result["keywords"] = result.get("keywords", []) + ["ingredient", "seafood", "seaweed"]
|
| 410 |
result["keywords_name"] = result.get("keywords_name", []) + ["seaweed"]
|
| 411 |
+
result["ingredients"] = result.get("ingredients", []) + ["seaweed"]
|
| 412 |
+
|
| 413 |
elif "vegan cheese" in text.lower():
|
| 414 |
result["keywords"] = result.get("keywords", []) + ["dairy-free", "vegan", "cheese"]
|
| 415 |
result["keywords_name"] = result.get("keywords_name", []) + ["vegan cheese"]
|
| 416 |
+
result["ingredients"] = result.get("ingredients", []) + ["cashews", "nutritional yeast", "coconut oil"]
|
| 417 |
+
|
| 418 |
elif "air fryer" in text.lower():
|
| 419 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "air fryer", "healthy"]
|
| 420 |
result["keywords_name"] = result.get("keywords_name", []) + ["air fryer"]
|
| 421 |
+
result["ingredients"] = result.get("ingredients", []) # Ingredients vary with recipe, left blank
|
| 422 |
+
|
| 423 |
elif "instant pot" in text.lower():
|
| 424 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "instant pot", "pressure cooker"]
|
| 425 |
result["keywords_name"] = result.get("keywords_name", []) + ["instant pot"]
|
| 426 |
+
result["ingredients"] = result.get("ingredients", []) # Ingredients vary with recipe, left blank
|
| 427 |
+
|
| 428 |
elif "sous vide" in text.lower():
|
| 429 |
result["keywords"] = result.get("keywords", []) + ["cooking method", "sous vide", "precision cooking"]
|
| 430 |
result["keywords_name"] = result.get("keywords_name", []) + ["sous vide"]
|
| 431 |
+
result["ingredients"] = result.get("ingredients", []) # Ingredients vary with recipe, left blank
|
| 432 |
+
|
| 433 |
elif "paleo" in text.lower():
|
| 434 |
result["keywords"] = result.get("keywords", []) + ["diet", "paleo", "low-carb"]
|
| 435 |
result["keywords_name"] = result.get("keywords_name", []) + ["paleo"]
|
| 436 |
+
result["ingredients"] = result.get("ingredients", []) # Ingredients vary with recipe, left blank
|
| 437 |
+
|
| 438 |
elif "fodmap" in text.lower():
|
| 439 |
result["keywords"] = result.get("keywords", []) + ["diet", "fodmap", "digestive health"]
|
| 440 |
result["keywords_name"] = result.get("keywords_name", []) + ["fodmap"]
|
| 441 |
+
result["ingredients"] = result.get("ingredients", []) # Ingredients vary with recipe, left blank
|
| 442 |
+
|
| 443 |
elif "cold brew" in text.lower():
|
| 444 |
result["keywords"] = result.get("keywords", []) + ["beverages", "caffeinated", "cold coffee"]
|
| 445 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "cold brew"]
|
| 446 |
+
result["ingredients"] = result.get("ingredients", []) + ["coffee grounds", "water"]
|
| 447 |
+
|
| 448 |
elif "matcha" in text.lower():
|
| 449 |
result["keywords"] = result.get("keywords", []) + ["beverages", "green tea", "matcha"]
|
| 450 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "matcha"]
|
| 451 |
+
result["ingredients"] = result.get("ingredients", []) + ["matcha powder", "water", "milk"]
|
| 452 |
+
|
| 453 |
elif "smoothie" in text.lower():
|
| 454 |
result["keywords"] = result.get("keywords", []) + ["beverages", "healthy", "smoothie"]
|
| 455 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "smoothie"]
|
| 456 |
+
result["ingredients"] = result.get("ingredients", []) + ["fruits", "milk", "yogurt"]
|
| 457 |
+
|
| 458 |
elif "protein shake" in text.lower():
|
| 459 |
result["keywords"] = result.get("keywords", []) + ["beverages", "high protein", "shake"]
|
| 460 |
result["keywords_name"] = result.get("keywords_name", []) + ["beverages", "protein shake"]
|
| 461 |
+
result["ingredients"] = result.get("ingredients", []) + ["protein powder", "milk", "banana"]
|
| 462 |
+
|
| 463 |
elif "oat milk" in text.lower() or "almond milk" in text.lower():
|
| 464 |
result["keywords"] = result.get("keywords", []) + ["dairy-free", "vegan", "plant-based milk"]
|
| 465 |
result["keywords_name"] = result.get("keywords_name", []) + ["oat milk" if "oat" in text.lower() else "almond milk"]
|
| 466 |
+
result["ingredients"] = result.get("ingredients", []) + ["oats" if "oat" in text.lower() else "almonds", "water"]
|
| 467 |
+
|
| 468 |
elif "zoodles" in text.lower():
|
| 469 |
result["keywords"] = result.get("keywords", []) + ["low carb", "gluten-free", "vegetable noodles", "noodles"]
|
| 470 |
result["keywords_name"] = result.get("keywords_name", []) + ["zoodles", "noodles"]
|
| 471 |
+
result["ingredients"] = result.get("ingredients", []) + ["zucchini"]
|
| 472 |
+
|
| 473 |
elif "avocado toast" in text.lower():
|
| 474 |
result["keywords"] = result.get("keywords", []) + ["breakfast", "healthy", "avocado"]
|
| 475 |
result["keywords_name"] = result.get("keywords_name", []) + ["avocado toast"]
|
| 476 |
+
result["ingredients"] = result.get("ingredients", []) + ["avocado", "bread"]
|
| 477 |
+
|
| 478 |
elif "golden milk" in text.lower():
|
| 479 |
result["keywords"] = result.get("keywords", []) + ["beverage", "turmeric", "anti-inflammatory"]
|
| 480 |
result["keywords_name"] = result.get("keywords_name", []) + ["golden milk"]
|
| 481 |
+
result["ingredients"] = result.get("ingredients", []) + ["turmeric", "milk", "honey", "spices"]
|
| 482 |
+
# other cases...
|
| 483 |
|
| 484 |
except json.JSONDecodeError:
|
| 485 |
result = {"error": "Failed to parse JSON", "output": output_text}
|
|
|
|
| 489 |
# Example usage:
|
| 490 |
if __name__ == '__main__':
|
| 491 |
test_cases = [
|
| 492 |
+
# "Something i can make with chocolate, milk and cheese",
|
| 493 |
+
# "I have basil, tomato and clove what can i make in 30 minutes",
|
| 494 |
+
# "beef stew with potatoes, carrots, and herbs",
|
| 495 |
+
# "chocolate cake with milk and sugar",
|
| 496 |
+
# "avocado smoothie with milk and ice",
|
| 497 |
+
"noodles",
|
| 498 |
# "need a pasta recipe",
|
| 499 |
# "looking for a chicken dish",
|
| 500 |
# "want to make something with rice",
|
|
|
|
| 517 |
# "chocolate, brownie, cake, brown sugar",
|
| 518 |
# "avocado smoothie, avocado, milk, ice",
|
| 519 |
# "momo, momo, sauce",
|
|
|
|
|
|
|
| 520 |
]
|
| 521 |
|
| 522 |
for test_input in test_cases:
|
| 523 |
print(f"\nTesting: {test_input}")
|
| 524 |
result = extract_recipe_attributes(test_input)
|
| 525 |
+
print(json.dumps(result, indent=2))
|