ydshieh commited on
Commit
f705683
1 Parent(s): fa37d5f

use selectbox

Browse files
Files changed (2) hide show
  1. app.py +22 -22
  2. samples/sample_01.jpg +0 -0
app.py CHANGED
@@ -17,18 +17,24 @@ with st.spinner('Loading ViT-GPT2 model ...'):
17
  from model import *
18
  st.sidebar.write(f'Vit-GPT2 model loaded :)')
19
 
20
- st.sidebar.title("Upload Image")
21
 
22
- # Disabling warning
23
- st.set_option('deprecation.showfileUploaderEncoding', False)
24
- # Choose your own image
25
- uploaded_file = st.sidebar.file_uploader(" ", type=['png', 'jpg', 'jpeg'])
 
 
 
 
 
26
 
27
- if uploaded_file is not None:
 
28
 
29
- image = Image.open(uploaded_file)
30
- show = st.image(image, use_column_width=True)
31
- show.image(image, 'Uploaded Image', use_column_width=True)
32
 
33
 
34
  # For newline
@@ -36,19 +42,13 @@ st.sidebar.write('\n')
36
 
37
  if st.sidebar.button("Click here to get image caption"):
38
 
39
- if uploaded_file is None:
40
 
41
- st.sidebar.write("Please upload an Image to Classify")
42
 
43
- else:
 
 
44
 
45
- with st.spinner('Generating image caption ...'):
46
-
47
- caption, tokens, token_ids = predict(image)
48
-
49
- st.success(f'caption: {caption}')
50
- st.success(f'tokens: {tokens}')
51
- st.success(f'token ids: {token_ids}')
52
-
53
- st.sidebar.header("ViT-GPT2 predicts:")
54
- st.sidebar.write(f"caption: {caption}", '\n')
 
17
  from model import *
18
  st.sidebar.write(f'Vit-GPT2 model loaded :)')
19
 
20
+ st.sidebar.title("Select a sample image")
21
 
22
+ sample_name = st.sidebar.selectbox(
23
+ "Please Choose the Model",
24
+ (
25
+ "sample 1",
26
+ "sample 2",
27
+ "sample 3",
28
+ "sample 4"
29
+ )
30
+ )
31
 
32
+ sample_name = f'sample_{sample_name.split()[-1].zfill(2)}.jpg'
33
+ sample_path = f'samples/{sample_name}'
34
 
35
+ image = Image.open(sample_path)
36
+ show = st.image(image, use_column_width=True)
37
+ show.image(image, 'Uploaded Image', use_column_width=True)
38
 
39
 
40
  # For newline
 
42
 
43
  if st.sidebar.button("Click here to get image caption"):
44
 
45
+ with st.spinner('Generating image caption ...'):
46
 
47
+ caption, tokens, token_ids = predict(image)
48
 
49
+ st.success(f'caption: {caption}')
50
+ st.success(f'tokens: {tokens}')
51
+ st.success(f'token ids: {token_ids}')
52
 
53
+ st.sidebar.header("ViT-GPT2 predicts:")
54
+ st.sidebar.write(f"caption: {caption}", '\n')
 
 
 
 
 
 
 
 
samples/sample_01.jpg ADDED