moved flag directory to temp directory

This commit is contained in:
Abubakar Abid 2019-05-13 23:07:16 -07:00
parent 71316b23f0
commit 422a8f7704

View File

@ -35,8 +35,8 @@ CONFIG_FILE = "static/config.json"
ASSOCIATION_PATH_IN_STATIC = "static/apple-app-site-association" ASSOCIATION_PATH_IN_STATIC = "static/apple-app-site-association"
ASSOCIATION_PATH_IN_ROOT = "apple-app-site-association" ASSOCIATION_PATH_IN_ROOT = "apple-app-site-association"
FLAGGING_DIRECTORY = 'gradio-flagged/{}' FLAGGING_DIRECTORY = 'static/flagged/'
FLAGGING_FILENAME = 'gradio-flagged.txt' FLAGGING_FILENAME = 'data.txt'
def build_template(temp_dir, input_interface, output_interface): def build_template(temp_dir, input_interface, output_interface):
@ -174,7 +174,6 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
if interface.saliency is not None: if interface.saliency is not None:
import numpy as np import numpy as np
saliency = interface.saliency(interface.model_obj, processed_input, prediction) saliency = interface.saliency(interface.model_obj, processed_input, prediction)
np.save('sal2.npy', saliency)
output['saliency'] = saliency.tolist() output['saliency'] = saliency.tolist()
# Prepare return json dictionary. # Prepare return json dictionary.
@ -184,7 +183,7 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
self._set_headers() self._set_headers()
data_string = self.rfile.read(int(self.headers["Content-Length"])) data_string = self.rfile.read(int(self.headers["Content-Length"]))
msg = json.loads(data_string) msg = json.loads(data_string)
flag_dir = FLAGGING_DIRECTORY.format(interface.hash) flag_dir = os.path.join(directory_to_serve, FLAGGING_DIRECTORY)
os.makedirs(flag_dir, exist_ok=True) os.makedirs(flag_dir, exist_ok=True)
output = {'input': interface.input_interface.rebuild_flagged(flag_dir, msg), output = {'input': interface.input_interface.rebuild_flagged(flag_dir, msg),
'output': interface.output_interface.rebuild_flagged(flag_dir, msg), 'output': interface.output_interface.rebuild_flagged(flag_dir, msg),
@ -193,7 +192,6 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
f.write(json.dumps(output)) f.write(json.dumps(output))
f.write("\n") f.write("\n")
#TODO(abidlabs): clean this up #TODO(abidlabs): clean this up
elif self.path == "/api/auto/rotation": elif self.path == "/api/auto/rotation":
from gradio import validation_data, preprocessing_utils from gradio import validation_data, preprocessing_utils
@ -203,8 +201,10 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
data_string = self.rfile.read(int(self.headers["Content-Length"])) data_string = self.rfile.read(int(self.headers["Content-Length"]))
msg = json.loads(data_string) msg = json.loads(data_string)
img_orig = preprocessing_utils.encoding_to_image(msg["data"]) img_orig = preprocessing_utils.encoding_to_image(msg["data"])
img_orig = img_orig.convert('RGB')
img_orig = img_orig.resize((224, 224))
flag_dir = FLAGGING_DIRECTORY.format(interface.hash) flag_dir = os.path.join(directory_to_serve, FLAGGING_DIRECTORY)
os.makedirs(flag_dir, exist_ok=True) os.makedirs(flag_dir, exist_ok=True)
for deg in range(-180, 180+45, 45): for deg in range(-180, 180+45, 45):
@ -233,9 +233,11 @@ def serve_files_in_background(interface, port, directory_to_serve=None):
data_string = self.rfile.read(int(self.headers["Content-Length"])) data_string = self.rfile.read(int(self.headers["Content-Length"]))
msg = json.loads(data_string) msg = json.loads(data_string)
img_orig = preprocessing_utils.encoding_to_image(msg["data"]) img_orig = preprocessing_utils.encoding_to_image(msg["data"])
img_orig = img_orig.convert('RGB')
img_orig = img_orig.resize((224, 224))
enhancer = ImageEnhance.Brightness(img_orig) enhancer = ImageEnhance.Brightness(img_orig)
flag_dir = FLAGGING_DIRECTORY.format(interface.hash) flag_dir = os.path.join(directory_to_serve, FLAGGING_DIRECTORY)
os.makedirs(flag_dir, exist_ok=True) os.makedirs(flag_dir, exist_ok=True)
for i in range(9): for i in range(9):