File size: 1,678 Bytes
4734ebb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
# app.py
# Hugging Face Spaces (Gradio)๋กœ ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ "์˜ค๋Š˜์˜ ํ•œ๋ผ" ๋ฐ๋ชจ ์•ฑ
# - ๊ธฐ๋ถ„/์„ ํ˜ธ/์ œ์•ฝ/์กฐ๋ฆฌ์‹œ๊ฐ„/๋‚œ์ด๋„/์นผ๋กœ๋ฆฌ ๋ชฉํ‘œ/๋ณด์œ  ์žฌ๋ฃŒ ๋“ฑ์„ ์ž…๋ ฅ
# - ์Šค์ฝ”์–ด๋ง ๊ธฐ๋ฐ˜ ๋ ˆ์‹œํ”ผ ์ถ”์ฒœ + ์˜์–‘/์›๊ฐ€ ์ถ”์ • + ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ

import gradio as gr
from dataclasses import dataclass
from typing import List, Dict

@dataclass
class Recipe:
    name: str
    mood: List[str]
    diet: List[str]
    allergens: List[str]
    cook_time: int
    calories: int

RECIPES = [
    Recipe("๊น€์น˜๋ณถ์Œ๋ฐฅ", ["ํ”ผ๊ณค", "๋ฐ”์จ"], ["ํ•œ์‹"], ["๊ณ„๋ž€"], 12, 580),
    Recipe("์น˜ํ‚จ์ƒ๋Ÿฌ๋“œ", ["์ƒ์พŒ"], ["๊ณ ๋‹จ๋ฐฑ", "์ €ํƒ„"], ["์šฐ์œ "], 15, 350),
]

def recommend(mood, diet, allergens, max_time):
    recs = []
    for r in RECIPES:
        if any(a in r.allergens for a in allergens):
            continue
        if r.cook_time > max_time:
            continue
        score = len(set(mood) & set(r.mood)) + len(set(diet) & set(r.diet))
        recs.append((score, r))
    recs.sort(reverse=True, key=lambda x: x[0])
    return [r.name for _, r in recs[:3]] or ["์กฐ๊ฑด์— ๋งž๋Š” ๋ ˆ์‹œํ”ผ ์—†์Œ"]

demo = gr.Interface(
    fn=recommend,
    inputs=[
        gr.CheckboxGroup(["ํ”ผ๊ณค", "๋ฐ”์จ", "์ƒ์พŒ"], label="์˜ค๋Š˜์˜ ๊ธฐ๋ถ„"),
        gr.CheckboxGroup(["ํ•œ์‹", "๊ณ ๋‹จ๋ฐฑ", "์ €ํƒ„"], label="์‹๋‹จ/์Šคํƒ€์ผ"),
        gr.CheckboxGroup(["๊ณ„๋ž€", "์šฐ์œ "], label="ํ”ผํ•  ์•Œ๋ ˆ๋ฅด๊ฒ"),
        gr.Slider(5, 60, value=20, step=5, label="์ตœ๋Œ€ ์กฐ๋ฆฌ์‹œ๊ฐ„(๋ถ„)")
    ],
    outputs=gr.Textbox(label="์ถ”์ฒœ ๋ ˆ์‹œํ”ผ"),
    title="์˜ค๋Š˜์˜ ํ•œ๋ผ - ๊ฐ„๋‹จ ๋ฐ๋ชจ",
)

if __name__ == "__main__":
    demo.launch()