forked from gradio-app/gradio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
interface and launch refactoring, documentation
- Loading branch information
Showing
3 changed files
with
105 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import requests | ||
from IPython import get_ipython | ||
analytics_url = 'https://api.gradio.app/' | ||
|
||
|
||
def error_analytics(type): | ||
""" | ||
Send error analytics if there is network | ||
:param type: RuntimeError or NameError | ||
""" | ||
data = {'error': '{} in launch method'.format(type)} | ||
try: | ||
requests.post(analytics_url + 'gradio-error-analytics/', | ||
data=data) | ||
except requests.ConnectionError: | ||
pass # do not push analytics if no network | ||
|
||
|
||
def colab_check(): | ||
""" | ||
Check if interface is launching from Google Colab | ||
:return is_colab (bool): True or False | ||
""" | ||
is_colab = False | ||
try: # Check if running interactively using ipython. | ||
from_ipynb = get_ipython() | ||
if "google.colab" in str(from_ipynb): | ||
is_colab = True | ||
except NameError: | ||
error_analytics("NameError", analytics_url) | ||
return is_colab | ||
|
||
|
||
def ipython_check(): | ||
""" | ||
Check if interface is launching from iPython (not colab) | ||
:return is_ipython (bool): True or False | ||
""" | ||
try: # Check if running interactively using ipython. | ||
get_ipython() | ||
is_ipython = True | ||
except NameError: | ||
is_ipython = False | ||
return is_ipython |