diff --git a/.gitignore b/.gitignore index 72ecee3ba8..8954135443 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ docs.json demo/tmp.zip demo/flagged test.txt -build/ \ No newline at end of file +build/ +gradio/launches.json \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index 635b108ab3..912d581a0c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ recursive-include gradio/templates * recursive-include gradio/static * +include gradio/launches.json \ No newline at end of file diff --git a/gradio/interface.py b/gradio/interface.py index 697016756e..f37ae67f1e 100644 --- a/gradio/interface.py +++ b/gradio/interface.py @@ -7,6 +7,7 @@ from gradio.inputs import InputComponent from gradio.outputs import OutputComponent from gradio import networking, strings, utils from gradio.interpretation import quantify_difference_in_label +import pkg_resources import requests import random import time @@ -19,11 +20,14 @@ import numpy as np import os import copy import markdown2 +import json analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy" analytics_url = 'https://api.gradio.app/' ip_address = networking.get_local_ip_address() +JSON_PATH = pkg_resources.resource_filename("gradio", "launches.json") + class Interface: """ Interfaces are created with Gradio using the `gradio.Interface()` function. @@ -365,6 +369,7 @@ class Interface: path_to_local_server (str): Locally accessible link share_url (str): Publicly accessible link (if share=True) """ + config = self.get_config_file() networking.set_config(config) networking.set_meta_tags(self.title, self.description, self.thumbnail) @@ -392,6 +397,17 @@ class Interface: else: print("Colab notebook detected. To show errors in colab notebook, set debug=True in launch()") + if not os.path.exists(JSON_PATH): + with open(JSON_PATH, "w+") as j: + launches = {"launches": 0} + j.write(json.dumps(launches)) + else: + with open(JSON_PATH) as j: + launches = json.load(j) + + if launches["launches"] in [25, 50]: + print(strings.en["BETA_INVITE"]) + self.share = share if share: print("This share link will expire in 24 hours. If you need a " @@ -469,6 +485,10 @@ class Interface: if not is_in_interactive_mode: self.run_until_interrupted(thread, path_to_local_server) + launches["launches"] += 1 + with open(JSON_PATH, "w") as j: + j.write(json.dumps(launches)) + return app, path_to_local_server, share_url diff --git a/gradio/strings.py b/gradio/strings.py index 1d0568e502..7190e2f0a9 100644 --- a/gradio/strings.py +++ b/gradio/strings.py @@ -8,5 +8,7 @@ en = { "MODEL_PUBLICLY_AVAILABLE_URL": "Model available publicly at: {} (may take up to a minute for link to be usable)", "GENERATING_PUBLIC_LINK": "Generating public link (may take a few seconds...):", "TF1_ERROR": "It looks like you might be using tensorflow < 2.0. Please pass capture_session=True in Interface() to" - " avoid the 'Tensor is not an element of this graph.' error." + " avoid the 'Tensor is not an element of this graph.' error.", + "BETA_INVITE": "\nWe want to invite you to become a beta user.\nYou'll get early access to new and premium " + "features (persistent links, hosting, and more).\nIf you're interested please email beta@gradio.app\n" }