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