Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip code execution in sandbox when code not updated. #3642

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
702e8ff
Add components
digitsisyph Nov 16, 2024
b6d3c6c
Modify fastchat code
digitsisyph Nov 16, 2024
a7d9d27
Merge pull request #2 from MMCode-Project/lgary/sandbox/prototype
digitsisyph Nov 16, 2024
6a6fc7a
Update readme
digitsisyph Nov 16, 2024
c19f7fa
Merge pull request #3 from MMCode-Project/lgary/update_readme
digitsisyph Nov 16, 2024
54f21ac
Fix
digitsisyph Nov 17, 2024
50140e4
Merge pull request #4 from MMCode-Project/lgary/fix
digitsisyph Nov 17, 2024
10b9b00
Support PyGame Sandbox
digitsisyph Nov 18, 2024
43b5fdf
Merge pull request #5 from MMCode-Project/lgary/pygame_sandbox
digitsisyph Nov 18, 2024
b63ecb8
Add sandbox for anony tab
Zoeyyhc Nov 20, 2024
f19b9c7
Remove extra comments
Zoeyyhc Nov 22, 2024
eb76f0d
Merge pull request #6 from MMCode-Project/zoey/anony
Zoeyyhc Nov 22, 2024
0628193
Attempt to add sandbox to direct chat (but ' on_click_run_code' not t…
Zoeyyhc Nov 24, 2024
eb491a8
fix
Zoeyyhc Nov 25, 2024
5e89ec1
stop tracking cert
Zoeyyhc Nov 25, 2024
6420452
Merge pull request #7 from MMCode-Project/zoey/direct_chat
Zoeyyhc Nov 25, 2024
051eefa
Support Vue Sandbox
Zoeyyhc Nov 27, 2024
c3ca94b
Fix
digitsisyph Nov 27, 2024
91147f1
Merge pull request #8 from BigComputer-Project/zoey/support_vue
Zoeyyhc Nov 27, 2024
a52dcda
Support streamlit and gradio sandbox
Zoeyyhc Nov 28, 2024
7e6add8
Remove streamlit related code
Zoeyyhc Nov 28, 2024
b85ed17
Merge pull request #9 from BigComputer-Project/zoey/streamlit_gradio_…
Zoeyyhc Nov 28, 2024
418730a
Fix checkbox in web_server
Zoeyyhc Dec 2, 2024
b459b4d
Fix sandbox prompt and ui in direct chat
Zoeyyhc Dec 2, 2024
2e5bf30
Ban change env chocie after sandbox enabled in one round of conversat…
Zoeyyhc Dec 3, 2024
cab811f
Fix minor issues in the sandbox component
digitsisyph Dec 4, 2024
504e3df
Merge pull request #10 from BigComputer-Project/lgary/fix_cc_sandbox
digitsisyph Dec 4, 2024
0fbcff3
Hide prompt and env choice when checkbox not ticked.
Zoeyyhc Dec 4, 2024
92d9084
Fix anony and named sandbox.
Zoeyyhc Dec 6, 2024
a26d216
Fix
Zoeyyhc Dec 7, 2024
45bc787
Fix minor issues in the sandbox component
digitsisyph Dec 4, 2024
abaae0a
Clear sandbox components when clear btn or model selector clicked.
Zoeyyhc Dec 7, 2024
c565f76
Merge pull request #11 from BigComputer-Project/zoey/fix_clear_sandbox
digitsisyph Dec 7, 2024
1cb21ac
Merge branch 'lm-sys:main' into main
digitsisyph Dec 7, 2024
4968fd5
Avoid None key error
digitsisyph Dec 7, 2024
7029627
Improve comments
digitsisyph Dec 8, 2024
2d70b52
Remove Auto Env which is not supported yet
digitsisyph Dec 8, 2024
36ba568
Add Label for sandbox button
digitsisyph Dec 8, 2024
515e10e
Tweak custom components UI
digitsisyph Dec 8, 2024
d44459d
Add support for NiceGUI
digitsisyph Dec 8, 2024
e8cadd1
Merge pull request #12 from BigComputer-Project/lgary/minor_overhaul
digitsisyph Dec 8, 2024
209f7df
Support Streamlit
digitsisyph Dec 10, 2024
8d6a2f9
Merge pull request #13 from BigComputer-Project/lgary/streamlit
digitsisyph Dec 10, 2024
8d19e34
Enforce Prompt
digitsisyph Dec 10, 2024
d908946
Merge pull request #14 from BigComputer-Project/lgary/enforce_prompt
digitsisyph Dec 10, 2024
3df1c3e
Add support for javascript/python code interpreter
digitsisyph Dec 10, 2024
7435ffb
Merge pull request #15 from BigComputer-Project/lgary/show_output
digitsisyph Dec 10, 2024
c94fd68
Fix slow response of checkbox
Zoeyyhc Dec 11, 2024
36cb8af
Merge pull request #16 from BigComputer-Project/zoey/fix_checkbox
Zoeyyhc Dec 11, 2024
68a134a
Skip sandbox execution when code not changed.
Zoeyyhc Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dist
wandb
output
checkpoints_flant5_3b
.gradio/certificate.pem

# Data
*.pkl
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ FastChat's core features include:
- [Fine-tuning](#fine-tuning)
- [Citation](#citation)

----

For Software Areana, please follow the following extra steps:
1. Set your E2B API Key: `export E2B_API_KEY=<YOUR_API_KEY>`
2. Custom Component Build: Follow https://www.gradio.app/guides/custom-components-in-five-minutes to set up environment. Go into `custom_components/sandboxcomponent` and run `gradio cc install`, `gradio cc build`.
3. Use `pip install custom_components/sandboxcomponent/dist/gradio_sandboxcomponent-xxx-py3-none-any.whl` to install the custom components.

----

## Install

### Method 1: With pip
Expand Down
12 changes: 12 additions & 0 deletions custom_components/sandboxcomponent/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.eggs/
dist/
*.pyc
__pycache__/
*.py[cod]
*$py.class
__tmp/*
*.pyi
.mypycache
.ruff_cache
node_modules
backend/**/templates/
252 changes: 252 additions & 0 deletions custom_components/sandboxcomponent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@

# `gradio_sandboxcomponent`
<a href="https://pypi.org/project/gradio_sandboxcomponent/" target="_blank"><img alt="PyPI - Version" src="https://img.shields.io/pypi/v/gradio_sandboxcomponent"></a>

Gradio library for easily interacting with remote sandbox.

## Installation

```bash
pip install gradio_sandboxcomponent
```

## Usage

```python

import gradio as gr
from gradio_sandboxcomponent import SandboxComponent

example = SandboxComponent().example_value()


with gr.Blocks() as demo:
with gr.Tab("Sandbox Demo"):
with gr.Row():
gr.Markdown("## Sandbox")
with gr.Row():
SandboxComponent(
label="Sandbox Example",
value=("https://www.gradio.app/", "Hello World"),
show_label=True)


if __name__ == "__main__":
demo.launch()

```

## `SandboxComponent`

### Initialization

<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>value</code></td>
<td align="left" style="width: 25%;">

```python
tuple[str, str] | Callable | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component.</td>
</tr>

<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">the label for this component, displayed above the component if `show_label` is `True` and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component corresponds to.</td>
</tr>

<tr>
<td align="left"><code>every</code></td>
<td align="left" style="width: 25%;">

```python
Timer | float | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.</td>
</tr>

<tr>
<td align="left"><code>inputs</code></td>
<td align="left" style="width: 25%;">

```python
Component | Sequence[Component] | set[Component] | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.</td>
</tr>

<tr>
<td align="left"><code>show_label</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">if True, will display label.</td>
</tr>

<tr>
<td align="left"><code>scale</code></td>
<td align="left" style="width: 25%;">

```python
int | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.</td>
</tr>

<tr>
<td align="left"><code>min_width</code></td>
<td align="left" style="width: 25%;">

```python
int
```

</td>
<td align="left"><code>160</code></td>
<td align="left">minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.</td>
</tr>

<tr>
<td align="left"><code>interactive</code></td>
<td align="left" style="width: 25%;">

```python
bool | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.</td>
</tr>

<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">If False, component will be hidden.</td>
</tr>

<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">

```python
str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">None</td>
</tr>

<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">

```python
list[str] | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
</tr>

<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">

```python
bool
```

</td>
<td align="left"><code>True</code></td>
<td align="left">If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
</tr>

<tr>
<td align="left"><code>key</code></td>
<td align="left" style="width: 25%;">

```python
int | str | None
```

</td>
<td align="left"><code>None</code></td>
<td align="left">if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.</td>
</tr>
</tbody></table>


### Events

| name | description |
|:-----|:------------|
| `change` | Triggered when the value of the SandboxComponent changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input. |
| `input` | This listener is triggered when the user changes the value of the SandboxComponent. |
| `submit` | This listener is triggered when the user presses the Enter key while the SandboxComponent is focused. |



### User function

The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).

- When used as an Input, the component only impacts the input signature of the user function.
- When used as an output, the component only impacts the return signature of the user function.

The code snippet below is accurate in cases where the component is used as both an input and an output.

- **As output:** Is passed, passes text value as a {str} into the function.
- **As input:** Should return, expects a {str} returned from function and sets textarea value to it.

```python
def predict(
value: str | None
) -> str | None:
return value
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

from .sandboxcomponent import SandboxComponent

__all__ = ['SandboxComponent']
Loading
Loading