Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -5,22 +5,19 @@ import requests
|
|
5 |
from PIL import Image
|
6 |
from model import get_caption_model, generate_caption
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
return get_caption_model()
|
12 |
-
|
13 |
-
caption_model = get_model()
|
14 |
|
15 |
def predict():
|
16 |
captions = []
|
17 |
try:
|
18 |
-
pred_caption = generate_caption('tmp.jpg', caption_model)
|
19 |
st.markdown('#### Predicted Captions:')
|
20 |
captions.append(pred_caption)
|
21 |
|
22 |
for _ in range(4):
|
23 |
-
pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True)
|
24 |
if pred_caption not in captions:
|
25 |
captions.append(pred_caption)
|
26 |
|
|
|
5 |
from PIL import Image
|
6 |
from model import get_caption_model, generate_caption
|
7 |
|
8 |
+
# Initialize session state for the model
|
9 |
+
if 'caption_model' not in st.session_state:
|
10 |
+
st.session_state.caption_model = get_caption_model()
|
|
|
|
|
|
|
11 |
|
12 |
def predict():
|
13 |
captions = []
|
14 |
try:
|
15 |
+
pred_caption = generate_caption('tmp.jpg', st.session_state.caption_model)
|
16 |
st.markdown('#### Predicted Captions:')
|
17 |
captions.append(pred_caption)
|
18 |
|
19 |
for _ in range(4):
|
20 |
+
pred_caption = generate_caption('tmp.jpg', st.session_state.caption_model, add_noise=True)
|
21 |
if pred_caption not in captions:
|
22 |
captions.append(pred_caption)
|
23 |
|