ixtidb / app.py
openfree's picture
Upload app.py with huggingface_hub
b9e7deb verified
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()