Spaces:
Build error
Build error
import streamlit as st | |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
# Load the model and tokenizer | |
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 π€") | |