Spaces:
Running
Running
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=""" | |
<div style='text-align: center;'> | |
<img src='https://huggingface.co/spaces/ayajoharji/recipes_arabic/resolve/main/image.jpg' width='600' style='display: block; margin-left: auto; margin-right: auto;' /> | |
<p>ادخل المكونات التي لديك للحصول على اقتراحات لوصفات عربية تقليدية.</p> | |
</div> | |
""" | |
) | |
# Launch the interface | |
if __name__ == "__main__": | |
iface.launch(share=True) | |