recipes_arabic / app.py
ayajoharji's picture
Update app.py
aa5a0a0 verified
raw
history blame
1.67 kB
import gradio as gr
import pandas as pd
# Load recipes from CSV file
def load_recipes(file_path):
df = pd.read_csv(file_path)
recipes = []
for _, row in df.iterrows():
recipes.append({
"name": row["name"],
"ingredients": [i.strip() for i in row["ingredients"].split(',')],
"steps": row["steps"]
})
return recipes
# Load recipes
recipes = load_recipes('recipes_arabic.csv')
def suggest_recipes(user_ingredients):
user_ingredients = [i.strip().lower() for i in user_ingredients.split(',')]
matching_recipes = []
for recipe in recipes:
recipe_ingredients = [i.strip().lower() for i in recipe['ingredients']]
if all(ingredient in recipe_ingredients for ingredient in user_ingredients):
ingredient_list = ', '.join(recipe['ingredients'])
matching_recipes.append(f"{recipe['name']}\nIngredients: {ingredient_list}\nSteps: {recipe['steps']}")
if not matching_recipes:
return "لا توجد وصفات تتناسب مع المكونات المدخلة."
return "\n\n".join(matching_recipes)
# Create the Gradio interface
iface = gr.Interface(
fn=suggest_recipes,
inputs=gr.Textbox(label="ادخل المكونات (مفصولة بفواصل)"),
outputs=gr.Textbox(label="الوصفات المقترحة"),
title="اقتراحات الوصفات العربية",
description="<img src='image.jpg' width='400'/> <br>ادخل المكونات التي لديك للحصول على اقتراحات لوصفات عربية تقليدية."
)
# Launch the interface
if __name__ == "__main__":
iface.launch(share=True)