AyushChothe
commited on
Commit
·
3eb2415
1
Parent(s):
6a28ae4
Done
Browse files- pipeline.py +7 -21
- requirements.txt +1 -2
pipeline.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
-
import asyncio
|
2 |
-
from io import BytesIO
|
3 |
from typing import List, Union
|
|
|
4 |
|
5 |
-
import aiohttp
|
6 |
import numpy as np
|
7 |
from fashion_clip.fashion_clip import FashionCLIP
|
8 |
from PIL import Image
|
@@ -12,18 +10,15 @@ class PreTrainedPipeline:
|
|
12 |
def __init__(self, path=""):
|
13 |
self.model = FashionCLIP("fashion-clip")
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
return image
|
19 |
|
20 |
-
|
21 |
if isinstance(inputs, str):
|
22 |
inputs = [inputs]
|
23 |
|
24 |
-
|
25 |
-
tasks = [self._download_image(session, url) for url in set(inputs)]
|
26 |
-
images = await asyncio.gather(*tasks)
|
27 |
|
28 |
# Encode the image to generate the embedding
|
29 |
embeddings = self.model.encode_images(images, batch_size=1)
|
@@ -40,14 +35,5 @@ class PreTrainedPipeline:
|
|
40 |
Return:
|
41 |
A :obj:`list` of floats: The features computed by the model.
|
42 |
"""
|
43 |
-
|
44 |
-
embedding = loop.run_until_complete(self.process(inputs=inputs))
|
45 |
-
loop.close()
|
46 |
return embedding
|
47 |
-
|
48 |
-
|
49 |
-
print(
|
50 |
-
PreTrainedPipeline().__call__(
|
51 |
-
inputs="https://images.unsplash.com/photo-1575936123452-b67c3203c357?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8Mnx8aW1hZ2V8ZW58MHx8MHx8fDA%3D&w=1000&q=80"
|
52 |
-
)
|
53 |
-
)
|
|
|
|
|
|
|
1 |
from typing import List, Union
|
2 |
+
from urllib.request import urlopen
|
3 |
|
|
|
4 |
import numpy as np
|
5 |
from fashion_clip.fashion_clip import FashionCLIP
|
6 |
from PIL import Image
|
|
|
10 |
def __init__(self, path=""):
|
11 |
self.model = FashionCLIP("fashion-clip")
|
12 |
|
13 |
+
def _download_image(self, url) -> Image:
|
14 |
+
image = Image.open(urlopen(url))
|
15 |
+
return image
|
|
|
16 |
|
17 |
+
def process(self, inputs: Union[str, List[str]]) -> List[float]:
|
18 |
if isinstance(inputs, str):
|
19 |
inputs = [inputs]
|
20 |
|
21 |
+
images = [self._download_image(url) for url in set(inputs)]
|
|
|
|
|
22 |
|
23 |
# Encode the image to generate the embedding
|
24 |
embeddings = self.model.encode_images(images, batch_size=1)
|
|
|
35 |
Return:
|
36 |
A :obj:`list` of floats: The features computed by the model.
|
37 |
"""
|
38 |
+
embedding = self.process(inputs=inputs)
|
|
|
|
|
39 |
return embedding
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,3 +1,2 @@
|
|
1 |
fashion-clip==0.2.1
|
2 |
-
Pillow==10.0.0
|
3 |
-
aiohttp==3.8.5
|
|
|
1 |
fashion-clip==0.2.1
|
2 |
+
Pillow==10.0.0
|
|