File size: 2,797 Bytes
0ad74ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
from __future__ import annotations
from gradio_client.documentation import document
class DuplicateBlockError(ValueError):
"""Raised when a Blocks contains more than one Block with the same id"""
pass
class InvalidComponentError(ValueError):
"""Raised when invalid components are used."""
pass
class TooManyRequestsError(Exception):
"""Raised when the Hugging Face API returns a 429 status code."""
pass
class ModelNotFoundError(Exception):
"""Raised when the provided model doesn't exists or is not found by the provided api url."""
pass
class RenderError(Exception):
"""Raised when a component has not been rendered in the current Blocks but is expected to have been rendered."""
pass
class InvalidApiNameError(ValueError):
pass
class ServerFailedToStartError(Exception):
pass
class InvalidBlockError(ValueError):
"""Raised when an event in a Blocks contains a reference to a Block that is not in the original Blocks"""
pass
class ReloadError(ValueError):
"""Raised when something goes wrong when reloading the gradio app."""
pass
class GradioVersionIncompatibleError(Exception):
"""Raised when loading a 3.x space with 4.0"""
pass
InvalidApiName = InvalidApiNameError # backwards compatibility
@document(documentation_group="modals")
class Error(Exception):
"""
This class allows you to pass custom error messages to the user. You can do so by raising a gr.Error("custom message") anywhere in the code, and when that line is executed the custom message will appear in a modal on the demo.
Example:
import gradio as gr
def divide(numerator, denominator):
if denominator == 0:
raise gr.Error("Cannot divide by zero!")
gr.Interface(divide, ["number", "number"], "number").launch()
Demos: calculator, blocks_chained_events
"""
def __init__(
self,
message: str = "Error raised.",
duration: float | None = 10,
visible: bool = True,
):
"""
Parameters:
message: The error message to be displayed to the user. Can be HTML, which will be rendered in the modal.
duration: The duration in seconds to display the error message. If None or 0, the error message will be displayed until the user closes it.
visible: Whether the error message should be displayed in the UI.
"""
self.message = message
self.duration = duration
self.visible = visible
super().__init__(self.message)
def __str__(self):
return repr(self.message)
class ComponentDefinitionError(NotImplementedError):
pass
class InvalidPathError(ValueError):
pass
class ChecksumMismatchError(Exception):
pass
|