gchhablani commited on
Commit
3f280c5
1 Parent(s): 8120e79

Add image URL option in MLM

Browse files
Files changed (1) hide show
  1. apps/mlm.py +17 -1
apps/mlm.py CHANGED
@@ -13,7 +13,8 @@ import os
13
  import matplotlib.pyplot as plt
14
  from mtranslate import translate
15
  from .utils import read_markdown
16
-
 
17
  from .model.flax_clip_vision_bert.modeling_clip_vision_bert import (
18
  FlaxCLIPVisionBertForMaskedLM,
19
  )
@@ -63,6 +64,7 @@ def app(state):
63
  with st.spinner("Loading model..."):
64
  mlm_state.mlm_model = load_model(mlm_checkpoints[0])
65
 
 
66
  if st.button(
67
  "Get a random example",
68
  help="Get a random example from the 100 `seeded` image-text pairs.",
@@ -79,6 +81,20 @@ def app(state):
79
  image = plt.imread(image_path)
80
  mlm_state.mlm_image = image
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  transformed_image = get_transformed_image(mlm_state.mlm_image)
83
 
84
  new_col1, new_col2 = st.beta_columns([5, 5])
 
13
  import matplotlib.pyplot as plt
14
  from mtranslate import translate
15
  from .utils import read_markdown
16
+ import requests
17
+ from PIL import Image
18
  from .model.flax_clip_vision_bert.modeling_clip_vision_bert import (
19
  FlaxCLIPVisionBertForMaskedLM,
20
  )
 
64
  with st.spinner("Loading model..."):
65
  mlm_state.mlm_model = load_model(mlm_checkpoints[0])
66
 
67
+
68
  if st.button(
69
  "Get a random example",
70
  help="Get a random example from the 100 `seeded` image-text pairs.",
 
81
  image = plt.imread(image_path)
82
  mlm_state.mlm_image = image
83
 
84
+ st.write("OR")
85
+
86
+ query1 = st.text_input(
87
+ "Enter a URL to an image",
88
+ value="http://images.cocodataset.org/val2017/000000039769.jpg",
89
+ )
90
+ if st.button("Use this URL"):
91
+ image_data = requests.get(query1, stream=True).raw
92
+ image = np.asarray(Image.open(image_data))
93
+ print(image.shape)
94
+ mlm_state.mlm_image = image
95
+
96
+
97
+
98
  transformed_image = get_transformed_image(mlm_state.mlm_image)
99
 
100
  new_col1, new_col2 = st.beta_columns([5, 5])