Spaces:
Running
Running
fix image loading
Browse files- image2text.py +7 -2
- localization.py +7 -1
image2text.py
CHANGED
@@ -9,6 +9,11 @@ import requests
|
|
9 |
import jax
|
10 |
import gc
|
11 |
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def app():
|
14 |
st.title("From Image to Text")
|
@@ -63,7 +68,7 @@ def app():
|
|
63 |
text_embeds.extend(text_encoder(c, model, tokenizer)[0])
|
64 |
|
65 |
text_embeds = jnp.array(text_embeds)
|
66 |
-
response = requests.get(image_url)
|
67 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
68 |
transform = get_image_transform(model.config.vision_config.image_size)
|
69 |
image_embed, _ = image_encoder(transform(image), model)
|
@@ -84,6 +89,6 @@ def app():
|
|
84 |
gc.collect()
|
85 |
|
86 |
elif image_url:
|
87 |
-
response = requests.get(image_url)
|
88 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
89 |
st.image(image)
|
|
|
9 |
import jax
|
10 |
import gc
|
11 |
|
12 |
+
headers = {
|
13 |
+
"User-Agent":
|
14 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
|
15 |
+
}
|
16 |
+
|
17 |
|
18 |
def app():
|
19 |
st.title("From Image to Text")
|
|
|
68 |
text_embeds.extend(text_encoder(c, model, tokenizer)[0])
|
69 |
|
70 |
text_embeds = jnp.array(text_embeds)
|
71 |
+
response = requests.get(image_url, headers=headers, stream=True)
|
72 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
73 |
transform = get_image_transform(model.config.vision_config.image_size)
|
74 |
image_embed, _ = image_encoder(transform(image), model)
|
|
|
89 |
gc.collect()
|
90 |
|
91 |
elif image_url:
|
92 |
+
response = requests.get(image_url, headers=headers, stream=True)
|
93 |
image = Image.open(BytesIO(response.content)).convert("RGB")
|
94 |
st.image(image)
|
localization.py
CHANGED
@@ -13,6 +13,11 @@ import jax
|
|
13 |
import gc
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
16 |
preprocess = transforms.Compose(
|
17 |
[
|
18 |
transforms.ToTensor(),
|
@@ -224,7 +229,8 @@ def app():
|
|
224 |
|
225 |
elif image_url:
|
226 |
image = requests.get(
|
227 |
-
image_url,
|
|
|
228 |
stream=True,
|
229 |
).raw
|
230 |
image = Image.open(image).convert("RGB")
|
|
|
13 |
import gc
|
14 |
|
15 |
|
16 |
+
headers = {
|
17 |
+
"User-Agent":
|
18 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
|
19 |
+
}
|
20 |
+
|
21 |
preprocess = transforms.Compose(
|
22 |
[
|
23 |
transforms.ToTensor(),
|
|
|
229 |
|
230 |
elif image_url:
|
231 |
image = requests.get(
|
232 |
+
image_url,
|
233 |
+
headers=headers,
|
234 |
stream=True,
|
235 |
).raw
|
236 |
image = Image.open(image).convert("RGB")
|