File size: 1,421 Bytes
84d7012
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the model and tokenizer
@st.cache_resource
def load_model():
    tokenizer = AutoTokenizer.from_pretrained("Izza-shahzad-13/recipe-generator")
    model = AutoModelForSeq2SeqLM.from_pretrained("Izza-shahzad-13/recipe-generator")
    return tokenizer, model

tokenizer, model = load_model()

# Streamlit App
st.title("🍳 Recipe Generator App")
st.markdown("Generate delicious recipes by entering the ingredients you have!")

# Input ingredients
ingredients = st.text_area(
    "Enter ingredients (comma-separated):",
    placeholder="e.g., chicken, onion, garlic, tomatoes",
)

# Generate recipe button
if st.button("Generate Recipe"):
    if ingredients:
        with st.spinner("Generating your recipe... 🍲"):
            # Prepare input for the model
            inputs = tokenizer(f"Ingredients: {ingredients}", return_tensors="pt")

            # Generate recipe
            outputs = model.generate(inputs["input_ids"], max_length=150, num_beams=5, early_stopping=True)
            recipe = tokenizer.decode(outputs[0], skip_special_tokens=True)

            # Display the recipe
            st.success("Here's your recipe:")
            st.write(recipe)
    else:
        st.warning("Please enter some ingredients!")

# Footer
st.markdown("---")
st.markdown("Built with ❀️ using Streamlit and Hugging Face πŸ€—")