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