Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| from typing import Literal | |
| # Keep classification lightweight and deployment-safe. | |
| # The earlier notebook used BERT Q&A plus keyword fallback, but the Space was | |
| # failing on missing torch. This version keeps the same outward behavior | |
| # (baked vs. cooked) using the keyword fallback only. | |
| BAKE_KEYWORDS = [ | |
| "bake", "baking", "oven", "preheat", "flour", "dough", "batter", | |
| "cake", "cookie", "muffin", "bread", "pastry", "brownie", "tart", | |
| "pie", "scone", "loaf", "whisk", "fold in", "sift", "knead", | |
| "leavening", "baking soda", "baking powder", "yeast" | |
| ] | |
| COOK_KEYWORDS = [ | |
| "saute", "sauté", "fry", "boil", "simmer", "stir", "grill", | |
| "roast", "steam", "poach", "braise", "sear", "stove", "skillet", | |
| "pan", "wok", "sauce", "soup", "stew", "marinate" | |
| ] | |
| def classify_recipe(recipe_text: str) -> Literal["baked", "cooked"]: | |
| text = (recipe_text or "").lower() | |
| bake_score = sum(1 for kw in BAKE_KEYWORDS if kw in text) | |
| cook_score = sum(1 for kw in COOK_KEYWORDS if kw in text) | |
| return "baked" if bake_score > cook_score else "cooked" | |
| def answer_question(question: str, paragraph: str) -> str: | |
| """Compatibility stub for older code paths. | |
| The original MVP used a BERT QA answer here. For deployment stability, we | |
| keep the function name but return a conservative empty answer. | |
| """ | |
| return "" | |
| def classify_recipe_type(recipe_text: str) -> str: | |
| """Alias for any older imports that expect a different helper name.""" | |
| return classify_recipe(recipe_text) | |