Updated alg
This commit is contained in:
parent
af1d8383a9
commit
0a8b117aa8
|
@ -2,13 +2,7 @@ from . import utilities
|
|||
from .utilities import *
|
||||
|
||||
from . import image_tagger
|
||||
from image_tagger import *
|
||||
from .image_tagger import *
|
||||
|
||||
from . import exceptions
|
||||
from exceptions import *
|
||||
|
||||
__all__ = ['utilities',
|
||||
'image_tagger',
|
||||
'exceptions',
|
||||
'Utilities',
|
||||
'CoffeeHouseAlgException']
|
||||
from .exceptions import *
|
|
@ -1,4 +1,2 @@
|
|||
from . import image_tagger
|
||||
from .image_tagger import *
|
||||
|
||||
__all__ = ['image_tagger', 'ImageTagger']
|
|
@ -34,20 +34,16 @@ class ImageTagger:
|
|||
:return:
|
||||
"""
|
||||
headers = {
|
||||
"Accept": "application/json, text/javascript",
|
||||
"Authorization": self.access_key,
|
||||
"Content-Type": "application/json",
|
||||
"Origin": "https://demos.algorithmia.com",
|
||||
"Referer": "https://demos.algorithmia.com/image-tagger",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-site",
|
||||
}
|
||||
payload = {
|
||||
"image": image_content,
|
||||
"numResults": results
|
||||
}
|
||||
headers = Utilities.add_client_headers(headers)
|
||||
headers = Utilities.add_client_headers(headers, True)
|
||||
|
||||
response = requests.post(self.illustration_endpoint, data=json.dumps(payload), headers=headers)
|
||||
j_response = json.loads(response.text)
|
||||
|
@ -65,16 +61,12 @@ class ImageTagger:
|
|||
:return:
|
||||
"""
|
||||
headers = {
|
||||
"Accept": "application/json, text/javascript",
|
||||
"Authorization": self.access_key,
|
||||
"Content-Type": "application/json",
|
||||
"Origin": "https://demos.algorithmia.com",
|
||||
"Referer": "https://demos.algorithmia.com/image-tagger",
|
||||
"Sec-Fetch-Dest": "empty",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"Sec-Fetch-Site": "same-site",
|
||||
"Referer": "https://demos.algorithmia.com/image-tagger"
|
||||
}
|
||||
headers = Utilities.add_client_headers(headers)
|
||||
headers = Utilities.add_client_headers(headers, False)
|
||||
|
||||
response = requests.post(self.inception_endpoint, data=json.dumps(image_content), headers=headers)
|
||||
j_response = json.loads(response.text)
|
||||
|
|
|
@ -45,14 +45,20 @@ class Utilities:
|
|||
return "data:%s;base64,%s" % (mimetype, image_b64content)
|
||||
|
||||
@staticmethod
|
||||
def add_client_headers(headers):
|
||||
def add_client_headers(headers, include_sec=True):
|
||||
"""
|
||||
Adds the required client headers
|
||||
:param include_sec:
|
||||
:param headers:
|
||||
:return:
|
||||
"""
|
||||
headers['Accept'] = 'application/json, text/javascript'
|
||||
headers['Accept-Encoding'] = 'gzip, deflate, br'
|
||||
headers['Accept-Language'] = 'en'
|
||||
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' \
|
||||
'Chrome/80.0.3987.122 Safari/537.36 '
|
||||
headers['Accept-Language'] = 'en-CA,en-US;q=0.7,en;q=0.3'
|
||||
headers['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0'
|
||||
|
||||
if include_sec:
|
||||
headers['Sec-Fetch-Dest'] = 'empty'
|
||||
headers['Sec-Fetch-Mode'] = 'cors'
|
||||
headers['Sec-Fetch-Site'] = 'same-site'
|
||||
return headers
|
||||
|
|
|
@ -2,7 +2,7 @@ from coffeehouse_alg.utilities import Utilities
|
|||
from coffeehouse_alg.image_tagger import ImageTagger
|
||||
|
||||
|
||||
url = "https://cdn4.telesco.pe/file/ETCYVng0VOEczJuIjUbsgzC4a7EOi8wMfwfFBAss_OlKZd822FNiF5Xy5V7MpY0nUvHcBCzDt1MexuBrawuit0WL5HGa0-O5bZXYsBwA5P4QAFKM6VyH0k1G9VbnCn-QiFJ5ipClcP1azPykgcRqDz4d-g_3IHWegBY3wHBD8BHm1T589XhkXbfCl_HN6TJSZ1LIYnoASnN1FF6YDV92UOhMc0-c2FTQkoxx-gGt4A7Vwy821x4-TAd6AlNI_q5NO4NKe047oRlJfm_MCtEsojYGP5tyJKB-xZYm_zRtzriwC0GSJh2zoY_RCv4L-Uudq3GGQ0_8A2OrHCmCNj0AGA.jpg"
|
||||
url = "https://upload.wikimedia.org/wikipedia/commons/9/9f/Gisele_Bundchen_2018_clear_original_%28cropped%29.jpg"
|
||||
|
||||
image_tagger = ImageTagger()
|
||||
image_content = Utilities.process_img_from_url(url)
|
||||
|
|
Loading…
Reference in New Issue