File size: 1,412 Bytes
755e467
 
 
 
1c82651
 
 
755e467
 
b4fd20a
 
755e467
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from transformers import pipeline

# Load a model from Hugging Face for recipe generation
# Use a pipeline as a high-level helper
from transformers import pipeline
model = pipeline("text2text-generation", model="flax-community/t5-recipe-generation")
# Recipe generation function
def suggest_recipes(ingredients):
    prompt = f" You are expert in cooking. Please suggest 3 recipes using the following ingredients: {ingredients}. Give the title to each recipe. Include preparation time for each recipe at the beginning."
    response = model(prompt)
    
    # Parse model output into a readable format
    recipes = []
    for i, recipe in enumerate(response):
        recipes.append(f"Recipe {i+1}: {recipe['generated_text']}")
    
    return "\n\n".join(recipes)

# Gradio interface
with gr.Blocks() as app:
    gr.Markdown("# Recipe Suggestion App")
    gr.Markdown("Provide the ingredients you have, and this app will suggest recipes along with preparation times!")
    
    with gr.Row():
        ingredients_input = gr.Textbox(label="Enter Ingredients (comma-separated):", placeholder="e.g., eggs, milk, flour")
    
    recipe_output = gr.Textbox(label="Suggested Recipes:", lines=10, interactive=False)
    
    generate_button = gr.Button("Get Recipes")
    
    generate_button.click(suggest_recipes, inputs=ingredients_input, outputs=recipe_output)

# Launch the app
app.launch()