Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,27 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load a model from Hugging Face for recipe generation
|
5 |
-
model = pipeline("text-generation", model="flax-community/t5-recipe-generation")
|
|
|
6 |
# Recipe generation function
|
7 |
def suggest_recipes(ingredients):
|
8 |
-
prompt =
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Gradio interface
|
14 |
with gr.Blocks() as app:
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Load a model from Hugging Face for recipe generation
|
5 |
+
model = pipeline("text-generation", model="flax-community/t5-recipe-generation")
|
6 |
+
|
7 |
# Recipe generation function
|
8 |
def suggest_recipes(ingredients):
|
9 |
+
prompt = (
|
10 |
+
f"You are an expert in cooking. Please suggest 3 recipes using the following "
|
11 |
+
f"ingredients: {ingredients}. Provide a title for each recipe, include "
|
12 |
+
f"preparation time, and list step-by-step directions."
|
13 |
+
)
|
14 |
+
response = model(prompt, max_length=512, num_return_sequences=1)
|
15 |
+
|
16 |
+
# Parse the generated text to create structured recipes
|
17 |
+
generated_text = response[0]['generated_text']
|
18 |
+
recipes = generated_text.split("Recipe ")
|
19 |
+
structured_recipes = []
|
20 |
+
|
21 |
+
for i, recipe in enumerate(recipes):
|
22 |
+
if recipe.strip(): # Ensure non-empty recipe
|
23 |
+
structured_recipes.append(f"Recipe {i+1}:\n{recipe.strip()}")
|
24 |
+
|
25 |
+
return "\n\n".join(structured_recipes)
|
26 |
|
27 |
# Gradio interface
|
28 |
with gr.Blocks() as app:
|