Merge remote-tracking branch 'origin/master' into aliabd/components-tests

This commit is contained in:
aliabd 2021-11-04 13:09:41 -07:00
commit 6a643d1bb9
12 changed files with 84 additions and 26 deletions

View File

@ -10,11 +10,9 @@ Quickly create a GUI around your machine learning model, API, or function. Gradi
Gradio is useful for:
* Creating demos of your machine learning code for clients / collaborators / users
* Getting feedback on model performance from testers
* Debugging your model interactively during development
* **Demoing** your machine learning models for clients / collaborators / users / students
* **Deploying** your models quickly with automatic shareable links and getting feedback on model performance
* **Debugging** your model interactively during development using built-in interpretation visualizations for any model
## Getting Started

View File

@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: gradio
Version: 2.4.1
Version: 2.4.2
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

@ -161,6 +161,8 @@ class Interface:
self.css = css
if examples is None or isinstance(examples, str) or (isinstance(examples, list) and (len(examples) == 0 or isinstance(examples[0], list))):
self.examples = examples
elif isinstance(examples, list) and len(self.input_components) == 1: # If there is only one input component, examples can be provided as a regular list instead of a list of lists
self.examples = [[e] for e in examples]
else:
raise ValueError(
"Examples argument must either be a directory or a nested list, where each sublist represents a set of inputs.")

View File

@ -405,14 +405,11 @@ def queue_thread(path_to_local_server, test_mode=False):
while True:
try:
next_job = queue.pop()
print(next_job)
if next_job is not None:
_, hash, input_data, task_type = next_job
print(hash)
queue.start_job(hash)
response = requests.post(
path_to_local_server + "/api/" + task_type + "/", json=input_data)
print('response', response)
if response.status_code == 200:
queue.pass_job(hash, response.json())
else:

View File

@ -134,9 +134,9 @@ class Label(OutputComponent):
"float label, or a dictionary whose keys are labels and values are confidences.")
def deserialize(self, y):
# 4 cases: (1): {'label': 'lion'}, {'label': 'lion', 'confidences':...}, {'lion': 0.46, ...}, 'lion'
if self.type == "label" or (self.type == "auto" and (isinstance(y, str) or ('label' in y and not('confidences' in y.keys())))):
if isinstance(y, str):
# 5 cases: (1): {'label': 'lion'}, {'label': 'lion', 'confidences':...}, {'lion': 0.46, ...}, 'lion', '0.46'
if self.type == "label" or (self.type == "auto" and (isinstance(y, str) or isinstance(y, int) or isinstance(y, float) or ('label' in y and not('confidences' in y.keys())))):
if isinstance(y, str) or isinstance(y, int) or isinstance(y, float):
return y
else:
return y['label']

View File

@ -1,18 +1,18 @@
{
"files": {
"main.css": "/static/css/main.ccb63765.css",
"main.css": "/static/css/main.fdac3282.css",
"main.js": "/static/bundle.js",
"index.html": "/index.html",
"static/media/arrow-left.794a4706.svg": "/static/media/arrow-left.794a4706.svg",
"static/media/arrow-right.5a7d4ada.svg": "/static/media/arrow-right.5a7d4ada.svg",
"static/media/clear.85cf6de8.svg": "/static/media/clear.85cf6de8.svg",
"static/media/edit.c6b7d6f7.svg": "/static/media/edit.c6b7d6f7.svg",
"static/media/logo.36a8f455.svg": "/static/media/logo.36a8f455.svg",
"static/media/arrow-left.e497f657.svg": "/static/media/arrow-left.e497f657.svg",
"static/media/arrow-right.ea6059fd.svg": "/static/media/arrow-right.ea6059fd.svg",
"static/media/clear.33f9b5f3.svg": "/static/media/clear.33f9b5f3.svg",
"static/media/edit.44bd4fe1.svg": "/static/media/edit.44bd4fe1.svg",
"static/media/logo.411acfd1.svg": "/static/media/logo.411acfd1.svg",
"static/media/logo_loading.e93acd82.jpg": "/static/media/logo_loading.e93acd82.jpg"
},
"entrypoints": [
"static/bundle.css",
"static/css/main.ccb63765.css",
"static/css/main.fdac3282.css",
"static/bundle.js"
]
}

View File

@ -8,4 +8,4 @@
window.config = {{ config|tojson }};
} catch (e) {
window.config = {};
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.ccb63765.css" rel="stylesheet"></head><body style="height:100%"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>
}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js"></script><title>Gradio</title><link href="static/bundle.css" rel="stylesheet"><link href="static/css/main.fdac3282.css" rel="stylesheet"></head><body style="height:100%"><div id="root" style="height:100%"></div><script src="static/bundle.js"></script></body></html>

View File

@ -1 +1 @@
2.4.1
2.4.2

View File

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

View File

@ -1,4 +1,63 @@
from gradio.interface import *
import unittest
import unittest.mock as mock
import requests
class TestInterface(unittest.TestCase):
# send_error_analytics should probably actually be a method of Interface
# (so it doesn't have to take the 'enabled' argument)
# and since it's specific to the launch method, it should probably be
# renamed to send_launch_error_analytics.
# these tests test its current behavior
@mock.patch("requests.post")
def test_error_analytics_doesnt_crash_on_connection_error(self, mock_post):
mock_post.side_effect = requests.ConnectionError()
send_error_analytics(True)
mock_post.assert_called()
@mock.patch("requests.post")
def test_error_analytics_doesnt_post_if_not_enabled(self, mock_post):
send_error_analytics(False)
mock_post.assert_not_called()
@mock.patch("requests.post")
def test_error_analytics_successful(self, mock_post):
send_error_analytics(True)
mock_post.assert_called()
# as above, send_launch_analytics should probably be a method of Interface
@mock.patch("requests.post")
def test_launch_analytics_doesnt_crash_on_connection_error(self, mock_post):
mock_post.side_effect = requests.ConnectionError()
send_launch_analytics(analytics_enabled=True,
inbrowser=True, is_colab="is_colab",
share="share", share_url="share_url")
mock_post.assert_called()
@mock.patch("requests.post")
def test_launch_analytics_doesnt_post_if_not_enabled(self, mock_post):
send_launch_analytics(analytics_enabled=False,
inbrowser=True, is_colab="is_colab",
share="share", share_url="share_url")
mock_post.assert_not_called()
def test_reset_all(self):
interface = Interface(lambda input: None, "textbox", "label")
interface.close = mock.MagicMock()
reset_all()
interface.close.assert_called()
def test_examples_invalid_input(self):
with self.assertRaises(ValueError):
Interface(lambda x: x, examples=1234)
def test_examples_not_valid_path(self):
with self.assertRaises(FileNotFoundError):
interface = Interface(lambda x: x, "textbox", "label", examples='invalid-path')
interface.launch()
if __name__ == '__main__':
unittest.main()

View File

@ -27,10 +27,10 @@ class ImagePreprocessing(unittest.TestCase):
"/images/test_image.png")
self.assertEqual(output_base64, gr.test_data.BASE64_IMAGE)
def test_encode_plot_to_base64(self):
plt.plot([1, 2, 3, 4])
output_base64 = gr.processing_utils.encode_plot_to_base64(plt)
self.assertEqual(output_base64, gr.test_data.BASE64_PLT_IMG)
# def test_encode_plot_to_base64(self): # Commented out because this is throwing errors on Windows. Possibly due to different matplotlib behavior on Windows?
# plt.plot([1, 2, 3, 4])
# output_base64 = gr.processing_utils.encode_plot_to_base64(plt)
# self.assertEqual(output_base64, gr.test_data.BASE64_PLT_IMG)
def test_encode_array_to_base64(self):
img = Image.open("test/images/test_image.png")

View File

@ -53,10 +53,12 @@ class TestUtils(unittest.TestCase):
mock_post.side_effect = requests.ConnectionError()
error_analytics("placeholder")
mock_post.assert_called()
@mock.patch("requests.post")
def test_error_analytics_successful(self, mock_post):
error_analytics("placeholder")
mock_post.assert_called()
@mock.patch("IPython.get_ipython")