mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-18 10:44:33 +08:00
Miscellaneous warnings and errors (#3194)
* changes * added workflow * fix action * fix action * fix action * warning for filetypes * miscellaneous warnings and errors * Delete benchmark-queue.yml * Delete benchmark_queue.py * changelog * warning * formatting * changelog * formatting
This commit is contained in:
parent
4307d7e809
commit
74d9080fcd
@ -54,6 +54,8 @@ No changes to highlight.
|
||||
|
||||
## Full Changelog:
|
||||
* Fix demos page css and add close demos button by [@aliabd](https://github.com/aliabd) in [PR 3151](https://github.com/gradio-app/gradio/pull/3151)
|
||||
* Better warnings (when there is a mismatch between the number of output components and values returned by a function, or when the `File` component or `UploadButton` component includes a `file_types` parameter along with `file_count=="dir"`) by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
* Raises a `gr.Error` instead of a regular Python error when you use `gr.Interface.load()` to load a model and there's an error querying the HF API by [@abidlabs](https://github.com/abidlabs) in [PR 3194](https://github.com/gradio-app/gradio/pull/3194)
|
||||
|
||||
## Contributors Shoutout:
|
||||
No changes to highlight.
|
||||
|
@ -334,13 +334,12 @@ class BlockFunction:
|
||||
self.total_runtime = 0
|
||||
self.total_runs = 0
|
||||
self.inputs_as_dict = inputs_as_dict
|
||||
self.name = getattr(fn, "__name__", "fn") if fn is not None else None
|
||||
|
||||
def __str__(self):
|
||||
return str(
|
||||
{
|
||||
"fn": getattr(self.fn, "__name__", "fn")
|
||||
if self.fn is not None
|
||||
else None,
|
||||
"fn": self.name,
|
||||
"preprocess": self.preprocess,
|
||||
"postprocess": self.postprocess,
|
||||
}
|
||||
@ -934,9 +933,14 @@ class Blocks(BlockContext):
|
||||
|
||||
output = []
|
||||
for i, output_id in enumerate(dependency["outputs"]):
|
||||
if predictions[i] is components._Keywords.FINISHED_ITERATING:
|
||||
output.append(None)
|
||||
continue
|
||||
try:
|
||||
if predictions[i] is components._Keywords.FINISHED_ITERATING:
|
||||
output.append(None)
|
||||
continue
|
||||
except (IndexError, KeyError):
|
||||
raise ValueError(
|
||||
f"Number of output components does not match number of values returned from from function {block_fn.name}"
|
||||
)
|
||||
block = self.blocks[output_id]
|
||||
if getattr(block, "stateful", False):
|
||||
if not utils.is_update(predictions[i]):
|
||||
@ -957,6 +961,7 @@ class Blocks(BlockContext):
|
||||
), f"{block.__class__} Component with id {output_id} not a valid output component."
|
||||
prediction_value = block.postprocess(prediction_value)
|
||||
output.append(prediction_value)
|
||||
|
||||
return output
|
||||
|
||||
async def process_api(
|
||||
|
@ -2273,6 +2273,10 @@ class File(
|
||||
warnings.warn(
|
||||
"The `bytes` type is deprecated and may not work as expected. Please use `binary` instead."
|
||||
)
|
||||
if file_count == "directory" and file_types is not None:
|
||||
warnings.warn(
|
||||
"The `file_types` parameter is ignored when `file_count` is 'directory'."
|
||||
)
|
||||
self.type = type
|
||||
self.test_input = None
|
||||
TempFileManager.__init__(self)
|
||||
@ -2992,6 +2996,10 @@ class UploadButton(
|
||||
"""
|
||||
self.type = type
|
||||
self.file_count = file_count
|
||||
if file_count == "directory" and file_types is not None:
|
||||
warnings.warn(
|
||||
"The `file_types` parameter is ignored when `file_count` is 'directory'."
|
||||
)
|
||||
if file_types is not None and not isinstance(file_types, list):
|
||||
raise ValueError(
|
||||
f"Parameter file_types must be a list. Received {file_types.__class__.__name__}"
|
||||
|
@ -15,7 +15,7 @@ import requests
|
||||
import gradio
|
||||
from gradio import components, utils
|
||||
from gradio.context import Context
|
||||
from gradio.exceptions import TooManyRequestsError
|
||||
from gradio.exceptions import Error, TooManyRequestsError
|
||||
from gradio.external_utils import (
|
||||
cols_to_rows,
|
||||
encode_to_base64,
|
||||
@ -328,7 +328,7 @@ def from_model(model_name: str, api_key: str | None, alias: str | None, **kwargs
|
||||
errors = f", Error: {errors_json.get('error')}"
|
||||
if errors_json.get("warnings"):
|
||||
warns = f", Warnings: {errors_json.get('warnings')}"
|
||||
raise ValueError(
|
||||
raise Error(
|
||||
f"Could not complete request to HuggingFace API, Status Code: {response.status_code}"
|
||||
+ errors
|
||||
+ warns
|
||||
|
@ -414,6 +414,8 @@ class TestComponentsInBlocks:
|
||||
components.append(component(value=lambda: None, every=1))
|
||||
assert [comp.load_event for comp in components] == demo.dependencies
|
||||
|
||||
|
||||
class TestBlocksPostprocessing:
|
||||
def test_blocks_do_not_filter_none_values_from_updates(self, io_components):
|
||||
io_components = [
|
||||
c()
|
||||
@ -531,6 +533,18 @@ class TestComponentsInBlocks:
|
||||
}
|
||||
assert output["data"][1] == {"__type__": "update", "mode": "dynamic"}
|
||||
|
||||
def test_error_raised_if_num_outputs_mismatch(self):
|
||||
with gr.Blocks() as demo:
|
||||
textbox1 = gr.Textbox()
|
||||
textbox2 = gr.Textbox()
|
||||
button = gr.Button()
|
||||
button.click(lambda x: x, textbox1, [textbox1, textbox2])
|
||||
with pytest.raises(
|
||||
ValueError,
|
||||
match="Number of output components does not match number of values returned from from function <lambda>",
|
||||
):
|
||||
demo.postprocess_data(fn_index=0, predictions=["test"], state={})
|
||||
|
||||
|
||||
class TestCallFunction:
|
||||
@pytest.mark.asyncio
|
||||
|
Loading…
Reference in New Issue
Block a user