Merge pull request #331 from gradio-app/abidlabs/interface

examples can handle non-nested list if single input interface
This commit is contained in:
Abubakar Abid 2021-11-04 06:27:53 -05:00 committed by GitHub
commit 7d9f892bf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 5 deletions

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

@ -51,11 +51,11 @@ class TestInterface(unittest.TestCase):
def test_examples_invalid_input(self):
with self.assertRaises(ValueError):
Interface(lambda input: None, examples=1234)
Interface(lambda x: x, examples=1234)
def test_examples_not_valid_path(self):
with self.assertRaises(FileNotFoundError):
interface = Interface(lambda input: None, "textbox", "label", examples='wrong-path')
interface = Interface(lambda x: x, "textbox", "label", examples='invalid-path')
interface.launch()