Esempio n. 1
0
url = args.path

domain = "landmarks"
language = "en"

if is_url(url):
    try:
        headers = {'User-Agent': 'Mozilla/5.0'}
        req = urllib.request.Request(url, headers=headers)

        if urllib.request.urlopen(req).status == 200:
            try:
                analysis = client.analyze_image_by_domain(
                    domain, url, language)
            except Exception as e:
                catch_exception(e, url)

    except urllib.error.URLError:
        sys.exit("Error: The URL does not appear to exist. Please check.\n"
                 f"{url}")

else:
    path = os.path.join(get_cmd_cwd(), url)
    with open(path, 'rb') as fstream:
        try:
            analysis = client.analyze_image_by_domain_in_stream(
                domain, fstream, language)
        except Exception as e:
            catch_exception(e, path)

for landmark in analysis.result["landmarks"]:
Esempio n. 2
0
Filename: {}""".format(url0, url1, url2),
    begin="\n")

mlpreview(url)
mlask(end="\n")

mlcat(
    "Tag Analysis",
    """We list the tags for the image together with a measure of confidence.
""")

try:
    image_analysis = client.analyze_image(
        url, visual_features=[VisualFeatureTypes.tags])
except Exception as e:
    catch_exception(e, url)

for tag in image_analysis.tags:
    if tag.confidence > 0.2:
        print("Confidence: {:4.2f} Tag: {}".format(round(tag.confidence, 2),
                                                   tag.name))

mlask(begin="\n", end="\n")
mlcat(
    "Subject Domain List",
    """Various subject domains can be used to analyze images. The domains include
celebrities and landmarks.
""")

models = client.list_models()
Esempio n. 3
0
from redis import Redis
from django.conf import settings
from utils import catch_exception
from redis.exceptions import RedisError
from inspect import ismethod
from django.utils.functional import update_wrapper

REDIS_HOST = getattr(settings, 'REDIS_HOST', 'localhost')
REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379)
REDIS_DB = getattr(settings, 'REDIS_DB', 0)
IGNORE_REDIS = True
# IGNORE_REDIS = getattr(settings, 'IGNORE_REDIS', False) and settings.DEBUG

default_connection = Redis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)

catch_exception_dec = catch_exception(RedisError, u'Redis error', '')

class RedisCounterField(Exception):
    pass

class RedisCounterFieldNotUnique(RedisCounterField):
    pass

class RedisCounterFieldNoSettings(RedisCounterField):
    pass

def redis_key_wrapper(func, key):
    def wrapper(*args, **kwargs):
        if IGNORE_REDIS:
            return
        return func(key, *args, **kwargs)