From 6386544d1f774740e30b0115da45b6f449a4718d Mon Sep 17 00:00:00 2001 From: aliabd Date: Wed, 10 Jun 2020 02:34:24 -0700 Subject: [PATCH] changed all f-strings to .format --- build-interface.py | 2 +- gradio/inputs.py | 20 ++++++++++---------- gradio/interface.py | 9 +++++---- gradio/networking.py | 8 +++++--- gradio/outputs.py | 5 +++-- gradio/tunneling.py | 22 +++++++++++++--------- screenshots/.image_interface.png.icloud | Bin 0 -> 171 bytes web/img/.cheetah-clean.png.icloud | Bin 0 -> 169 bytes 8 files changed, 37 insertions(+), 29 deletions(-) create mode 100644 screenshots/.image_interface.png.icloud create mode 100644 web/img/.cheetah-clean.png.icloud diff --git a/build-interface.py b/build-interface.py index c2376def13..d53695fa21 100644 --- a/build-interface.py +++ b/build-interface.py @@ -32,7 +32,7 @@ def launch_interface(args): pass def service_shutdown(signum, frame): - print('Shutting server down due to signal %d' % signum) + print('Shutting server down due to signal {}'.format(signum)) httpd.shutdown() raise ServiceExit diff --git a/gradio/inputs.py b/gradio/inputs.py index baaf7700b0..be173e7a6f 100644 --- a/gradio/inputs.py +++ b/gradio/inputs.py @@ -125,8 +125,8 @@ class Sketchpad(AbstractInput): im = preprocessing_utils.decode_base64_to_image(msg) timestamp = time.time()*1000 - filename = f'input_{timestamp}.png' - im.save(f'{dir}/{filename}', 'PNG') + filename = 'input_{}.png'.format(timestamp) + im.save('{}/{}'.format(dir, filename), 'PNG') return filename def get_sample_inputs(self): @@ -171,8 +171,8 @@ class Webcam(AbstractInput): inp = msg['data']['input'] im = preprocessing_utils.decode_base64_to_image(inp) timestamp = time.time()*1000 - filename = f'input_{timestamp}.png' - im.save(f'{dir}/{filename}', 'PNG') + filename = 'input_{}.png'.format(timestamp) + im.save('{}/{}'.format(dir, filename), 'PNG') return filename @@ -198,8 +198,8 @@ class Textbox(AbstractInput): Default rebuild method for text saves it .txt file """ timestamp = time.time()*1000 - filename = f'input_{timestamp}' - with open(f'{dir}/{filename}.txt','w') as f: + filename = 'input_{}'.format(timestamp) + with open('{}/{}.txt'.format(dir, filename),'w') as f: f.write(msg) return filename @@ -252,8 +252,8 @@ class ImageUpload(AbstractInput): """ im = preprocessing_utils.decode_base64_to_image(msg) timestamp = time.time()*1000 - filename = f'input_{timestamp}.png' - im.save(f'{dir}/{filename}', 'PNG') + filename = 'input_{}.png'.format(timestamp) + im.save('{}/{}'.format(dir, filename), 'PNG') return filename # TODO(abidlabs): clean this up @@ -261,8 +261,8 @@ class ImageUpload(AbstractInput): """ """ timestamp = time.time()*1000 - filename = f'input_{timestamp}.png' - img.save(f'{dir}/{filename}', 'PNG') + filename = 'input_{}.png'.format(timestamp) + img.save('{}/{}'.format(dir, filename), 'PNG') return filename diff --git a/gradio/interface.py b/gradio/interface.py index 6fbd4be638..1a6d7aa469 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -191,7 +191,7 @@ class Interface: for m, msg in enumerate(validation_inputs): if self.verbose: print( - f"Validating samples: {m+1}/{n} [" + "Validating samples: {}/{} [".format(m+1, n) + "=" * (m + 1) + "." * (n - m - 1) + "]", @@ -272,9 +272,10 @@ class Interface: current_pkg_version = pkg_resources.require("gradio")[0].version latest_pkg_version = requests.get(url=PKG_VERSION_URL).json()["version"] if StrictVersion(latest_pkg_version) > StrictVersion(current_pkg_version): - print(f"IMPORTANT: You are using gradio version {current_pkg_version}, " - f"however version {latest_pkg_version} " - f"is available, please upgrade.") + print("IMPORTANT: You are using gradio version {}, " + "however version {} " + "is available, please upgrade.".format( + current_pkg_version, latest_pkg_version)) print('--------') except: # TODO(abidlabs): don't catch all exceptions pass diff --git a/gradio/networking.py b/gradio/networking.py index 3a25636e63..efd4ffb207 100644 --- a/gradio/networking.py +++ b/gradio/networking.py @@ -254,7 +254,8 @@ def serve_files_in_background(interface, port, directory_to_serve=None): output = {'input': interface.input_interface.save_to_file(flag_dir, img), 'output': interface.output_interface.rebuild_flagged( flag_dir, {'data': {'output': processed_output}}), - 'message': f'rotation by {deg} degrees'} + 'message': 'rotation by {} degrees'.format( + deg)} with open(os.path.join(flag_dir, FLAGGING_FILENAME), 'a+') as f: f.write(json.dumps(output)) @@ -287,7 +288,8 @@ def serve_files_in_background(interface, port, directory_to_serve=None): output = {'input': interface.input_interface.save_to_file(flag_dir, img), 'output': interface.output_interface.rebuild_flagged( flag_dir, {'data': {'output': processed_output}}), - 'message': f'brighting adjustment by a factor of {i}'} + 'message': 'brighting adjustment by a factor ' + 'of {}'.format(i)} with open(os.path.join(flag_dir, FLAGGING_FILENAME), 'a+') as f: f.write(json.dumps(output)) @@ -297,7 +299,7 @@ def serve_files_in_background(interface, port, directory_to_serve=None): self.wfile.write(json.dumps({}).encode()) else: - self.send_error(404, 'Path not found: %s' % self.path) + self.send_error(404, 'Path not found: {}'.format(self.path)) class HTTPServer(BaseHTTPServer): """The main server, you pass in base_path which is the path you want to serve requests from""" diff --git a/gradio/outputs.py b/gradio/outputs.py index 1a495e3207..a249dc376e 100644 --- a/gradio/outputs.py +++ b/gradio/outputs.py @@ -159,8 +159,9 @@ class Image(AbstractOutput): """ im = preprocessing_utils.decode_base64_to_image(msg) timestamp = datetime.datetime.now() - filename = f'output_{timestamp.strftime("%Y-%m-%d-%H-%M-%S")}.png' - im.save(f'{dir}/{filename}', 'PNG') + filename = 'output_{}.png'.format(timestamp. + strftime("%Y-%m-%d-%H-%M-%S")) + im.save('{}/{}'.format(dir, filename), 'PNG') return filename diff --git a/gradio/tunneling.py b/gradio/tunneling.py index 990eee3d0b..45122c484a 100644 --- a/gradio/tunneling.py +++ b/gradio/tunneling.py @@ -19,12 +19,13 @@ def handler(chan, host, port): try: sock.connect((host, port)) except Exception as e: - verbose("Forwarding request to %s:%d failed: %r" % (host, port, e)) + verbose("Forwarding request to {}:{} failed: {}".format(host, port, e)) return verbose( - "Connected! Tunnel open %r -> %r -> %r" - % (chan.origin_addr, chan.getpeername(), (host, port)) + "Connected! Tunnel open {} -> {} -> {}".format(chan.origin_addr, + chan.getpeername(), + (host, port)) ) while True: r, w, x = select.select([sock, chan], [], []) @@ -40,7 +41,7 @@ def handler(chan, host, port): sock.send(data) chan.close() sock.close() - verbose("Tunnel closed from %r" % (chan.origin_addr,)) + verbose("Tunnel closed from {}".format(chan.origin_addr,)) def reverse_forward_tunnel(server_port, remote_host, remote_port, transport): @@ -65,7 +66,8 @@ def create_tunnel(payload, local_server, local_server_port): client.set_missing_host_key_policy(paramiko.WarningPolicy()) verbose( - "Connecting to ssh host %s:%d ..." % (payload["host"], int(payload["port"])) + "Connecting to ssh host {}:{} ...".format(payload["host"], int(payload[ + "port"])) ) try: with warnings.catch_warnings(): @@ -78,14 +80,16 @@ def create_tunnel(payload, local_server, local_server_port): ) except Exception as e: print( - "*** Failed to connect to %s:%d: %r" - % (payload["host"], int(payload["port"]), e) + "*** Failed to connect to {}:{}: {}}".format(payload["host"], + int(payload["port"]), e) ) sys.exit(1) verbose( - "Now forwarding remote port %d to %s:%d ..." - % (int(payload["remote_port"]), local_server, local_server_port) + "Now forwarding remote port {} to {}:{} ...".format(int(payload[ + "remote_port"]), + local_server, + local_server_port) ) thread = threading.Thread( diff --git a/screenshots/.image_interface.png.icloud b/screenshots/.image_interface.png.icloud new file mode 100644 index 0000000000000000000000000000000000000000..4f5ecae07b73d2b00f2850963ee03527f6639109 GIT binary patch literal 171 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?4zf;mq8`^wjvwypq(Sw8Z38y@I@SAqFL7w|D^=th$0y(@S#_i#YgY^t}>N R8Nh&%5kfPtLunY*0ss{3E_46@ literal 0 HcmV?d00001 diff --git a/web/img/.cheetah-clean.png.icloud b/web/img/.cheetah-clean.png.icloud new file mode 100644 index 0000000000000000000000000000000000000000..54e3e47420f3e193e1bb45460683d0f13fa5bbc0 GIT binary patch literal 169 zcmYc)$jK}&F)+By$i&RT$`<1n92(@~mzbOComv?$AOPmNW#*&?XI4RkB;Z0psm1xF zMaiill?4zf!Q_n8)RM#u-Q=9q#5}!%ymTQ3C1tmG0U4}%f>P5