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()
|