Spaces:
Runtime error
Runtime error
ydshieh
commited on
Commit
•
f705683
1
Parent(s):
fa37d5f
use selectbox
Browse files- app.py +22 -22
- 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("
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
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 |
-
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
|
|
|
|
44 |
|
45 |
-
|
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