| import gradio as gr |
| import random |
| recipes_db = { |
| "๊น์น๋ณถ์๋ฐฅ": { |
| "ingredients": ["๊น์น", "๋ฐฅ", "๊ณ๋", "ํ"], |
| "steps": [ |
| "1. ๊น์น๋ฅผ ์๊ฒ ์ฐ์ด์ฃผ์ธ์.", |
| "2. ํฌ์ ๋ฌ๊ตฐ ํ ๊น์น๋ฅผ ๋ณถ์์ฃผ์ธ์.", |
| "3. ๋ฐฅ์ ๋ฃ๊ณ ํจ๊ป ๋ณถ์์ฃผ์ธ์.", |
| "4. ๊ณ๋์ ํ๋ผ์ดํด์ ์ฌ๋ ค์ฃผ์ธ์.", |
| "5. ์ฌ ํ๋ฅผ garnish๋ก ์ฌ๋ ค์ฃผ์ธ์." |
| ], |
| "difficulty": "์ฌ์", |
| "time": "15๋ถ" |
| }, |
| "๋์ฅ์ฐ๊ฐ": { |
| "ingredients": ["๋์ฅ", "๋๋ถ", "๊ฐ์", "ํ", "์ํ"], |
| "steps": [ |
| "1. ๋ฌผ์ ๋์ฌ์ฃผ์ธ์.", |
| "2. ๋์ฅ์ ํ์ด์ฃผ์ธ์.", |
| "3. ๊ฐ์์ ์ํ๋ฅผ ๋ฃ๊ณ ๋์ฌ์ฃผ์ธ์.", |
| "4. ๋๋ถ๋ฅผ ๋ฃ์ด์ฃผ์ธ์.", |
| "5. ํ๋ฅผ ๋ฃ๊ณ ๋ง๋ฌด๋ฆฌํด์ฃผ์ธ์." |
| ], |
| "difficulty": "๋ณดํต", |
| "time": "20๋ถ" |
| }, |
| "๊ณ๋๋ง์ด": { |
| "ingredients": ["๊ณ๋", "ํ", "๋น๊ทผ"], |
| "steps": [ |
| "1. ๊ณ๋์ ํ์ด์ฃผ์ธ์.", |
| "2. ์๊ฒ ์ฌ ํ์ ๋น๊ทผ์ ๋ฃ์ด์ฃผ์ธ์.", |
| "3. ํฌ์ ๊ธฐ๋ฆ์ ๋๋ฅด๊ณ ๊ณ๋๋ฌผ์ ๋ถ์ด์ฃผ์ธ์.", |
| "4. ํ์ชฝ๋ถํฐ ๋ง์๊ฐ๋ฉฐ ์กฐ๋ฆฌํด์ฃผ์ธ์.", |
| "5. ์ ๋นํ ํฌ๊ธฐ๋ก ์๋ผ ์์ฑํด์ฃผ์ธ์." |
| ], |
| "difficulty": "์ฌ์", |
| "time": "10๋ถ" |
| }, |
| "๋ผ๋ฉด": { |
| "ingredients": ["๋ผ๋ฉด", "๊ณ๋", "ํ"], |
| "steps": [ |
| "1. ๋ฌผ์ ๋์ฌ์ฃผ์ธ์.", |
| "2. ๋ผ๋ฉด๊ณผ ์คํ๋ฅผ ๋ฃ์ด์ฃผ์ธ์.", |
| "3. ๊ณ๋์ ๋ฃ์ด์ฃผ์ธ์.", |
| "4. ์ฌ ํ๋ฅผ ๋ฃ์ด์ฃผ์ธ์.", |
| "5. 2-3๋ถ ๋ ๋์ฌ ์์ฑํด์ฃผ์ธ์." |
| ], |
| "difficulty": "์ฌ์", |
| "time": "5๋ถ" |
| } |
| } |
| available_ingredients = sorted(list(set( |
| ingredient |
| for recipe in recipes_db.values() |
| for ingredient in recipe['ingredients'] |
| ))) |
| def find_recipes(selected_ingredients): |
| if not selected_ingredients: |
| return "์ฌ๋ฃ๋ฅผ ์ ํํด์ฃผ์ธ์." |
| possible_recipes = [] |
| for recipe_name, recipe_info in recipes_db.items(): |
| required_ingredients = set(recipe_info['ingredients']) |
| selected_set = set(selected_ingredients) |
| if selected_set.intersection(required_ingredients): |
| match_percentage = len(selected_set.intersection(required_ingredients)) / len(required_ingredients) * 100 |
| possible_recipes.append((recipe_name, match_percentage, recipe_info)) |
| if not possible_recipes: |
| return "์ ํํ ์ฌ๋ฃ๋ก ๋ง๋ค ์ ์๋ ์๋ฆฌ๊ฐ ์์ต๋๋ค." |
| possible_recipes.sort(key=lambda x: x[1], reverse=True) |
| result = "" |
| for recipe_name, match, recipe_info in possible_recipes: |
| result += f"\n๐ณ {recipe_name} (์ฌ๋ฃ ์ผ์น๋: {match:.1f}%)\n" |
| result += f"๋์ด๋: {recipe_info['difficulty']}\n" |
| result += f"์กฐ๋ฆฌ์๊ฐ: {recipe_info['time']}\n" |
| result += "\nํ์ํ ์ฌ๋ฃ:\n" |
| result += "โข " + "\nโข ".join(recipe_info['ingredients']) + "\n" |
| result += "\n์กฐ๋ฆฌ ๊ณผ์ :\n" |
| result += "\n".join(recipe_info['steps']) + "\n" |
| result += "\n" + "="*50 + "\n" |
| return result |
| demo = gr.Interface( |
| fn=find_recipes, |
| inputs=gr.Checkboxgroup( |
| choices=available_ingredients, |
| label="๊ฐ์ง๊ณ ์๋ ์ฌ๋ฃ๋ฅผ ์ ํํ์ธ์" |
| ), |
| outputs=gr.Textbox(label="์ถ์ฒ ์๋ฆฌ ๋ ์ํผ", lines=20), |
| title="๐ฅ ์๋ฆฌ ๋ ์ํผ ์ถ์ฒ", |
| description="๊ฐ์ง๊ณ ์๋ ์ฌ๋ฃ๋ฅผ ์ ํํ๋ฉด ๋ง๋ค ์ ์๋ ์๋ฆฌ์ ๋ ์ํผ๋ฅผ ์ถ์ฒํด๋๋ฆฝ๋๋ค.", |
| theme="soft", |
| examples=[ |
| [["๊น์น", "๋ฐฅ", "๊ณ๋"]], |
| [["๋์ฅ", "๋๋ถ", "ํ"]], |
| [["๊ณ๋", "ํ"]] |
| ] |
| ) |
|
|
| if __name__ == '__main__': |
| demo.launch() |