coldrnan commited on
Commit
4734ebb
ยท
verified ยท
1 Parent(s): 980da08

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ # Hugging Face Spaces (Gradio)๋กœ ๋ฐฐํฌ ๊ฐ€๋Šฅํ•œ "์˜ค๋Š˜์˜ ํ•œ๋ผ" ๋ฐ๋ชจ ์•ฑ
3
+ # - ๊ธฐ๋ถ„/์„ ํ˜ธ/์ œ์•ฝ/์กฐ๋ฆฌ์‹œ๊ฐ„/๋‚œ์ด๋„/์นผ๋กœ๋ฆฌ ๋ชฉํ‘œ/๋ณด์œ  ์žฌ๋ฃŒ ๋“ฑ์„ ์ž…๋ ฅ
4
+ # - ์Šค์ฝ”์–ด๋ง ๊ธฐ๋ฐ˜ ๋ ˆ์‹œํ”ผ ์ถ”์ฒœ + ์˜์–‘/์›๊ฐ€ ์ถ”์ • + ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
5
+
6
+ import gradio as gr
7
+ from dataclasses import dataclass
8
+ from typing import List, Dict
9
+
10
+ @dataclass
11
+ class Recipe:
12
+ name: str
13
+ mood: List[str]
14
+ diet: List[str]
15
+ allergens: List[str]
16
+ cook_time: int
17
+ calories: int
18
+
19
+ RECIPES = [
20
+ Recipe("๊น€์น˜๋ณถ์Œ๋ฐฅ", ["ํ”ผ๊ณค", "๋ฐ”์จ"], ["ํ•œ์‹"], ["๊ณ„๋ž€"], 12, 580),
21
+ Recipe("์น˜ํ‚จ์ƒ๋Ÿฌ๋“œ", ["์ƒ์พŒ"], ["๊ณ ๋‹จ๋ฐฑ", "์ €ํƒ„"], ["์šฐ์œ "], 15, 350),
22
+ ]
23
+
24
+ def recommend(mood, diet, allergens, max_time):
25
+ recs = []
26
+ for r in RECIPES:
27
+ if any(a in r.allergens for a in allergens):
28
+ continue
29
+ if r.cook_time > max_time:
30
+ continue
31
+ score = len(set(mood) & set(r.mood)) + len(set(diet) & set(r.diet))
32
+ recs.append((score, r))
33
+ recs.sort(reverse=True, key=lambda x: x[0])
34
+ return [r.name for _, r in recs[:3]] or ["์กฐ๊ฑด์— ๋งž๋Š” ๋ ˆ์‹œํ”ผ ์—†์Œ"]
35
+
36
+ demo = gr.Interface(
37
+ fn=recommend,
38
+ inputs=[
39
+ gr.CheckboxGroup(["ํ”ผ๊ณค", "๋ฐ”์จ", "์ƒ์พŒ"], label="์˜ค๋Š˜์˜ ๊ธฐ๋ถ„"),
40
+ gr.CheckboxGroup(["ํ•œ์‹", "๊ณ ๋‹จ๋ฐฑ", "์ €ํƒ„"], label="์‹๋‹จ/์Šคํƒ€์ผ"),
41
+ gr.CheckboxGroup(["๊ณ„๋ž€", "์šฐ์œ "], label="ํ”ผํ•  ์•Œ๋ ˆ๋ฅด๊ฒ"),
42
+ gr.Slider(5, 60, value=20, step=5, label="์ตœ๋Œ€ ์กฐ๋ฆฌ์‹œ๊ฐ„(๋ถ„)")
43
+ ],
44
+ outputs=gr.Textbox(label="์ถ”์ฒœ ๋ ˆ์‹œํ”ผ"),
45
+ title="์˜ค๋Š˜์˜ ํ•œ๋ผ - ๊ฐ„๋‹จ ๋ฐ๋ชจ",
46
+ )
47
+
48
+ if __name__ == "__main__":
49
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=4.40.0