aliabid94 HF staff commited on
Commit
47e2c18
1 Parent(s): 36b9444

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -2,8 +2,8 @@
2
  ---
3
  tags: [gradio-custom-component,gradio-template-Column,Modal, Popup]
4
  title: gradio_modal V0.0.1
5
- colorFrom: green
6
- colorTo: green
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
 
2
  ---
3
  tags: [gradio-custom-component,gradio-template-Column,Modal, Popup]
4
  title: gradio_modal V0.0.1
5
+ colorFrom: yellow
6
+ colorTo: purple
7
  sdk: docker
8
  pinned: false
9
  license: apache-2.0
__pycache__/__init__.cpython-310.pyc ADDED
Binary file (138 Bytes). View file
 
__pycache__/app.cpython-310.pyc ADDED
Binary file (957 Bytes). View file
 
app.py CHANGED
@@ -1,21 +1,20 @@
1
-
2
  import gradio as gr
3
  from gradio_modal import Modal
4
 
5
-
6
  with gr.Blocks() as demo:
7
- gr.Markdown("### Main Page")
8
- gr.Textbox("lorem ipsum " * 1000, lines=10)
9
-
10
- with Modal(visible=True) as modal:
11
- gr.Markdown("# License Agreement")
12
- gr.Textbox(value="This is the license agreement. Please read it carefully. " * 5, lines=12)
13
- close_btn = gr.Button("Close Modal")
14
- close_btn.click(lambda: Modal(visible=False), None, modal)
15
-
16
- show_btn = gr.Button("Show Modal")
 
 
 
17
  show_btn.click(lambda: Modal(visible=True), None, modal)
18
 
19
-
20
- if __name__ == "__main__":
21
- demo.launch()
 
 
1
  import gradio as gr
2
  from gradio_modal import Modal
3
 
 
4
  with gr.Blocks() as demo:
5
+ with gr.Tab("Tab 1"):
6
+ text_1 = gr.Textbox(label="Input 1")
7
+ text_2 = gr.Textbox(label="Input 2")
8
+ text_1.submit(lambda x:x, text_1, text_2)
9
+ show_btn = gr.Button("Show Modal")
10
+ gr.Examples(
11
+ [["Text 1", "Text 2"], ["Text 3", "Text 4"]],
12
+ inputs=[text_1, text_2],
13
+ )
14
+ with gr.Tab("Tab 2"):
15
+ gr.Markdown("This is tab 2")
16
+ with Modal(visible=False) as modal:
17
+ gr.Markdown("Hello world!")
18
  show_btn.click(lambda: Modal(visible=True), None, modal)
19
 
20
+ demo.launch()
 
 
src/backend/gradio_modal/modal.py CHANGED
@@ -3,7 +3,9 @@ from __future__ import annotations
3
  from gradio_client.documentation import document, set_documentation_group
4
 
5
  from gradio.blocks import BlockContext
 
6
  from gradio.component_meta import ComponentMeta
 
7
 
8
  set_documentation_group("layout")
9
 
@@ -22,7 +24,7 @@ class Modal(BlockContext, metaclass=ComponentMeta):
22
  Guides: controlling-layout
23
  """
24
 
25
- EVENTS = []
26
 
27
  def __init__(
28
  self,
@@ -49,3 +51,18 @@ class Modal(BlockContext, metaclass=ComponentMeta):
49
  elem_classes=elem_classes,
50
  render=render,
51
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from gradio_client.documentation import document, set_documentation_group
4
 
5
  from gradio.blocks import BlockContext
6
+ from gradio.context import Context
7
  from gradio.component_meta import ComponentMeta
8
+ from gradio.events import Events
9
 
10
  set_documentation_group("layout")
11
 
 
24
  Guides: controlling-layout
25
  """
26
 
27
+ EVENTS = [Events.blur]
28
 
29
  def __init__(
30
  self,
 
51
  elem_classes=elem_classes,
52
  render=render,
53
  )
54
+ if Context.root_block:
55
+ self.blur(
56
+ None,
57
+ None,
58
+ self,
59
+ js="""
60
+ () => {
61
+ return {
62
+ "__type__": "update",
63
+ "visible": false
64
+ }
65
+ }
66
+ """
67
+ )
68
+
src/backend/gradio_modal/modal.pyi CHANGED
@@ -26,7 +26,7 @@ class Modal(BlockContext, metaclass=ComponentMeta):
26
  Guides: controlling-layout
27
  """
28
 
29
- EVENTS = []
30
 
31
  def __init__(
32
  self,
@@ -39,7 +39,7 @@ class Modal(BlockContext, metaclass=ComponentMeta):
39
  ):
40
  """
41
  Parameters:
42
- visible: If False, column will be hidden.
43
  elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
44
  elem_classes: An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles.
45
  allow_user_close: If True, user can close the modal (by clicking outside, clicking the X, or the escape key).
@@ -52,4 +52,61 @@ class Modal(BlockContext, metaclass=ComponentMeta):
52
  elem_id=elem_id,
53
  elem_classes=elem_classes,
54
  render=render,
55
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  Guides: controlling-layout
27
  """
28
 
29
+ EVENTS = [Events.blur]
30
 
31
  def __init__(
32
  self,
 
39
  ):
40
  """
41
  Parameters:
42
+ visible: If False, modal will be hidden.
43
  elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
44
  elem_classes: An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles.
45
  allow_user_close: If True, user can close the modal (by clicking outside, clicking the X, or the escape key).
 
52
  elem_id=elem_id,
53
  elem_classes=elem_classes,
54
  render=render,
55
+ )
56
+ if Context.root_block:
57
+ self.blur(
58
+ None,
59
+ None,
60
+ self,
61
+ js="""
62
+ () => {
63
+ return {
64
+ "__type__": "update",
65
+ "visible": false
66
+ }
67
+ }
68
+ """
69
+ )
70
+
71
+
72
+ def blur(self,
73
+ fn: Callable | None,
74
+ inputs: Component | Sequence[Component] | set[Component] | None = None,
75
+ outputs: Component | Sequence[Component] | None = None,
76
+ api_name: str | None | Literal[False] = None,
77
+ scroll_to_output: bool = False,
78
+ show_progress: Literal["full", "minimal", "hidden"] = "full",
79
+ queue: bool | None = None,
80
+ batch: bool = False,
81
+ max_batch_size: int = 4,
82
+ preprocess: bool = True,
83
+ postprocess: bool = True,
84
+ cancels: dict[str, Any] | list[dict[str, Any]] | None = None,
85
+ every: float | None = None,
86
+ trigger_mode: Literal["once", "multiple", "always_last"] | None = None,
87
+ js: str | None = None,
88
+ concurrency_limit: int | None | Literal["default"] = "default",
89
+ concurrency_id: str | None = None,
90
+ show_api: bool = True) -> Dependency:
91
+ """
92
+ Parameters:
93
+ fn: the function to call when this event is triggered. Often a machine learning model's prediction function. Each parameter of the function corresponds to one input component, and the function should return a single value or a tuple of values, with each element in the tuple corresponding to one output component.
94
+ inputs: List of gradio.components to use as inputs. If the function takes no inputs, this should be an empty list.
95
+ outputs: List of gradio.components to use as outputs. If the function returns no outputs, this should be an empty list.
96
+ api_name: Defines how the endpoint appears in the API docs. Can be a string, None, or False. If False, the endpoint will not be exposed in the api docs. If set to None, the endpoint will be exposed in the api docs as an unnamed endpoint, although this behavior will be changed in Gradio 4.0. If set to a string, the endpoint will be exposed in the api docs with the given name.
97
+ scroll_to_output: If True, will scroll to output component on completion
98
+ show_progress: If True, will show progress animation while pending
99
+ queue: If True, will place the request on the queue, if the queue has been enabled. If False, will not put this event on the queue, even if the queue has been enabled. If None, will use the queue setting of the gradio app.
100
+ batch: If True, then the function should process a batch of inputs, meaning that it should accept a list of input values for each parameter. The lists should be of equal length (and be up to length `max_batch_size`). The function is then *required* to return a tuple of lists (even if there is only 1 output component), with each list in the tuple corresponding to one output component.
101
+ max_batch_size: Maximum number of inputs to batch together if this is called from the queue (only relevant if batch=True)
102
+ preprocess: If False, will not run preprocessing of component data before running 'fn' (e.g. leaving it as a base64 string if this method is called with the `Image` component).
103
+ postprocess: If False, will not run postprocessing of component data before returning 'fn' output to the browser.
104
+ cancels: A list of other events to cancel when this listener is triggered. For example, setting cancels=[click_event] will cancel the click_event, where click_event is the return value of another components .click method. Functions that have not yet run (or generators that are iterating) will be cancelled, but functions that are currently running will be allowed to finish.
105
+ every: Run this event 'every' number of seconds while the client connection is open. Interpreted in seconds. Queue must be enabled.
106
+ trigger_mode: If "once" (default for all events except `.change()`) would not allow any submissions while an event is pending. If set to "multiple", unlimited submissions are allowed while pending, and "always_last" (default for `.change()` event) would allow a second submission after the pending event is complete.
107
+ js: Optional frontend js method to run before running 'fn'. Input arguments for js method are values of 'inputs' and 'outputs', return should be a list of values for output components.
108
+ concurrency_limit: If set, this is the maximum number of this event that can be running simultaneously. Can be set to None to mean no concurrency_limit (any number of this event can be running simultaneously). Set to "default" to use the default concurrency limit (defined by the `default_concurrency_limit` parameter in `Blocks.queue()`, which itself is 1 by default).
109
+ concurrency_id: If set, this is the id of the concurrency group. Events with the same concurrency_id will be limited by the lowest set concurrency_limit.
110
+ show_api: whether to show this event in the "view API" page of the Gradio app, or in the ".view_api()" method of the Gradio clients. Unlike setting api_name to False, setting show_api to False will still allow downstream apps to use this event. If fn is None, show_api will automatically be set to False.
111
+ """
112
+ ...
src/demo/app.py CHANGED
@@ -1,21 +1,20 @@
1
-
2
  import gradio as gr
3
  from gradio_modal import Modal
4
 
5
-
6
  with gr.Blocks() as demo:
7
- gr.Markdown("### Main Page")
8
- gr.Textbox("lorem ipsum " * 1000, lines=10)
9
-
10
- with Modal(visible=True) as modal:
11
- gr.Markdown("# License Agreement")
12
- gr.Textbox(value="This is the license agreement. Please read it carefully. " * 5, lines=12)
13
- close_btn = gr.Button("Close Modal")
14
- close_btn.click(lambda: Modal(visible=False), None, modal)
15
-
16
- show_btn = gr.Button("Show Modal")
 
 
 
17
  show_btn.click(lambda: Modal(visible=True), None, modal)
18
 
19
-
20
- if __name__ == "__main__":
21
- demo.launch()
 
 
1
  import gradio as gr
2
  from gradio_modal import Modal
3
 
 
4
  with gr.Blocks() as demo:
5
+ with gr.Tab("Tab 1"):
6
+ text_1 = gr.Textbox(label="Input 1")
7
+ text_2 = gr.Textbox(label="Input 2")
8
+ text_1.submit(lambda x:x, text_1, text_2)
9
+ show_btn = gr.Button("Show Modal")
10
+ gr.Examples(
11
+ [["Text 1", "Text 2"], ["Text 3", "Text 4"]],
12
+ inputs=[text_1, text_2],
13
+ )
14
+ with gr.Tab("Tab 2"):
15
+ gr.Markdown("This is tab 2")
16
+ with Modal(visible=False) as modal:
17
+ gr.Markdown("Hello world!")
18
  show_btn.click(lambda: Modal(visible=True), None, modal)
19
 
20
+ demo.launch()
 
 
src/frontend/Index.svelte CHANGED
@@ -1,16 +1,24 @@
1
  <script lang="ts">
2
  import { Block } from "@gradio/atoms";
3
  import Column from "@gradio/column";
 
4
  export let elem_id = "";
5
  export let elem_classes: string[] = [];
6
  export let visible = false;
7
  export let allow_user_close = true;
 
 
 
8
 
9
  let element: HTMLElement | null = null;
 
 
 
 
10
 
11
  document.addEventListener("keydown", (evt: KeyboardEvent) => {
12
  if (allow_user_close && evt.key === "Escape") {
13
- visible = false;
14
  }
15
  });
16
  </script>
@@ -23,14 +31,14 @@
23
  id={elem_id}
24
  on:click={(evt) => {
25
  if (allow_user_close && evt.target === element) {
26
- visible = false;
27
  }
28
  }}
29
  >
30
  <div class="modal-container">
31
  <Block height="100%">
32
  {#if allow_user_close}
33
- <div class="close" on:click={() => (visible = false)}>
34
  <svg
35
  width="10"
36
  height="10"
 
1
  <script lang="ts">
2
  import { Block } from "@gradio/atoms";
3
  import Column from "@gradio/column";
4
+ import { Gradio } from "@gradio/utils";
5
  export let elem_id = "";
6
  export let elem_classes: string[] = [];
7
  export let visible = false;
8
  export let allow_user_close = true;
9
+ export let gradio: Gradio<{
10
+ blur: never;
11
+ }>;
12
 
13
  let element: HTMLElement | null = null;
14
+ const close = () => {
15
+ visible = false;
16
+ gradio.dispatch("blur");
17
+ };
18
 
19
  document.addEventListener("keydown", (evt: KeyboardEvent) => {
20
  if (allow_user_close && evt.key === "Escape") {
21
+ close();
22
  }
23
  });
24
  </script>
 
31
  id={elem_id}
32
  on:click={(evt) => {
33
  if (allow_user_close && evt.target === element) {
34
+ close();
35
  }
36
  }}
37
  >
38
  <div class="modal-container">
39
  <Block height="100%">
40
  {#if allow_user_close}
41
+ <div class="close" on:click={close}>
42
  <svg
43
  width="10"
44
  height="10"