Skip to content

Commit

Permalink
flagging dir name
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabd committed Jul 27, 2020
1 parent a7f16bd commit 1f7518d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
19 changes: 17 additions & 2 deletions gradio/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import sys
import weakref
import analytics

import os

PKG_VERSION_URL = "https://gradio.app/api/pkg-version"
analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
Expand All @@ -30,6 +30,8 @@
except requests.ConnectionError:
ip_address = "No internet connection"

FLAGGING_DIRECTORY = 'flagged/'


class Interface:
"""
Expand Down Expand Up @@ -121,6 +123,18 @@ def get_output_instance(iface):
except (ImportError, AttributeError): # If they are using TF >= 2.0 or don't have TF, just ignore this.
pass

if self.allow_flagging:
if self.title is not None:
dir_name = "-".join(self.title.split(" ")) + "-1"
else:
dir_name = "-".join(self.input_interfaces) + "-to-" \
+ "-".join(self.output_interfaces) + "-1"
i = 1
while os.path.exists(FLAGGING_DIRECTORY + dir_name):
i += 1
dir_name = dir_name[:-2] + "-" + str(i)
self.flagging_dir = FLAGGING_DIRECTORY + dir_name

try:
requests.post(analytics_url + 'gradio-initiated-analytics/',
data=data)
Expand All @@ -142,7 +156,8 @@ def get_config_file(self):
"title": self.title,
"description": self.description,
"thumbnail": self.thumbnail,
"allow_screenshot": self.allow_screenshot
"allow_screenshot": self.allow_screenshot,
"allow_flagging": self.allow_flagging
}
try:
param_names = inspect.getfullargspec(self.predict[0])[0]
Expand Down
17 changes: 6 additions & 11 deletions gradio/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import sys
import analytics


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.
TRY_NUM_PORTS = int(os.getenv(
Expand All @@ -36,8 +35,7 @@
ASSOCIATION_PATH_IN_STATIC = "static/apple-app-site-association"
ASSOCIATION_PATH_IN_ROOT = "apple-app-site-association"

FLAGGING_DIRECTORY = 'flagged/'
FLAGGING_FILENAME = 'data.txt'
FLAGGING_FILENAME = 'flagged.txt'
analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
analytics_url = 'https://api.gradio.app/'

Expand Down Expand Up @@ -187,20 +185,17 @@ def do_POST(self):
data_string = self.rfile.read(
int(self.headers["Content-Length"]))
msg = json.loads(data_string)
flag_dir = os.path.join(FLAGGING_DIRECTORY,
str(interface.flag_hash))
os.makedirs(flag_dir, exist_ok=True)
os.makedirs(interface.flagging_dir, exist_ok=True)
output = {'inputs': [interface.input_interfaces[
i].rebuild_flagged(
flag_dir, msg['data']['input_data']) for i
interface.flagging_dir, msg['data']['input_data']) for i
in range(len(interface.input_interfaces))],
'outputs': [interface.output_interfaces[
i].rebuild_flagged(
flag_dir, msg['data']['output_data']) for i
in range(len(interface.output_interfaces))],
'message': msg['data']['message']}
interface.flagging_dir, msg['data']['output_data']) for i
in range(len(interface.output_interfaces))]}

with open(os.path.join(flag_dir, FLAGGING_FILENAME), 'a+') as f:
with open(os.path.join(interface.flagging_dir, FLAGGING_FILENAME), 'a+') as f:
f.write(json.dumps(output))
f.write("\n")

Expand Down
4 changes: 2 additions & 2 deletions gradio/static/css/gradio.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ input.submit:hover {
.flag {
visibility: hidden;
}
.flag.flagged {
background-color: pink;
.flagged {
background-color: pink !important;
}
/* label:hover {
background-color: lightgray;
Expand Down
3 changes: 1 addition & 2 deletions gradio/static/js/all_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ var io_master_template = {
var post_data = {
'data': {
'input_data' : toStringIfObject(this.last_input) ,
'output_data' : toStringIfObject(this.last_output),
'message' : "no-message"
'output_data' : toStringIfObject(this.last_output)
}
}
$.ajax({type: "POST",
Expand Down

0 comments on commit 1f7518d

Please sign in to comment.