ceyda commited on
Commit
bc75186
1 Parent(s): 19e4e13

cache the model so it doesn't reload for every image

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -4,6 +4,14 @@ from PIL import Image
4
  import streamlit as st
5
  import tensorflow as tf
6
 
 
 
 
 
 
 
 
 
7
  # Inputs
8
  st.title("Input your image")
9
  image_url = st.text_input(
@@ -27,10 +35,6 @@ if uploaded_file:
27
 
28
  st.image(image, caption="Original Image")
29
 
30
- # Load the DINO model
31
- with st.spinner("Loading the model..."):
32
- dino = from_pretrained_keras("probing-vits/vit-dino-base16")
33
-
34
  with st.spinner("Generating the attention scores..."):
35
  # Get the attention scores
36
  _, attention_score_dict = dino.predict(preprocessed_image)
 
4
  import streamlit as st
5
  import tensorflow as tf
6
 
7
+ st.cache(show_spinner=True)
8
+ def load_model():
9
+ # Load the DINO model
10
+ dino = from_pretrained_keras("probing-vits/vit-dino-base16")
11
+ return dino
12
+
13
+ dino=load_model()
14
+
15
  # Inputs
16
  st.title("Input your image")
17
  image_url = st.text_input(
 
35
 
36
  st.image(image, caption="Original Image")
37
 
 
 
 
 
38
  with st.spinner("Generating the attention scores..."):
39
  # Get the attention scores
40
  _, attention_score_dict = dino.predict(preprocessed_image)