updated PyPi version

This commit is contained in:
Abubakar Abid 2020-08-11 19:28:51 -05:00
parent f918fa0260
commit 0cd62350b5
5 changed files with 32 additions and 40 deletions

View File

@ -49,7 +49,8 @@ class Interface:
capture_session=False, title=None, description=None,
thumbnail=None, server_port=None, server_name=networking.LOCALHOST_NAME,
allow_screenshot=True, allow_flagging=True,
flagging_dir="flagged"):
flagging_dir="flagged", analytics_enabled=True):
"""
Parameters:
fn (Callable): the function to wrap an interface around.
@ -123,6 +124,7 @@ class Interface:
self.allow_flagging = allow_flagging
self.flagging_dir = flagging_dir
Interface.instances.add(self)
self.analytics_enabled=analytics_enabled
data = {'fn': fn,
'inputs': inputs,
@ -154,11 +156,12 @@ class Interface:
self.flagging_dir = self.flagging_dir + "/" + dir_name + \
"_{}".format(index)
try:
requests.post(analytics_url + 'gradio-initiated-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
if self.analytics_enabled:
try:
requests.post(analytics_url + 'gradio-initiated-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
def get_config_file(self):
config = {
@ -293,7 +296,10 @@ class Interface:
is_colab = utils.colab_check()
if not is_colab:
print(strings.en["RUNNING_LOCALLY"].format(path_to_local_server))
if not networking.url_ok(path_to_local_server):
share = True
else:
print(strings.en["RUNNING_LOCALLY"].format(path_to_local_server))
else:
if debug:
print("Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. "
@ -302,11 +308,19 @@ class Interface:
print("Colab notebook detected. To show errors in colab notebook, set debug=True in launch()")
if share:
print("This share link will expire in 6 hours. If you need a "
"permanent link, email support@gradio.app")
try:
share_url = networking.setup_tunnel(server_port)
print("Running on External URL:", share_url)
except RuntimeError:
utils.error_analytics("RuntimeError")
data = {'error': 'RuntimeError in launch method'}
if self.analytics_enabled:
try:
requests.post(analytics_url + 'gradio-error-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
share_url = None
if self.verbose:
print(strings.en["NGROK_NO_INTERNET"])
@ -374,11 +388,13 @@ class Interface:
'share_url': share_url,
'ip_address': ip_address
}
try:
requests.post(analytics_url + 'gradio-launched-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
if self.analytics_enabled:
try:
requests.post(analytics_url + 'gradio-launched-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
is_in_interactive_mode = bool(getattr(sys, 'ps1', sys.flags.interactive))
if not is_in_interactive_mode:

View File

@ -16,7 +16,6 @@ import urllib.request
from shutil import copyfile
import requests
import sys
import analytics
import csv
@ -38,9 +37,6 @@ CONFIG_FILE = "static/config.json"
ASSOCIATION_PATH_IN_STATIC = "static/apple-app-site-association"
ASSOCIATION_PATH_IN_ROOT = "apple-app-site-association"
analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
analytics_url = 'https://api.gradio.app/'
def build_template(temp_dir):
"""
@ -128,21 +124,6 @@ def get_first_available_port(initial, final):
)
def send_prediction_analytics(interface):
data = {'title': interface.title,
'description': interface.description,
'thumbnail': interface.thumbnail,
'input_interface': interface.input_interfaces,
'output_interface': interface.output_interfaces,
}
try:
requests.post(
analytics_url + 'gradio-prediction-analytics/',
data=data)
except requests.ConnectionError:
pass # do not push analytics if no network
def serve_files_in_background(interface, port, directory_to_serve=None, server_name=LOCALHOST_NAME):
class HTTPHandler(SimpleHTTPRequestHandler):
"""This handler uses server.base_path instead of always using os.getcwd()"""
@ -174,10 +155,6 @@ def serve_files_in_background(interface, port, directory_to_serve=None, server_n
output = {"data": prediction, "durations": durations}
self.wfile.write(json.dumps(output).encode())
analytics_thread = threading.Thread(
target=send_prediction_analytics, args=[interface])
analytics_thread.start()
elif self.path == "/api/flag/":
self._set_headers()
data_string = self.rfile.read(

View File

@ -24,8 +24,7 @@ def colab_check():
is_colab = False
try: # Check if running interactively using ipython.
from_ipynb = get_ipython()
if "google.colab" in str(from_ipynb) or "ipykernel" in str(
from_ipynb):
if "google.colab" in str(from_ipynb):
is_colab = True
except NameError:
error_analytics("NameError", analytics_url)

View File

@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: gradio
Version: 1.1.5
Version: 1.1.6
Summary: Python library for easily interacting with trained machine learning models
Home-page: https://github.com/gradio-app/gradio-UI
Author: Abubakar Abid

View File

@ -5,7 +5,7 @@ except ImportError:
setup(
name='gradio',
version='1.1.5',
version='1.1.6',
include_package_data=True,
description='Python library for easily interacting with trained machine learning models',
author='Abubakar Abid',