Upload app.py with huggingface_hub
Browse files
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()
|