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

Add code for data analysis #3654

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 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
30b806c
Merge pull request #17 from BigComputer-Project/zoey/check_code_updates
digitsisyph Dec 11, 2024
16c4910
Add Dark Mode and Size Limit
digitsisyph Dec 11, 2024
46f2cb4
Merge pull request #18 from BigComputer-Project/lgary/custom_componen…
digitsisyph Dec 11, 2024
f48dddb
Fix image rendering
digitsisyph Dec 11, 2024
61584f5
Merge pull request #19 from BigComputer-Project/lgary/fix_render
digitsisyph Dec 11, 2024
0aefb34
Add Collapse for Sandbox
digitsisyph Dec 12, 2024
096627b
Merge pull request #20 from BigComputer-Project/lgary/collapse_sandbox
digitsisyph Dec 12, 2024
def863a
Add system prompt
digitsisyph Dec 12, 2024
89e1c90
Merge pull request #21 from BigComputer-Project/lgary/add_system_prompt
digitsisyph Dec 12, 2024
ddd3eb6
Improve prompt
digitsisyph Dec 12, 2024
751324d
Add role prompt
digitsisyph Dec 12, 2024
95dd6dc
Merge pull request #22 from BigComputer-Project/lgary/improve_prompt
digitsisyph Dec 12, 2024
f93823d
Disable Sandbox Modal
digitsisyph Dec 12, 2024
f7c56ea
Merge pull request #23 from BigComputer-Project/lgary/fix_sandbox_modal
digitsisyph Dec 12, 2024
504ffce
Support code edit
digitsisyph Dec 15, 2024
77069de
Merge pull request #25 from BigComputer-Project/lgary/edit_code
digitsisyph Dec 15, 2024
c5abeb3
Support Auto Env
digitsisyph Dec 15, 2024
9de0111
Improve code component
digitsisyph Dec 15, 2024
3aa2f1e
Merge pull request #26 from BigComputer-Project/lgary/support_auto_en…
digitsisyph Dec 15, 2024
5c6399d
Delete Is web ui value
digitsisyph Dec 16, 2024
6c635d7
Merge pull request #27 from BigComputer-Project/lgary/improve_check_w…
digitsisyph Dec 16, 2024
4db105c
Support one-side chat for named tab.
Zoeyyhc Dec 18, 2024
be3024f
Support one-side chat for anony.
Zoeyyhc Dec 18, 2024
b03df26
Support one-side regenerate.
Zoeyyhc Dec 21, 2024
c2aad12
Support HTML
digitsisyph Dec 22, 2024
f8de68e
Merge pull request #29 from BigComputer-Project/lgary/add_vanilla_html
digitsisyph Dec 22, 2024
fa4419c
Merge pull request #28 from BigComputer-Project/zoey/one_side_chat
Zoeyyhc Dec 26, 2024
e74081a
Revert "Support one-side chat and regenerate for named and anony tab."
terryyz Dec 26, 2024
614a804
Merge pull request #31 from BigComputer-Project/revert-28-zoey/one_si…
terryyz Dec 26, 2024
125ee38
Fix syntax error
Zoeyyhc Dec 27, 2024
8decd5c
Merge pull request #33 from BigComputer-Project/zoey/fix_one_side_chat
terryyz Dec 29, 2024
35e2368
Support dependencies
digitsisyph Dec 30, 2024
9c51bb4
Merge pull request #34 from BigComputer-Project/lgary/support_depende…
digitsisyph Dec 30, 2024
81ddc08
draft enhancement for extraction
terryyz Jan 6, 2025
48a590a
remove sandbox tag from prompt
terryyz Jan 6, 2025
848b99b
remove tag from prompt
terryyz Jan 6, 2025
489b6bb
improve py dependency extraction
terryyz Jan 6, 2025
f8cf752
fix js/ts import extraction
terryyz Jan 6, 2025
ceef956
remove doc details
terryyz Jan 7, 2025
3b6ba4c
fix the frameworks for react
terryyz Jan 7, 2025
b2b8136
enhance code postprocessing
terryyz Jan 7, 2025
eb8b8d8
add traj replication
terryyz Jan 7, 2025
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
79 changes: 79 additions & 0 deletions analysis/replicate_traj.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import json
import time
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import os

def parse_timestamp(ts_str):
return datetime.fromisoformat(ts_str.replace('Z', '+00:00')).timestamp()

def replay_interactions(json_file):
# Read interaction data
with open(json_file, 'r') as f:
data = json.load(f)

# Setup webdriver
driver = webdriver.Chrome()
actions = ActionChains(driver)

# Create screenshots directory
screenshots_dir = "interaction_screenshots"
os.makedirs(screenshots_dir, exist_ok=True)

try:
# Navigate to the sandbox URL
driver.get(data['sandboxUrl'])

# Initial pause to let page load
time.sleep(2)

# Take initial screenshot
driver.save_screenshot(os.path.join(screenshots_dir, "000_initial.png"))

# Process each interaction
prev_time = None
for idx, interaction in enumerate(data['userInteractionRecords'], 1):
current_time = parse_timestamp(interaction['time'])

# Wait appropriate time between actions
if prev_time is not None:
time_diff = current_time - prev_time
if time_diff > 0:
time.sleep(time_diff)

# Replay the interaction
if interaction['type'] == 'resize':
driver.set_window_size(interaction['width'], interaction['height'])

elif interaction['type'] == 'scroll':
driver.execute_script(
f"window.scrollTo({interaction['scrollLeft']}, {interaction['scrollTop']});"
)

elif interaction['type'] == 'click':
actions.move_by_offset(interaction['x'], interaction['y']).click().perform()
actions.reset_actions()

elif interaction['type'] == 'keydown':
actions.send_keys(interaction['key']).perform()
actions.reset_actions()

# Take screenshot after action
screenshot_name = f"{idx:03d}_{interaction['type']}.png"
driver.save_screenshot(os.path.join(screenshots_dir, screenshot_name))

prev_time = current_time

# Final pause and screenshot
time.sleep(2)
driver.save_screenshot(os.path.join(screenshots_dir, "final.png"))

finally:
driver.quit()
print(f"Screenshots saved in {screenshots_dir}/")

if __name__ == "__main__":
replay_interactions('userInteractions.json')
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