Skip to content

Commit

Permalink
flagging log.csv, fixed json error
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabd committed Aug 7, 2020
1 parent 4b69268 commit 23e7688
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions gradio.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gradio/outputs.py
gradio/preprocessing_utils.py
gradio/strings.py
gradio/tunneling.py
gradio/utils.py
gradio.egg-info/PKG-INFO
gradio.egg-info/SOURCES.txt
gradio.egg-info/dependency_links.txt
Expand Down
28 changes: 22 additions & 6 deletions gradio/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
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.
Expand Down Expand Up @@ -183,18 +185,32 @@ def do_POST(self):
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))

Expand Down
3 changes: 2 additions & 1 deletion gradio/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def rebuild(self, dir, data):
"""
Default rebuild method for label
"""
return json.loads(data)
# return json.loads(data)
return data

class Image(AbstractOutput):
'''
Expand Down
4 changes: 2 additions & 2 deletions gradio/static/js/all_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 23e7688

Please sign in to comment.