mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-27 02:30:17 +08:00
Merge pull request #331 from gradio-app/abidlabs/interface
examples can handle non-nested list if single input interface
This commit is contained in:
commit
7d9f892bf9
@ -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.")
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user