Spaces:
Sleeping
Sleeping
nishantguvvada
commited on
Commit
•
6547b74
1
Parent(s):
6534f94
Update app.py
Browse files
app.py
CHANGED
@@ -85,9 +85,10 @@ index_to_word = StringLookup(
|
|
85 |
|
86 |
## Probabilistic prediction using the trained model
|
87 |
def predict_caption(file):
|
|
|
88 |
gru_state = tf.zeros((1, ATTENTION_DIM))
|
89 |
|
90 |
-
img = tf.image.decode_jpeg(
|
91 |
img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH))
|
92 |
img = img / 255
|
93 |
|
@@ -117,38 +118,15 @@ def predict_caption(file):
|
|
117 |
|
118 |
return img, result
|
119 |
|
120 |
-
|
121 |
-
filename = "../sample_images/surf.jpeg" # you can also try surf.jpeg
|
122 |
-
|
123 |
-
for i in range(5):
|
124 |
-
image, caption = predict_caption(filename)
|
125 |
-
print(" ".join(caption[:-1]) + ".")
|
126 |
-
|
127 |
-
img = tf.image.decode_jpeg(tf.io.read_file(filename), channels=IMG_CHANNELS)
|
128 |
-
plt.imshow(img)
|
129 |
-
plt.axis("off")
|
130 |
-
|
131 |
-
|
132 |
-
filename = np.array(Image.open(file).convert('RGB'))
|
133 |
-
|
134 |
-
def model_prediction(path):
|
135 |
-
resize = tf.image.resize(path, (256,256))
|
136 |
-
with st.spinner('Model is being loaded..'):
|
137 |
-
model=load_image_model()
|
138 |
-
yhat = model.predict(np.expand_dims(resize/255, 0))
|
139 |
-
return yhat
|
140 |
-
|
141 |
def on_click():
|
142 |
if file is None:
|
143 |
st.text("Please upload an image file")
|
144 |
else:
|
145 |
image = Image.open(file)
|
146 |
st.image(image, use_column_width=True)
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
st.write(""
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
st.button('Predict', on_click=on_click)
|
|
|
85 |
|
86 |
## Probabilistic prediction using the trained model
|
87 |
def predict_caption(file):
|
88 |
+
filename = Image.open(file)
|
89 |
gru_state = tf.zeros((1, ATTENTION_DIM))
|
90 |
|
91 |
+
img = tf.image.decode_jpeg(filename, channels=IMG_CHANNELS)
|
92 |
img = tf.image.resize(img, (IMG_HEIGHT, IMG_WIDTH))
|
93 |
img = img / 255
|
94 |
|
|
|
118 |
|
119 |
return img, result
|
120 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
def on_click():
|
122 |
if file is None:
|
123 |
st.text("Please upload an image file")
|
124 |
else:
|
125 |
image = Image.open(file)
|
126 |
st.image(image, use_column_width=True)
|
127 |
+
for i in range(5):
|
128 |
+
image, caption = predict_caption(file)
|
129 |
+
#print(" ".join(caption[:-1]) + ".")
|
130 |
+
st.write(" ".join(caption[:-1]) + ".")
|
131 |
+
|
132 |
+
st.button('Generate', on_click=on_click)
|
|
|
|