Spaces:
Runtime error
Runtime error
ydshieh
commited on
Commit
•
8d9306e
1
Parent(s):
7dcdfea
upload scripts
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
# Designing the interface
|
7 |
+
st.title("French Image Caption App")
|
8 |
+
# For newline
|
9 |
+
st.write('\n')
|
10 |
+
|
11 |
+
image = Image.open('images/image.png')
|
12 |
+
show = st.image(image, use_column_width=True)
|
13 |
+
# show.image(image, 'Preloaded Image', use_column_width=True)
|
14 |
+
|
15 |
+
with st.spinner('Loading ViT-GPT2 model ...'):
|
16 |
+
|
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.image(image, 'Uploaded Image', use_column_width=True)
|
31 |
+
|
32 |
+
|
33 |
+
# For newline
|
34 |
+
st.sidebar.write('\n')
|
35 |
+
|
36 |
+
if st.sidebar.button("Click here to get image caption"):
|
37 |
+
|
38 |
+
if uploaded_file is None:
|
39 |
+
|
40 |
+
st.sidebar.write("Please upload an Image to Classify")
|
41 |
+
|
42 |
+
else:
|
43 |
+
|
44 |
+
with st.spinner('Generating image caption ...'):
|
45 |
+
|
46 |
+
caption, tokens, token_ids = predict(image)
|
47 |
+
|
48 |
+
st.success(f'caption: {caption}')
|
49 |
+
st.success(f'tokens: {tokens}')
|
50 |
+
st.success(f'token ids: {token_ids}')
|
51 |
+
|
52 |
+
st.sidebar.header("ViT-GPT2 predicts:")
|
53 |
+
st.sidebar.write(f"caption: {caption}", '\n')
|
model.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def predict(image):
|
2 |
+
|
3 |
+
return 'dummy caption!', ['dummy', 'caption', '!'], [1, 2, 3]
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
|