diff --git a/gradio/networking.py b/gradio/networking.py index 1c013b193a..4cf0072ae9 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -16,6 +16,8 @@ from shutil import copyfile import requests import sys import analytics +import csv + INITIAL_PORT_VALUE = int(os.getenv( 'GRADIO_SERVER_PORT', "7860")) # The http server will try to open on port 7860. If not available, 7861, 7862, etc. @@ -183,18 +185,32 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n os.makedirs(interface.flagging_dir, exist_ok=True) output = {'inputs': [interface.input_interfaces[ i].rebuild( - interface.flagging_dir, msg['data']['input_data']) for i + interface.flagging_dir, msg['data']['input_data'][i]) for i in range(len(interface.input_interfaces))], 'outputs': [interface.output_interfaces[ i].rebuild( - interface.flagging_dir, msg['data']['output_data']) for i + interface.flagging_dir, msg['data']['output_data'][i]) + for i in range(len(interface.output_interfaces))]} - with open("{}/log.txt".format(interface.flagging_dir), - 'a+') as f: - f.write(json.dumps(output)) - f.write("\n") + log_fp = "{}/log.csv".format(interface.flagging_dir) + is_new = not os.path.exists(log_fp) + + with open(log_fp, "a") as csvfile: + headers = ["input_{}".format(i) for i in range(len( + output["inputs"]))] + ["output_{}".format(i) for i in + range(len(output["outputs"]))] + writer = csv.DictWriter(csvfile, delimiter=',', + lineterminator='\n', + fieldnames=headers) + if is_new: + writer.writeheader() + + writer.writerow( + dict(zip(headers, output["inputs"] + + output["outputs"])) + ) else: self.send_error(404, 'Path not found: {}'.format(self.path)) diff --git a/gradio/outputs.py b/gradio/outputs.py index 071fc384e2..c00cea639c 100644 --- a/gradio/outputs.py +++ b/gradio/outputs.py @@ -114,7 +114,8 @@ class Label(OutputComponent): """ Default rebuild method for label """ - return json.loads(data) + # return json.loads(data) + return data class Image(OutputComponent): ''' diff --git a/gradio/static/js/all_io.js b/gradio/static/js/all_io.js index 23978901ce..0bdb9c032a 100644 --- a/gradio/static/js/all_io.js +++ b/gradio/static/js/all_io.js @@ -59,8 +59,8 @@ var io_master_template = { flag: function() { var post_data = { 'data': { - 'input_data' : toStringIfObject(this.last_input) , - 'output_data' : toStringIfObject(this.last_output) + 'input_data' : this.last_input , + 'output_data' : this.last_output } } $.ajax({type: "POST", diff --git a/gradio/utils.py b/gradio/utils.py index a3d56fa9fe..dd0610cb03 100644 --- a/gradio/utils.py +++ b/gradio/utils.py @@ -24,7 +24,8 @@ def colab_check(): is_colab = False try: # Check if running interactively using ipython. from_ipynb = get_ipython() - if "google.colab" in str(from_ipynb): + if "google.colab" in str(from_ipynb) or "ipykernel" in str( + from_ipynb): is_colab = True except NameError: error_analytics("NameError", analytics_url)