-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.py
39 lines (33 loc) · 1.29 KB
/
api.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
from flask import Flask
from numpy import random
from dialogue_manager.system import getListenerPredictions, getSpeakerMessage
app = Flask(__name__)
image_set = []
top_scores, top_images = []
curr_image_index = 0
top_counter = 0
@app.route('/get_images')
def get_images():
global curr_image_index, top_scores, top_images, image_set
image_sets = []
with open('./image_file.txt', 'r') as f:
lines = f.readlines()
for line in lines:
image_set = line.split(' ')
image_sets.append(image_set)
n = random.randint(len(image_sets))
image_set = ' '.join(image_sets[n])
curr_image_index = 0
top_scores, top_images = []
return image_set
@app.route('/get_answer/<message>', methods=['GET'])
def get_answer(message):
global curr_image_index, top_scores, top_images, image_set
if message == "Yes":
message = "You have chosen Image number " + str(top_images[curr_image_index] + 1)
elif message == "No":
curr_image_index += 1
message = getSpeakerMessage(image_set, message, top_images[curr_image_index])
else:
top_scores, top_images = getListenerPredictions(image_set, message)
message = "Did you mean " + getSpeakerMessage(image_set, message, top_images[curr_image_index])