Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,27 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load the model (this runs only once!)
|
5 |
+
generator = pipeline("text2text-generation", model="LahiruProjects/recipe-generator-flan-t5")
|
6 |
|
7 |
+
def generate_recipe(name, ingredients, calories, time):
|
8 |
+
prompt = f"""Create a step-by-step recipe for "{name}" using these ingredients: {', '.join(ingredients.split(','))}.
|
9 |
+
Keep it under {calories} calories and make sure it's ready in less than {time} minutes."""
|
10 |
+
result = generator(prompt)
|
11 |
+
return result[0]["generated_text"]
|
12 |
+
|
13 |
+
# Gradio interface
|
14 |
+
iface = gr.Interface(
|
15 |
+
fn=generate_recipe,
|
16 |
+
inputs=[
|
17 |
+
gr.Textbox(label="Recipe Name"),
|
18 |
+
gr.Textbox(label="Ingredients (comma-separated)"),
|
19 |
+
gr.Number(label="Max Calories", value=400),
|
20 |
+
gr.Number(label="Max Cooking Time (minutes)", value=30)
|
21 |
+
],
|
22 |
+
outputs="text",
|
23 |
+
title="π³ Recipe Generator (FLAN-T5)",
|
24 |
+
description="Generate a step-by-step recipe based on ingredients, calorie limit, and time"
|
25 |
+
)
|
26 |
+
|
27 |
+
iface.launch()
|