openfree commited on
Commit
b9e7deb
โ€ข
1 Parent(s): 32e6ad6

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +100 -0
app.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ recipes_db = {
4
+ "๊น€์น˜๋ณถ์Œ๋ฐฅ": {
5
+ "ingredients": ["๊น€์น˜", "๋ฐฅ", "๊ณ„๋ž€", "ํŒŒ"],
6
+ "steps": [
7
+ "1. ๊น€์น˜๋ฅผ ์ž˜๊ฒŒ ์ฐ์–ด์ฃผ์„ธ์š”.",
8
+ "2. ํŒฌ์„ ๋‹ฌ๊ตฐ ํ›„ ๊น€์น˜๋ฅผ ๋ณถ์•„์ฃผ์„ธ์š”.",
9
+ "3. ๋ฐฅ์„ ๋„ฃ๊ณ  ํ•จ๊ป˜ ๋ณถ์•„์ฃผ์„ธ์š”.",
10
+ "4. ๊ณ„๋ž€์„ ํ”„๋ผ์ดํ•ด์„œ ์˜ฌ๋ ค์ฃผ์„ธ์š”.",
11
+ "5. ์ฌ ํŒŒ๋ฅผ garnish๋กœ ์˜ฌ๋ ค์ฃผ์„ธ์š”."
12
+ ],
13
+ "difficulty": "์‰ฌ์›€",
14
+ "time": "15๋ถ„"
15
+ },
16
+ "๋œ์žฅ์ฐŒ๊ฐœ": {
17
+ "ingredients": ["๋œ์žฅ", "๋‘๋ถ€", "๊ฐ์ž", "ํŒŒ", "์–‘ํŒŒ"],
18
+ "steps": [
19
+ "1. ๋ฌผ์„ ๋“์—ฌ์ฃผ์„ธ์š”.",
20
+ "2. ๋œ์žฅ์„ ํ’€์–ด์ฃผ์„ธ์š”.",
21
+ "3. ๊ฐ์ž์™€ ์–‘ํŒŒ๋ฅผ ๋„ฃ๊ณ  ๋“์—ฌ์ฃผ์„ธ์š”.",
22
+ "4. ๋‘๋ถ€๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”.",
23
+ "5. ํŒŒ๋ฅผ ๋„ฃ๊ณ  ๋งˆ๋ฌด๋ฆฌํ•ด์ฃผ์„ธ์š”."
24
+ ],
25
+ "difficulty": "๋ณดํ†ต",
26
+ "time": "20๋ถ„"
27
+ },
28
+ "๊ณ„๋ž€๋ง์ด": {
29
+ "ingredients": ["๊ณ„๋ž€", "ํŒŒ", "๋‹น๊ทผ"],
30
+ "steps": [
31
+ "1. ๊ณ„๋ž€์„ ํ’€์–ด์ฃผ์„ธ์š”.",
32
+ "2. ์ž˜๊ฒŒ ์ฌ ํŒŒ์™€ ๋‹น๊ทผ์„ ๋„ฃ์–ด์ฃผ์„ธ์š”.",
33
+ "3. ํŒฌ์— ๊ธฐ๋ฆ„์„ ๋‘๋ฅด๊ณ  ๊ณ„๋ž€๋ฌผ์„ ๋ถ€์–ด์ฃผ์„ธ์š”.",
34
+ "4. ํ•œ์ชฝ๋ถ€ํ„ฐ ๋ง์•„๊ฐ€๋ฉฐ ์กฐ๋ฆฌํ•ด์ฃผ์„ธ์š”.",
35
+ "5. ์ ๋‹นํ•œ ํฌ๊ธฐ๋กœ ์ž˜๋ผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”."
36
+ ],
37
+ "difficulty": "์‰ฌ์›€",
38
+ "time": "10๋ถ„"
39
+ },
40
+ "๋ผ๋ฉด": {
41
+ "ingredients": ["๋ผ๋ฉด", "๊ณ„๋ž€", "ํŒŒ"],
42
+ "steps": [
43
+ "1. ๋ฌผ์„ ๋“์—ฌ์ฃผ์„ธ์š”.",
44
+ "2. ๋ผ๋ฉด๊ณผ ์Šคํ”„๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”.",
45
+ "3. ๊ณ„๋ž€์„ ๋„ฃ์–ด์ฃผ์„ธ์š”.",
46
+ "4. ์ฌ ํŒŒ๋ฅผ ๋„ฃ์–ด์ฃผ์„ธ์š”.",
47
+ "5. 2-3๋ถ„ ๋” ๋“์—ฌ ์™„์„ฑํ•ด์ฃผ์„ธ์š”."
48
+ ],
49
+ "difficulty": "์‰ฌ์›€",
50
+ "time": "5๋ถ„"
51
+ }
52
+ }
53
+ available_ingredients = sorted(list(set(
54
+ ingredient
55
+ for recipe in recipes_db.values()
56
+ for ingredient in recipe['ingredients']
57
+ )))
58
+ def find_recipes(selected_ingredients):
59
+ if not selected_ingredients:
60
+ return "์žฌ๋ฃŒ๋ฅผ ์„ ํƒํ•ด์ฃผ์„ธ์š”."
61
+ possible_recipes = []
62
+ for recipe_name, recipe_info in recipes_db.items():
63
+ required_ingredients = set(recipe_info['ingredients'])
64
+ selected_set = set(selected_ingredients)
65
+ if selected_set.intersection(required_ingredients):
66
+ match_percentage = len(selected_set.intersection(required_ingredients)) / len(required_ingredients) * 100
67
+ possible_recipes.append((recipe_name, match_percentage, recipe_info))
68
+ if not possible_recipes:
69
+ return "์„ ํƒํ•œ ์žฌ๋ฃŒ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์š”๋ฆฌ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค."
70
+ possible_recipes.sort(key=lambda x: x[1], reverse=True)
71
+ result = ""
72
+ for recipe_name, match, recipe_info in possible_recipes:
73
+ result += f"\n๐Ÿณ {recipe_name} (์žฌ๋ฃŒ ์ผ์น˜๋„: {match:.1f}%)\n"
74
+ result += f"๋‚œ์ด๋„: {recipe_info['difficulty']}\n"
75
+ result += f"์กฐ๋ฆฌ์‹œ๊ฐ„: {recipe_info['time']}\n"
76
+ result += "\nํ•„์š”ํ•œ ์žฌ๋ฃŒ:\n"
77
+ result += "โ€ข " + "\nโ€ข ".join(recipe_info['ingredients']) + "\n"
78
+ result += "\n์กฐ๋ฆฌ ๊ณผ์ •:\n"
79
+ result += "\n".join(recipe_info['steps']) + "\n"
80
+ result += "\n" + "="*50 + "\n"
81
+ return result
82
+ demo = gr.Interface(
83
+ fn=find_recipes,
84
+ inputs=gr.Checkboxgroup(
85
+ choices=available_ingredients,
86
+ label="๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์žฌ๋ฃŒ๋ฅผ ์„ ํƒํ•˜์„ธ์š”"
87
+ ),
88
+ outputs=gr.Textbox(label="์ถ”์ฒœ ์š”๋ฆฌ ๋ ˆ์‹œํ”ผ", lines=20),
89
+ title="๐Ÿฅ˜ ์š”๋ฆฌ ๋ ˆ์‹œํ”ผ ์ถ”์ฒœ",
90
+ description="๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์žฌ๋ฃŒ๋ฅผ ์„ ํƒํ•˜๋ฉด ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์š”๋ฆฌ์™€ ๋ ˆ์‹œํ”ผ๋ฅผ ์ถ”์ฒœํ•ด๋“œ๋ฆฝ๋‹ˆ๋‹ค.",
91
+ theme="soft",
92
+ examples=[
93
+ [["๊น€์น˜", "๋ฐฅ", "๊ณ„๋ž€"]],
94
+ [["๋œ์žฅ", "๋‘๋ถ€", "ํŒŒ"]],
95
+ [["๊ณ„๋ž€", "ํŒŒ"]]
96
+ ]
97
+ )
98
+
99
+ if __name__ == '__main__':
100
+ demo.launch()