Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,23 +6,32 @@ import skimage.io as io
|
|
| 6 |
import PIL.Image
|
| 7 |
import difflib
|
| 8 |
import ViTCoAtt
|
|
|
|
| 9 |
from build_vocab import Vocabulary
|
| 10 |
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
# Caption generation functions
|
| 14 |
def generate_caption_clipgpt(image, max_tokens, temperature):
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
def generate_caption_vitgpt(image, max_tokens, temperature):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
def generate_caption_vitCoAtt(image):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
with gr.Row():
|
|
@@ -49,6 +58,9 @@ def predict(img, model_name, max_tokens, temperature):
|
|
| 49 |
return generate_caption_vitgpt(img, max_tokens, temperature)
|
| 50 |
elif model_name == "ViT-CoAttention":
|
| 51 |
return generate_caption_vitCoAtt(img)
|
|
|
|
|
|
|
|
|
|
| 52 |
else:
|
| 53 |
return "Caption generation for this model is not yet implemented."
|
| 54 |
|
|
|
|
| 6 |
import PIL.Image
|
| 7 |
import difflib
|
| 8 |
import ViTCoAtt
|
| 9 |
+
import cnn-rnn
|
| 10 |
from build_vocab import Vocabulary
|
| 11 |
|
| 12 |
|
| 13 |
+
|
| 14 |
|
| 15 |
# Caption generation functions
|
| 16 |
def generate_caption_clipgpt(image, max_tokens, temperature):
|
| 17 |
+
caption = clipGPT.generate_caption_clipgpt(image, max_tokens, temperature)
|
| 18 |
+
return caption
|
| 19 |
|
| 20 |
def generate_caption_vitgpt(image, max_tokens, temperature):
|
| 21 |
+
caption = vitGPT.generate_caption(image, max_tokens, temperature)
|
| 22 |
+
return caption
|
| 23 |
|
| 24 |
def generate_caption_vitCoAtt(image):
|
| 25 |
+
caption = ViTCoAtt.CaptionSampler.main(image)
|
| 26 |
+
return caption
|
| 27 |
|
| 28 |
+
def generate_caption_cnnrnn(image):
|
| 29 |
+
# with open('/content/Image_features_ecoder_decoder.pickle', 'rb') as f:
|
| 30 |
+
# Xnet_features = pickle.load(f)
|
| 31 |
+
# image = Xnet_features[image]
|
| 32 |
+
# caption = cnn-rnn.get_result(image)
|
| 33 |
+
caption = ""
|
| 34 |
+
return caption
|
| 35 |
|
| 36 |
|
| 37 |
with gr.Row():
|
|
|
|
| 58 |
return generate_caption_vitgpt(img, max_tokens, temperature)
|
| 59 |
elif model_name == "ViT-CoAttention":
|
| 60 |
return generate_caption_vitCoAtt(img)
|
| 61 |
+
elif model_name == "Baseline Model CNN-RNN":
|
| 62 |
+
print(img)
|
| 63 |
+
return generate_caption_cnnrnn(img)
|
| 64 |
else:
|
| 65 |
return "Caption generation for this model is not yet implemented."
|
| 66 |
|