-
Notifications
You must be signed in to change notification settings - Fork 0
/
hqbot.py
54 lines (40 loc) · 1.23 KB
/
hqbot.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
import io
import os
from choose_option import *
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
#from googleapiclient.discovery import build
import webbrowser
from secrets import *
from choose_option import *
import operator
NUM_ANSWERS = 3
# Instantiates a client
client = vision.ImageAnnotatorClient()
def search(filename):
# The name of the image file to annotate
file_path = os.path.join(
os.path.dirname(__file__), "imgs/" + filename)
#"imgs/"+filename)
# 'hqimgs/imageedit_6_8142551098.jpg'
# Loads the image into memory
with io.open(file_path, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
# Performs label detection on the image file
response = client.text_detection(image=image)
texts = response.text_annotations
lines = texts[0].description.split("\n")
lines = lines[::-1]
del lines[0]
answers = []
question = ""
for i in range(0,len(lines)):
if i >= NUM_ANSWERS:
question = lines[i] + " " + question
else:
answers.append(lines[i])
print(question)
print(answers)
choose_option(question, answers)