Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flagging #37

Merged
merged 8 commits into from
Jul 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

@abidlabs abidlabs Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more elegant to come up with the directory name in 1 step rather than 2. So something like:

base_dir_name = "-".join(self.title.split(" "))
index = 0
while os.path.exists(os.path.join(FLAGGING_DIRECTORY, base_dir_name , index)):
    index += 1
dir_name = os.path.join(FLAGGING_DIRECTORY, base_dir_name , index)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear join will add a / separator so it would be "FLAGGING_DIRECTORY/base_dir_name/index". I thought it would be too nested so I wrote similar code that produces "FLAGGING_DIRECTORY/base_dir_name_index"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do you think nested is better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, no I think what you wrote is better

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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this is fine for the default (although I would have probably used something like log.txt), but consider allowing user to override

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to log.txt, but haven't added it as a parameter. We're starting to have too many parameters in Interface right now. Do you think that's an annoyance?

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