import io import os import streamlit as st import requests from PIL import Image from model import get_caption_model, generate_caption @st.cache(allow_output_mutation=True) def get_model(): return get_caption_model() caption_model = get_model() def predict(): captions = [] pred_caption = generate_caption('tmp.jpg', caption_model) st.markdown('#### Predicted Captions:') captions.append(pred_caption) for _ in range(4): pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True) if pred_caption not in captions: captions.append(pred_caption) for c in captions: st.write(c) st.markdown('