File size: 928 Bytes
8d29b29
5dcff48
de9b5a0
5dcff48
 
 
de9b5a0
5dcff48
 
 
 
 
 
 
de9b5a0
8d29b29
 
5dcff48
8d29b29
5dcff48
 
 
8d29b29
 
 
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
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()