File size: 1,556 Bytes
9373226
 
 
 
2e9071b
 
 
 
9373226
 
 
 
 
2e9071b
9373226
2e9071b
9373226
 
 
2e9071b
9373226
 
 
2e9071b
 
9373226
 
 
 
2e9071b
 
 
 
 
9373226
2e9071b
 
 
 
9373226
 
2e9071b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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)