zamborg commited on
Commit
c8a1a5f
1 Parent(s): 4dab50d

uncommented

Browse files
Files changed (1) hide show
  1. app.py +49 -49
app.py CHANGED
@@ -1,66 +1,66 @@
1
  import streamlit as st
2
  import io
3
 
4
- # st.title("Image Captioning Demo from Redcaps")
5
- # st.sidebar.markdown(
6
- # """
7
- # Image Captioning Model from VirTex trained on Redcaps
8
- # """
9
- # )
10
 
11
- # with st.spinner("Loading Model"):
12
- # from model import *
13
- # sample_images = glob.glob("./samples/*.jpg")
14
- # download_files()
15
- # virtexModel = VirTexModel()
16
- # imageLoader = ImageLoader()
17
 
18
- # random_image = get_rand_img(sample_images)
19
 
20
- # st.sidebar.title("Select a sample image")
21
- # sample_image = st.sidebar.selectbox(
22
- # "",
23
- # sample_images
24
- # )
25
 
26
- # if st.sidebar.button("Random Sample Image"):
27
- # random_image = get_rand_img(sample_images)
28
- # sample_image = None
29
 
30
- # uploaded_image = None
31
- # with st.sidebar.form("file-uploader-form", clear_on_submit=True):
32
- # uploaded_file = st.file_uploader("Choose a file")
33
- # submitted = st.form_submit_button("Submit")
34
- # if uploaded_file is not None and submitted:
35
- # uploaded_image = Image.open(io.BytesIO(uploaded_file.get_values()))
36
 
37
- # if uploaded_image is None and submitted:
38
- # st.write("Please select a file to upload")
39
 
40
- # else:
41
- # image_file = sample_image if sample_image is not None else random_image
42
 
43
- # image = uploaded_image if uploaded_image is not None else Image.open()
44
 
45
- # image_dict = imageLoader.transform(image)
46
 
47
- # show.image(st.image(image_dict["image"]), "Target Image")
48
 
49
- # with st.spinner("Generating Caption"):
50
- # subreddit, caption = virtexModel.predict(image_dict)
51
- # st.header("Predicted Caption:\n\n")
52
- # st.subheader(f"Subreddit: {subreddit}\n")
53
- # st.subheader(f"Caption: {caption}\n")
54
 
55
- # image.close()
56
 
57
- from model import *
58
- download_files()
59
- sample_images = get_samples()
60
- v, il = VirTexModel(), ImageLoader()
61
 
62
- for s in sample_images:
63
- subreddit, caption = v.predict(il.load(s))
64
- print("=====================")
65
- print(subreddit)
66
- print(caption)
 
1
  import streamlit as st
2
  import io
3
 
4
+ st.title("Image Captioning Demo from Redcaps")
5
+ st.sidebar.markdown(
6
+ """
7
+ Image Captioning Model from VirTex trained on Redcaps
8
+ """
9
+ )
10
 
11
+ with st.spinner("Loading Model"):
12
+ from model import *
13
+ sample_images = glob.glob("./samples/*.jpg")
14
+ download_files()
15
+ virtexModel = VirTexModel()
16
+ imageLoader = ImageLoader()
17
 
18
+ random_image = get_rand_img(sample_images)
19
 
20
+ st.sidebar.title("Select a sample image")
21
+ sample_image = st.sidebar.selectbox(
22
+ "",
23
+ sample_images
24
+ )
25
 
26
+ if st.sidebar.button("Random Sample Image"):
27
+ random_image = get_rand_img(sample_images)
28
+ sample_image = None
29
 
30
+ uploaded_image = None
31
+ with st.sidebar.form("file-uploader-form", clear_on_submit=True):
32
+ uploaded_file = st.file_uploader("Choose a file")
33
+ submitted = st.form_submit_button("Submit")
34
+ if uploaded_file is not None and submitted:
35
+ uploaded_image = Image.open(io.BytesIO(uploaded_file.get_values()))
36
 
37
+ if uploaded_image is None and submitted:
38
+ st.write("Please select a file to upload")
39
 
40
+ else:
41
+ image_file = sample_image if sample_image is not None else random_image
42
 
43
+ image = uploaded_image if uploaded_image is not None else Image.open()
44
 
45
+ image_dict = imageLoader.transform(image)
46
 
47
+ show.image(st.image(image_dict["image"]), "Target Image")
48
 
49
+ with st.spinner("Generating Caption"):
50
+ subreddit, caption = virtexModel.predict(image_dict)
51
+ st.header("Predicted Caption:\n\n")
52
+ st.subheader(f"Subreddit: {subreddit}\n")
53
+ st.subheader(f"Caption: {caption}\n")
54
 
55
+ image.close()
56
 
57
+ # from model import *
58
+ # download_files()
59
+ # sample_images = get_samples()
60
+ # v, il = VirTexModel(), ImageLoader()
61
 
62
+ # for s in sample_images:
63
+ # subreddit, caption = v.predict(il.load(s))
64
+ # print("=====================")
65
+ # print(subreddit)
66
+ # print(caption)