Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model():
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("Izza-shahzad-13/recipe-generator")
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("Izza-shahzad-13/recipe-generator")
|
| 9 |
+
return tokenizer, model
|
| 10 |
+
|
| 11 |
+
tokenizer, model = load_model()
|
| 12 |
+
|
| 13 |
+
# Streamlit App
|
| 14 |
+
st.title("🍳 Recipe Generator App")
|
| 15 |
+
st.markdown("Generate delicious recipes by entering the ingredients you have!")
|
| 16 |
+
|
| 17 |
+
# Input ingredients
|
| 18 |
+
ingredients = st.text_area(
|
| 19 |
+
"Enter ingredients (comma-separated):",
|
| 20 |
+
placeholder="e.g., chicken, onion, garlic, tomatoes",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Generate recipe button
|
| 24 |
+
if st.button("Generate Recipe"):
|
| 25 |
+
if ingredients:
|
| 26 |
+
with st.spinner("Generating your recipe... 🍲"):
|
| 27 |
+
# Prepare input for the model
|
| 28 |
+
inputs = tokenizer(f"Ingredients: {ingredients}", return_tensors="pt")
|
| 29 |
+
|
| 30 |
+
# Generate recipe
|
| 31 |
+
outputs = model.generate(inputs["input_ids"], max_length=150, num_beams=5, early_stopping=True)
|
| 32 |
+
recipe = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 33 |
+
|
| 34 |
+
# Display the recipe
|
| 35 |
+
st.success("Here's your recipe:")
|
| 36 |
+
st.write(recipe)
|
| 37 |
+
else:
|
| 38 |
+
st.warning("Please enter some ingredients!")
|
| 39 |
+
|
| 40 |
+
# Footer
|
| 41 |
+
st.markdown("---")
|
| 42 |
+
st.markdown("Built with ❤️ using Streamlit and Hugging Face 🤗")
|