tariquef commited on
Commit
16d4da6
·
verified ·
1 Parent(s): 9fec3cd

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the recipe generation model
5
+ generator = pipeline("text2text-generation", model="flax-community/t5-recipe-generation")
6
+
7
+ def generate_recipe(ingredients):
8
+ """
9
+ Generate a recipe based on the provided ingredients
10
+ """
11
+ # Check if ingredients are provided
12
+ if not ingredients.strip():
13
+ return "Please enter some ingredients!"
14
+
15
+ try:
16
+ # Format the prompt for the model
17
+ # The model expects format: "items: ingredient1, ingredient2, ingredient3"
18
+ prompt = f"items: {ingredients}"
19
+
20
+ # Generate the recipe
21
+ result = generator(prompt, max_length=512, do_sample=True)
22
+
23
+ # Extract the generated recipe
24
+ recipe = result[0]['generated_text']
25
+
26
+ # Format the output nicely
27
+ output = "#Generated Recipe\n\n"
28
+ output += "---\n\n"
29
+ output += recipe
30
+ output += "\n\n---\n\n"
31
+ output += "**Tip**: Try different ingredient combinations for variety!"
32
+
33
+ return output
34
+
35
+ except Exception as e:
36
+ return f"Error generating recipe: {str(e)}\n\nPlease try again with different ingredients."
37
+
38
+ # Example ingredient combinations for users to try
39
+ examples = [
40
+ ["chicken, rice, garlic, tomatoes, onion"],
41
+ ["pasta, cream, parmesan cheese, mushrooms, spinach"],
42
+ ["eggs, milk, flour, sugar, vanilla extract"],
43
+ ["salmon, lemon, dill, potatoes, butter"],
44
+ ["beef, beans, chili powder, onion, tomatoes"],
45
+ ["tofu, soy sauce, ginger, broccoli, sesame oil"]
46
+ ]
47
+
48
+ # Create the Gradio interface
49
+ demo = gr.Interface(
50
+ fn=generate_recipe,
51
+ inputs=gr.Textbox(
52
+ label="Enter Your Ingredients",
53
+ placeholder="chicken, rice, garlic, tomatoes, onion",
54
+ lines=3,
55
+ info="Enter ingredients separated by commas"
56
+ ),
57
+ outputs=gr.Markdown(label="Your Recipe"),
58
+ title="AI Recipe Generator",
59
+ description="Enter the ingredients you have, and I'll generate a delicious recipe for you!",
60
+ examples=examples,
61
+ theme=gr.themes.Soft(),
62
+ article="""
63
+ ### How to use:
64
+ 1. Enter your available ingredients separated by commas
65
+ 2. Click 'Submit' or press Enter
66
+ 3. Get a complete recipe with instructions!
67
+
68
+ **Powered by T5 Recipe Generation Model from Hugging Face**
69
+ """
70
+ )
71
+
72
+ if __name__ == "__main__":
73
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch
4
+ sentencepiece