Spaces:
Runtime error
Runtime error
ydshieh
commited on
Commit
•
686f21e
1
Parent(s):
f705683
try import model related packages
Browse files- app.py +8 -8
- model.py +13 -2
- requirements.txt +4 -1
app.py
CHANGED
@@ -40,15 +40,15 @@ show.image(image, 'Uploaded Image', use_column_width=True)
|
|
40 |
# For newline
|
41 |
st.sidebar.write('\n')
|
42 |
|
43 |
-
if st.sidebar.button("Click here to get image caption"):
|
44 |
|
45 |
-
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
|
|
40 |
# For newline
|
41 |
st.sidebar.write('\n')
|
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')
|
model.py
CHANGED
@@ -1,9 +1,20 @@
|
|
1 |
-
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
4 |
|
|
|
|
|
5 |
|
|
|
|
|
6 |
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
|
|
|
1 |
+
import os, sys
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
|
5 |
+
import jax
|
6 |
+
from transformers import ViTFeatureExtractor
|
7 |
+
from transformers import GPT2Tokenizer
|
8 |
|
9 |
+
current_path = os.path.dirname(os.path.abspath(__file__))
|
10 |
+
sys.path.append(current_path)
|
11 |
|
12 |
+
# Main model - ViTGPT2LM
|
13 |
+
# from vit_gpt2.modeling_flax_vit_gpt2_lm import FlaxViTGPT2LMForConditionalGeneration
|
14 |
|
15 |
+
def predict(image):
|
16 |
+
|
17 |
+
return 'dummy caption!', ['dummy', 'caption', '!'], [1, 2, 3]
|
18 |
|
19 |
|
20 |
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
streamlit==0.84.1
|
|
|
|
|
|
|
|
1 |
+
streamlit==0.84.1
|
2 |
+
Pillow
|
3 |
+
jax
|
4 |
+
transformers
|