forked from Sachin-A/recaptcha-breaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimageAnnotation.py
75 lines (58 loc) · 1.84 KB
/
imageAnnotation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from config import keys
from requests import get
from selenium import webdriver
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
grisUrl="https://images.google.com"
def gris(args):
driver = args[0]
filepath = args[1]
hint = args[2]
if not os.path.isfile(filepath):
return "z"
driver.get(grisUrl)
# Click on file upload icon
driver.find_element_by_id("qbi").click()
# Upload file through key press simulation
driver.find_element_by_id("qbfile").send_keys(filepath)
# Wait for search to complete and suggestion to appear
try:
WebDriverWait(driver, 20).until(
EC.presence_of_element_located(
(By.CLASS_NAME, '_gUb')
)
)
except:
return "z"
tag = driver.find_elements_by_class_name("_gUb")[0].text
score = sss(hint, tag)
return (tag, score)
def clarifai(args):
driver = args[0]
filepath = args[1]
hint = args[2]
app = ClarifaiApp(api_key=keys['clarifai_key'])
model = app.models.get("general-v1.3")
image = ClImage(file_obj=open(filepath, 'rb'))
response = model.predict([image])
tags = ''
for x in response['outputs'][0]['data']['concepts']:
print x
tags += ' '
tags += x['name']
#return tags
#tags = driver.find_elements_by_class_name("_gUb")[0].text
score = sss(hint, tags)
return (tags, score)
sss_url = "http://swoogle.umbc.edu/SimService/GetSimilarity"
def sss(s1, s2, type='relation', corpus='webbase'):
try:
response = get(sss_url, params={'operation':'api','phrase1':s1,'phrase2':s2,'type':type,'corpus':corpus})
return float(response.text.strip())
except:
print 'Error in getting similarity for %s: %s' % ((s1,s2), response)
return 0.0