2006elad commited on
Commit
8d29b29
1 Parent(s): aa7588a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -1,4 +1,6 @@
 
1
  from transformers import T5Tokenizer, FlaxT5ForConditionalGeneration
 
2
 
3
  MODEL_NAME_OR_PATH = "t5-base"
4
  tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME_OR_PATH)
@@ -46,11 +48,21 @@ def generate_recipe(items):
46
  attention_mask=attention_mask,
47
  **generation_kwargs
48
  )
 
 
 
 
49
  generated_recipe = tokenizer.batch_decode(output_ids, skip_special_tokens=False)
50
  generated_recipe = target_postprocessing(generated_recipe, tokenizer.all_special_tokens)
51
  return generated_recipe[0]
52
 
53
- # Example usage
54
- input_items = "apple, cucumber"
55
- generated_recipe = generate_recipe(input_items)
56
- print(generated_recipe)
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  from transformers import T5Tokenizer, FlaxT5ForConditionalGeneration
3
+ import numpy as np
4
 
5
  MODEL_NAME_OR_PATH = "t5-base"
6
  tokenizer = T5Tokenizer.from_pretrained(MODEL_NAME_OR_PATH)
 
48
  attention_mask=attention_mask,
49
  **generation_kwargs
50
  )
51
+
52
+ # Convert output IDs to numpy array
53
+ output_ids = np.array(output_ids)
54
+
55
  generated_recipe = tokenizer.batch_decode(output_ids, skip_special_tokens=False)
56
  generated_recipe = target_postprocessing(generated_recipe, tokenizer.all_special_tokens)
57
  return generated_recipe[0]
58
 
59
+ def main():
60
+ st.title("Recipe Generation")
61
+
62
+ items = st.text_input("Enter food items separated by comma (e.g., apple, cucumber):")
63
+ if st.button("Generate Recipe"):
64
+ generated_recipe = generate_recipe(items)
65
+ st.write(generated_recipe)
66
+
67
+ if __name__ == "__main__":
68
+ main()