Spaces:
Running
Running
Update from beta_columns to columns
Browse files- examples.py +5 -6
- image2text.py +10 -4
- text2image.py +11 -7
examples.py
CHANGED
|
@@ -21,7 +21,7 @@ def app():
|
|
| 21 |
st.markdown("*A couple*")
|
| 22 |
st.image("static/img/examples/couple_0.jpeg", use_column_width=True)
|
| 23 |
|
| 24 |
-
col1, col2 = st.
|
| 25 |
col1.subheader("Una coppia con il tramonto sullo sfondo")
|
| 26 |
col1.markdown("*A couple with the sunset in the background*")
|
| 27 |
col1.image("static/img/examples/couple_1.jpeg", use_column_width=True)
|
|
@@ -34,7 +34,7 @@ def app():
|
|
| 34 |
st.markdown("*A couple walking on the beach at sunset*")
|
| 35 |
st.image("static/img/examples/couple_3.jpeg", use_column_width=True)
|
| 36 |
|
| 37 |
-
col1, col2 = st.
|
| 38 |
col1.subheader("Un bambino con un biberon")
|
| 39 |
col1.markdown("*A baby with a bottle*")
|
| 40 |
col1.image("static/img/examples/bambino_biberon.jpeg", use_column_width=True)
|
|
@@ -48,7 +48,7 @@ def app():
|
|
| 48 |
st.markdown("### 2. Dresses")
|
| 49 |
st.markdown("These examples were taken from the Unsplash dataset.")
|
| 50 |
|
| 51 |
-
col1, col2 = st.
|
| 52 |
col1.subheader("Un vestito primaverile")
|
| 53 |
col1.markdown("*A dress for the spring*")
|
| 54 |
col1.image("static/img/examples/vestito1.png", use_column_width=True)
|
|
@@ -60,7 +60,7 @@ def app():
|
|
| 60 |
st.markdown("### 3. Chairs with different styles")
|
| 61 |
st.markdown("These examples were taken from the CC dataset.")
|
| 62 |
|
| 63 |
-
col1, col2 = st.
|
| 64 |
col1.subheader("Una sedia semplice")
|
| 65 |
col1.markdown("*A simple chair*")
|
| 66 |
col1.image("static/img/examples/sedia_semplice.jpeg", use_column_width=True)
|
|
@@ -69,7 +69,7 @@ def app():
|
|
| 69 |
col2.markdown("*A royal chair*")
|
| 70 |
col2.image("static/img/examples/sedia_regale.jpeg", use_column_width=True)
|
| 71 |
|
| 72 |
-
col1, col2 = st.
|
| 73 |
col1.subheader("Una sedia moderna")
|
| 74 |
col1.markdown("*A modern chair*")
|
| 75 |
col1.image("static/img/examples/sedia_moderna.jpeg", use_column_width=True)
|
|
@@ -96,7 +96,6 @@ def app():
|
|
| 96 |
st.markdown("*A shark / a horse*")
|
| 97 |
st.image("static/img/examples/cavallo_squalo.png", use_column_width=True)
|
| 98 |
|
| 99 |
-
|
| 100 |
st.markdown("## Image Classification")
|
| 101 |
st.markdown(
|
| 102 |
"We report this cool example provided by the "
|
|
|
|
| 21 |
st.markdown("*A couple*")
|
| 22 |
st.image("static/img/examples/couple_0.jpeg", use_column_width=True)
|
| 23 |
|
| 24 |
+
col1, col2 = st.columns(2)
|
| 25 |
col1.subheader("Una coppia con il tramonto sullo sfondo")
|
| 26 |
col1.markdown("*A couple with the sunset in the background*")
|
| 27 |
col1.image("static/img/examples/couple_1.jpeg", use_column_width=True)
|
|
|
|
| 34 |
st.markdown("*A couple walking on the beach at sunset*")
|
| 35 |
st.image("static/img/examples/couple_3.jpeg", use_column_width=True)
|
| 36 |
|
| 37 |
+
col1, col2 = st.columns(2)
|
| 38 |
col1.subheader("Un bambino con un biberon")
|
| 39 |
col1.markdown("*A baby with a bottle*")
|
| 40 |
col1.image("static/img/examples/bambino_biberon.jpeg", use_column_width=True)
|
|
|
|
| 48 |
st.markdown("### 2. Dresses")
|
| 49 |
st.markdown("These examples were taken from the Unsplash dataset.")
|
| 50 |
|
| 51 |
+
col1, col2 = st.columns(2)
|
| 52 |
col1.subheader("Un vestito primaverile")
|
| 53 |
col1.markdown("*A dress for the spring*")
|
| 54 |
col1.image("static/img/examples/vestito1.png", use_column_width=True)
|
|
|
|
| 60 |
st.markdown("### 3. Chairs with different styles")
|
| 61 |
st.markdown("These examples were taken from the CC dataset.")
|
| 62 |
|
| 63 |
+
col1, col2 = st.columns(2)
|
| 64 |
col1.subheader("Una sedia semplice")
|
| 65 |
col1.markdown("*A simple chair*")
|
| 66 |
col1.image("static/img/examples/sedia_semplice.jpeg", use_column_width=True)
|
|
|
|
| 69 |
col2.markdown("*A royal chair*")
|
| 70 |
col2.image("static/img/examples/sedia_regale.jpeg", use_column_width=True)
|
| 71 |
|
| 72 |
+
col1, col2 = st.columns(2)
|
| 73 |
col1.subheader("Una sedia moderna")
|
| 74 |
col1.markdown("*A modern chair*")
|
| 75 |
col1.image("static/img/examples/sedia_moderna.jpeg", use_column_width=True)
|
|
|
|
| 96 |
st.markdown("*A shark / a horse*")
|
| 97 |
st.image("static/img/examples/cavallo_squalo.png", use_column_width=True)
|
| 98 |
|
|
|
|
| 99 |
st.markdown("## Image Classification")
|
| 100 |
st.markdown(
|
| 101 |
"We report this cool example provided by the "
|
image2text.py
CHANGED
|
@@ -34,7 +34,7 @@ def app():
|
|
| 34 |
|
| 35 |
MAX_CAP = 4
|
| 36 |
|
| 37 |
-
col1, col2 = st.
|
| 38 |
|
| 39 |
with col2:
|
| 40 |
captions_count = st.selectbox(
|
|
@@ -62,7 +62,10 @@ def app():
|
|
| 62 |
text_embeds.extend(text_encoder(c, model, tokenizer))
|
| 63 |
|
| 64 |
text_embeds = jnp.array(text_embeds)
|
| 65 |
-
image_raw = requests.get(
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
image = Image.open(image_raw).convert("RGB")
|
| 68 |
transform = get_image_transform(model.config.vision_config.image_size)
|
|
@@ -75,7 +78,7 @@ def app():
|
|
| 75 |
|
| 76 |
chart_data = pd.Series(cos_similarities[0], index=captions)
|
| 77 |
|
| 78 |
-
col1, col2 = st.
|
| 79 |
with col1:
|
| 80 |
st.bar_chart(chart_data)
|
| 81 |
|
|
@@ -84,6 +87,9 @@ def app():
|
|
| 84 |
gc.collect()
|
| 85 |
|
| 86 |
elif image_url:
|
| 87 |
-
image_raw = requests.get(
|
|
|
|
|
|
|
|
|
|
| 88 |
image = Image.open(image_raw).convert("RGB")
|
| 89 |
st.image(image)
|
|
|
|
| 34 |
|
| 35 |
MAX_CAP = 4
|
| 36 |
|
| 37 |
+
col1, col2 = st.columns([3, 1])
|
| 38 |
|
| 39 |
with col2:
|
| 40 |
captions_count = st.selectbox(
|
|
|
|
| 62 |
text_embeds.extend(text_encoder(c, model, tokenizer))
|
| 63 |
|
| 64 |
text_embeds = jnp.array(text_embeds)
|
| 65 |
+
image_raw = requests.get(
|
| 66 |
+
image_url,
|
| 67 |
+
stream=True,
|
| 68 |
+
).raw
|
| 69 |
|
| 70 |
image = Image.open(image_raw).convert("RGB")
|
| 71 |
transform = get_image_transform(model.config.vision_config.image_size)
|
|
|
|
| 78 |
|
| 79 |
chart_data = pd.Series(cos_similarities[0], index=captions)
|
| 80 |
|
| 81 |
+
col1, col2 = st.columns(2)
|
| 82 |
with col1:
|
| 83 |
st.bar_chart(chart_data)
|
| 84 |
|
|
|
|
| 87 |
gc.collect()
|
| 88 |
|
| 89 |
elif image_url:
|
| 90 |
+
image_raw = requests.get(
|
| 91 |
+
image_url,
|
| 92 |
+
stream=True,
|
| 93 |
+
).raw
|
| 94 |
image = Image.open(image_raw).convert("RGB")
|
| 95 |
st.image(image)
|
text2image.py
CHANGED
|
@@ -100,8 +100,8 @@ def get_image_transform(image_size):
|
|
| 100 |
|
| 101 |
headers = {
|
| 102 |
#'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
|
| 103 |
-
|
| 104 |
-
|
| 105 |
}
|
| 106 |
|
| 107 |
|
|
@@ -131,11 +131,11 @@ def app():
|
|
| 131 |
"Un fiore giallo",
|
| 132 |
"Un fiore blu",
|
| 133 |
"Una coppia in montagna",
|
| 134 |
-
"Una coppia al tramonto"
|
| 135 |
]
|
| 136 |
sugg_idx = -1
|
| 137 |
|
| 138 |
-
col1, col2, col3, col4, col5, col6 = st.
|
| 139 |
with col1:
|
| 140 |
if st.button(suggestions[0]):
|
| 141 |
sugg_idx = 0
|
|
@@ -155,7 +155,7 @@ def app():
|
|
| 155 |
if st.button(suggestions[5]):
|
| 156 |
sugg_idx = 5
|
| 157 |
|
| 158 |
-
col1, col2 = st.
|
| 159 |
with col1:
|
| 160 |
query = st.text_input("... or insert an Italian query text")
|
| 161 |
with col2:
|
|
@@ -194,13 +194,17 @@ def app():
|
|
| 194 |
if dataset_name == "Unsplash":
|
| 195 |
st.image(image_url)
|
| 196 |
elif dataset_name == "CC":
|
| 197 |
-
image_raw = requests.get(
|
|
|
|
|
|
|
| 198 |
image = Image.open(image_raw).convert("RGB")
|
| 199 |
st.image(image, use_column_width=True)
|
| 200 |
break
|
| 201 |
except (UnidentifiedImageError) as e:
|
| 202 |
if i == N - 1:
|
| 203 |
-
st.text(
|
|
|
|
|
|
|
| 204 |
|
| 205 |
gc.collect()
|
| 206 |
|
|
|
|
| 100 |
|
| 101 |
headers = {
|
| 102 |
#'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
|
| 103 |
+
"User-Agent": "Googlebot-Image/1.0", # Pretend to be googlebot
|
| 104 |
+
"X-Forwarded-For": "64.18.15.200",
|
| 105 |
}
|
| 106 |
|
| 107 |
|
|
|
|
| 131 |
"Un fiore giallo",
|
| 132 |
"Un fiore blu",
|
| 133 |
"Una coppia in montagna",
|
| 134 |
+
"Una coppia al tramonto",
|
| 135 |
]
|
| 136 |
sugg_idx = -1
|
| 137 |
|
| 138 |
+
col1, col2, col3, col4, col5, col6 = st.columns([1, 1, 1.2, 1.2, 1.4, 1.4])
|
| 139 |
with col1:
|
| 140 |
if st.button(suggestions[0]):
|
| 141 |
sugg_idx = 0
|
|
|
|
| 155 |
if st.button(suggestions[5]):
|
| 156 |
sugg_idx = 5
|
| 157 |
|
| 158 |
+
col1, col2 = st.columns([3, 1])
|
| 159 |
with col1:
|
| 160 |
query = st.text_input("... or insert an Italian query text")
|
| 161 |
with col2:
|
|
|
|
| 194 |
if dataset_name == "Unsplash":
|
| 195 |
st.image(image_url)
|
| 196 |
elif dataset_name == "CC":
|
| 197 |
+
image_raw = requests.get(
|
| 198 |
+
image_url, stream=True, allow_redirects=True, headers=headers
|
| 199 |
+
).raw
|
| 200 |
image = Image.open(image_raw).convert("RGB")
|
| 201 |
st.image(image, use_column_width=True)
|
| 202 |
break
|
| 203 |
except (UnidentifiedImageError) as e:
|
| 204 |
if i == N - 1:
|
| 205 |
+
st.text(
|
| 206 |
+
f"Tried to show {N} different image URLS but none of them were reachabele.\nMaybe try a different query?"
|
| 207 |
+
)
|
| 208 |
|
| 209 |
gc.collect()
|
| 210 |
|