Anandx05 commited on
Commit
8955de2
1 Parent(s): 9092e7b

Upload test.py

Browse files
Files changed (1) hide show
  1. test.py +43 -0
test.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import os
3
+ import streamlit as st
4
+ import requests
5
+ from PIL import Image
6
+ from model import get_caption_model, generate_caption
7
+
8
+
9
+ @st.cache(allow_output_mutation=True)
10
+ def get_model():
11
+ return get_caption_model()
12
+
13
+ caption_model = get_model()
14
+
15
+
16
+ def predict():
17
+ captions = []
18
+ pred_caption = generate_caption('tmp.jpg', caption_model)
19
+
20
+ st.markdown('#### Predicted Captions:')
21
+ captions.append(pred_caption)
22
+
23
+ for _ in range(4):
24
+ pred_caption = generate_caption('tmp.jpg', caption_model, add_noise=True)
25
+ if pred_caption not in captions:
26
+ captions.append(pred_caption)
27
+
28
+ for c in captions:
29
+ st.write(c)
30
+
31
+
32
+
33
+ st.markdown('<center style="opacity: 70%">OR</center>', unsafe_allow_html=True)
34
+ img_upload = st.file_uploader(label='Upload Image', type=['jpg', 'png', 'jpeg'])
35
+
36
+ if img_upload != None:
37
+ img = img_upload.read()
38
+ img = Image.open(io.BytesIO(img))
39
+ img = img.convert('RGB')
40
+ img.save('tmp.jpg')
41
+ st.image(img)
42
+ predict()
43
+ os.remove('tmp.jpg')