| import streamlit as st | |
| from transformers import T5Tokenizer, T5ForConditionalGeneration | |
| MODEL_NAME_OR_PATH = "flax-community/t5-recipe-generation" | |
| tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME_OR_PATH, use_fast=True) | |
| model = T5ForConditionalGeneration.from_pretrained(MODEL_NAME_OR_PATH) | |
| def generate_recipe(input_items): | |
| prefix = "items: " | |
| input_text = prefix + input_items | |
| input_ids = tokenizer.encode(input_text, return_tensors="pt") | |
| output_ids = model.generate(input_ids) | |
| generated_recipe = tokenizer.decode(output_ids[0], skip_special_tokens=True) | |
| return generated_recipe | |
| def main(): | |
| st.title("Recipe Generation") | |
| input_items = st.text_area("Enter the recipe instructions:") | |
| if st.button("Generate Recipe"): | |
| generated_recipe = generate_recipe(input_items) | |
| st.subheader("Generated Recipe:") | |
| st.text(generated_recipe) | |
| if __name__ == "__main__": | |
| main() | |