Izza-shahzad-13's picture
Create app.py
84d7012 verified
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 πŸ€—")