flagging dir name

This commit is contained in:
aliabd 2020-07-27 15:24:45 -07:00
parent a7f16bddf3
commit 1f7518dc58
4 changed files with 26 additions and 17 deletions

View File

@ -20,7 +20,7 @@ from IPython import get_ipython
import sys
import weakref
import analytics
import os
PKG_VERSION_URL = "https://gradio.app/api/pkg-version"
analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
@ -30,6 +30,8 @@ try:
except requests.ConnectionError:
ip_address = "No internet connection"
FLAGGING_DIRECTORY = 'flagged/'
class Interface:
"""
@ -121,6 +123,18 @@ class Interface:
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)
@ -142,7 +156,8 @@ class Interface:
"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]

View File

@ -17,7 +17,6 @@ import requests
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(
@ -36,8 +35,7 @@ CONFIG_FILE = "static/config.json"
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/'
@ -187,20 +185,17 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
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")

View File

@ -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;

View File

@ -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",